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 8340967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:19:51+00:00 2026-06-09T05:19:51+00:00

I am making an application that uses AlarmManager.setInexactRepeating() method, that takes a PendingIntent as

  • 0

I am making an application that uses AlarmManager.setInexactRepeating() method, that takes a PendingIntent as a paramater.

I start this by calling my setAlarm() method

public void setRepeatingAlarm() {

    Intent intent = new Intent(this, AlarmReceiver.class);
    String url = getAssembledUrl();
    intent.putExtra("url", url);
    pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);

}

and stop it by stopAlarm()

private void stopRepeatingAlarm() {

    alarmManager.cancel(pendingIntent);
    pendingIntent.cancel();

}

Works just fine. However when activity gets destroyed, and user decides to stop the alarm, obviously the pending intent is null, as it gets created in the setRepeatingAlarm() method that wasnt called during current activities life.

Whats the correct way to get around this?

I could be creating the pending intent in Activity.onCreate() and that would solve this problem, however I will not be able to start the alarm again as the pending intent got canceled and needs to be recreated again (i think, unless there is a way to check the intent was canceled that i dont know about)

  • 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-09T05:19:52+00:00Added an answer on June 9, 2026 at 5:19 am

    Actually, as it turns out

    PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    

    returns the same pending intent, if the intent is the same so, all i needed was

    private void stopRepeatingAlarm() {
    
        if(pendingIntent == null) {
            pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        }
    
        alarmManager.cancel(pendingIntent);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making an Android application that reads an XML Internet. This application uses SAX
I'm making a web application that uses hash tags for page navigation like this
Im making an application that uses of API-threads in C, The program takes N-files
I am making a simple application that uses a NSSlider, which can be put
I'm making an application in Win32 API that uses the modern Ribbon style UI.
I am making an application that uses Drools planner. The @ValueRangeFromSolutionProperty is supposed to
Alright, I'm in the process of making a C# application that uses an API
I am making an android application that uses these views: (Root) - LinearLayout (Child
I am making an android application that uses a listview. I want to get
I’m making a sample application that uses MigLayout in a very cool way. Unfortunately

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.