Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7754943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:26:29+00:00 2026-06-01T12:26:29+00:00

I have a Homework Planner application which I want to create an Alarm for

  • 0

I have a Homework Planner application which I want to create an Alarm for to remind users of the homework the night before/at a certain time. I have an Activity called AddNewHomework which is where the user creates a new homework item and it is added to the database. This code is then called.

Intent i = new Intent(this, AlarmNotificationReceiver.class);
i.putExtra("title", title);
PendingIntent pi = PendingIntent.getBroadcast(this.getApplicationContext(), (int) id, i, 0);
AlarmManager mAlarm = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
mAlarm.set(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + 10 * 1000, pi);

This creates a new Alarm which is triggered in 10 seconds and creates a notification.

My problem is that I have another activity called HomeworkList which contains a ListView and displays all of the homeworks stored in the database. If a user long clicks on one then they have the option to delete it, however removing it from the database will not remove the alarm.

I have looked for code I can use to remove the alarm however I have not found anything that allows me to understand how to cancel the alarm from this different activity. I know that I need to make the PendingIntent’s the same, but how do I do this as I cannot access the context from the other class. (I don’t think).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:26:30+00:00Added an answer on June 1, 2026 at 12:26 pm

    If it helps, you could access your context from another activity, by making a static getter for the current context. In your above class, just make a private field:

    private static Context context;
    
    public static Context getAppContext(){
        return MyActivity.context;
    }
    

    Then, simply add in the onCreate method a:

    MyActivity.context = getApplicationContext();
    

    Accessing the context from another activity is now pretty easy. You can use the context retrieved from “MyActivity” to cancel your alarm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a homework assignment in which I'm supposed to create a vector of pointers
I have a homework to build an application which will send and receive simple
I have a small homework application that writes random numbers from 5 to 77
I have a homework assignment which asks to have the user input a date
I have this homework question: Assume a Database table has 0 records at time
I have homework which I have to use scriptlets in , I need to
I have a prolog homework, which should work like this: singles([1,2,3,2,2,4,1], [3,4]). true Now
I have in my homework some question about data structure: I have elements which
I have a homework assignment to write a multi-threaded sudoku solver, which finds all
I have this insane homework where I have to create an expression to validate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.