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

  • Home
  • SEARCH
  • 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 8743671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:43:08+00:00 2026-06-13T11:43:08+00:00

In mainactivity I have Broadcast Receiver, pending intent, and alarm manager. It triggers as

  • 0

In mainactivity
I have Broadcast Receiver, pending intent, and alarm manager. It triggers as per selected time (System.currentTimeMillis() + smstimeinmilliseconds).

Intent intent = new Intent(this, DBBroadcastReceiver.class);
intent.putExtra("message", message);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, id, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + smstimeinmilliseconds, pendingIntent);

On selected time, this pending intent triggers broadcast receiver.

public class DBBroadcastReceiver extends BroadcastReceiver 

@Override
public void onReceive(Context context, Intent intent)
{
message = intent.getStringExtra("message");

}

I can set message in activity and set time in alarm manager.
Every thing works flawless. I can activate and deactivate this. But if i set few alarm mangers in future time and reboot my mobile. all alarm manager destroy …..

Kindly tell me in steps and sequence what to do with activity , broadcast receiver and do i need service , if yes then how can i use it.

  • 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-13T11:43:09+00:00Added an answer on June 13, 2026 at 11:43 am

    You need a BoradcastReceiver to be called on boot up.

    Then you need in your manifest :

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    
    <receiver
        android:name=".broadcasts.YourBroadcastReceiverName">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    

    And this broadcast receiver needs to schedule again all the alarms.
    Something like :

    public class YourBroadcastReceiverName extends BroadcastReceiver {
    
        private AlarmManagerFacade alarmManager;
    
        @Override
        public void onReceive(Context context, Intent intent) {
    
            // Retreive data related to alarms
            Cursor cursor = context.getContentResolver().query(Alarm.CONTENT_URI, null,
                    Alarm.COLUMN_ACTIVE + " = ? ",
                    new String[] { String.valueOf(1) }, "");
    
            if (cursor.moveToFirst()) {
    
                // Schedule all the active alarms.
                alarmManager = new AlarmManagerFacade(context);
                do {
                    // TODO : Schedule alarm according to data in cursor.
                } while (cursor.moveToNext());
            }
            cursor.close();
        }
    }
    

    (This code is coming from one of my app, some of the objects are not available in the Android SDK)

    In order to be able to re schedule all the alarms, you need to have them stored somewhere.

    You can write your own ContentProvider for example.

    • It works well with other android components thanks to the CursorAdapter widget.
    • It is not the easiest solution but it’s the way to go if you want to follow android guidelines.

    There may be other simpler alternative to store your alarms, like SharedPreferences.

    • It’s easy to use.
    • But you will need to hack around to store multiple alarms in a friendly manner.

    One last alternative is that you can create an object containing the information, serialize it and store it as a file on the SD Card.

    • It’s ugly and not flexible.
    • But it not that hard to implement …

    If you want to have a closer look to each storage options, you can read about it in the docs here : http://developer.android.com/guide/topics/data/data-storage.html

    I hope all this help you. 🙂

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

Sidebar

Related Questions

Hi I have a Broadcast receiver with following code. 1. Intent i = new
I have a broadcast receiver which is listening to the WifiManager.SCAN_RESULTS_AVAILABLE_ACTION. In that receiver
I have edited the code by using setOnClick pending intent, and this code works
I have a PushNotificationReceiver (extends BroadcastReceiver) and MainActivity . The receiver sends some data
I have been struggling with the problem. I have a Broadcast receiver that is
I have a Broadcast Receiver that inserts info into a table when sms is
Is it possible to have a notification start a broadcast receiver? I tried this
All, I have a broadcast receiver that does not have an associated layout or
i have code that calls a broadcast receiver, in the receiver, i try to
I have an activity ( MainActivity.java ) in which content view is like this

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.