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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:45:12+00:00 2026-05-30T01:45:12+00:00

I want to be able to create an alarm to ring a notification to

  • 0

I want to be able to create an alarm to ring a notification to the user to start the application every 2 minutes. Everything works fine, but the notification appears when i start my application manually. Here are my code :

Receiver:

public void onReceive(Context context, Intent intent) {
    nm = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    CharSequence from = "myactivity";
    CharSequence message = "click to start activity";


    Intent scheduledIntent = new Intent(context, AmslerTestActivity.class);


    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            scheduledIntent, 0);
    Notification notif = new Notification(R.drawable.icon,
            message, System.currentTimeMillis());
    notif.setLatestEventInfo(context, from, message, contentIntent);
    notif.flags = Notification.FLAG_AUTO_CANCEL;
    notif.defaults |= Notification.DEFAULT_SOUND;
    nm.notify(1, notif);
    scheduledIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(scheduledIntent);

}

Scheduler:

cal.set(Calendar.HOUR_OF_DAY, 12);
    cal.set(Calendar.MINUTE, 01);
    cal.set(Calendar.SECOND, 0);

    Intent intent = new Intent(myactivity.this, AlarmReceiver.class);

    PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    // Get the AlarmManager service
    am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 2 * 60 * 1000, sender);

I want the notification to only ring when the code is not running.

  • 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-30T01:45:13+00:00Added an answer on May 30, 2026 at 1:45 am

    Put the “scheduler” part of your code in onPause, onStop or onDestroy in order to set the alarm only once your Activity stops. Read here to decide which is best for your purposes. Then, when doing am.setRepeating, use System.currentTimeMillis() + 2 * 60 * 1000 for the triggerAtTime to make the alarm trigger 2 min from the time the Activity stops. Then it will repeat every 2 min based on the 3rd parameter, the interval, which you currently have set correctly to 2 min.

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

Sidebar

Related Questions

I want to be able to create a text file and let the user
I want to be able to create multiple user accounts with the same login
We want to be able to create log files from our Java application which
I want to be able to create .mobi files with python, but i haven't
I want to be able to create the url: http://example.com/+/user Is it possible using
I want to be able to create a Pandas DataFrame with MultiIndexes for the
I want to be able to create links looking like buttons with dynamic text
I want to be able to create modal dialogs, with, for example close: function()
I want to be able to create a temporary text File in Java to
I want to be able to create the XSD file for my typed dataset

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.