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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:08:35+00:00 2026-05-28T02:08:35+00:00

For some Android applications, I would like to integrate the following feature: The user

  • 0

For some Android applications, I would like to integrate the following feature:
The user can define a time when he wants to be reminded of something. When the time has come then, the application should create a notification in the notification bar even when the user doesn’t use the app at this moment.

For this purpose, the classes AlarmManager, NotificationManager und Notification.Builder are the ones to look at, right?

So how do I create a timed notification in advance? My code (so far) is this:

Add this under to the AndroidManifest to register the broadcast receiver:

<receiver android:name="AlarmNotificationReceiver"></receiver>

Create a new class file which handles the alarm that it receives:

public class AlarmNotificationReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {
        Bundle extras = intent.getExtras();
        if (extras != null) {
            String additionalData = extras.getString("displayText");
            // show the notification now
            NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            Notification mNotification = new Notification(R.drawable.ic_launcher, context.getString(R.string.app_name), System.currentTimeMillis());
            PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0); // open MainActivity if the user selects this notification
            mNotification.setLatestEventInfo(context, context.getString(R.string.app_name), additionalData, pi);
            mNotification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.DEFAULT_SOUND;
            mNotificationManager.notify(1, mNotification);
        }
    }

}

Use this code (for example in MainActivity) to set the alarm to 3 seconds from now:

    Intent i = new Intent(this, AlarmNotificationReceiver.class);
    i.putExtra("displayText", "sample text");
    PendingIntent pi = PendingIntent.getBroadcast(this.getApplicationContext(), 234324246, i, 0);
    AlarmManager mAlarm = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    mAlarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+3*1000, pi);

What do I need to change to make this work? Thank you!

The two problems are:

  1. The notification’s text does not change when I change it in code. It only changes when I change the requestCode in PendingIntent.getBroadcast(…). What is this request code all about? Can it be a random value or 0?
  2. After rebooting my phone, the “planned” notification, or the alarm, is gone. But now I’ve seen that this is normal behaviour, right? How can I circumvent this?
  • 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-05-28T02:08:36+00:00Added an answer on May 28, 2026 at 2:08 am

    Not sure about part 1, but for part 2 the general approach is to intercept the BOOT_COMPLETED intent and use that to re-register all alarms. This does unfortunately mean that for each alarm you have registered with the alarm manager you have to store it in your app’s db as well.

    So, you’ll need a broadcast receiver to intercept the BOOT_COMPLETED intent:

    public class BootReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            // get your stored alarms from your database
            // reregister them with the alarm manager
        }
    }
    

    To get the BOOT_COMPLETED intent, you must put the following permission in your manifest:

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    

    And the BootReceiver also needs to be registered in your manifest with the following intent filter:

        <receiver android:enabled="true" android:name=".receiver.BootReceiver"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
            <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                    <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>
    

    It’s important to note that if your app is installed to the sdcard, it can never receive the BOOT_COMPLETED intent. Also, it’s worth noting that this implementation is a bit naive in that it executes code immediately on booting which can slow the user’s phone down at startup. So, I recommend delaying your execution for a few minutes after intercepting the boot intent.

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

Sidebar

Related Questions

I have been looking into android development for some time and would really like
I would like to use Android phones as a way to do some processing
I am working on some reusable Android code that I would like to distribute
I would like only to start some applications dynamically with the package name from
I would like to perform a certain operation every time a user adds a
I would like to develop an android application with the following description: The app
I would like to start looking at development for Android applications (nothing huge, just
I've already written some small Android Applications, most of them in one Activity and
Greets, Made some app on android. I for the life of me can't get
Long time reader never posted until now. Im having some trouble with Android, im

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.