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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:45:38+00:00 2026-06-07T01:45:38+00:00

I am attempting to make alarm program. So far I have written an activity

  • 0

I am attempting to make alarm program. So far I have written an activity in which the user can select the time he wishes the alarm to go off. This is working fine. Now I need to use the alarm manger to tell the OS to call some of my code at a certain point in the future. Just to test this in a crude way I added the following code that gets executed when I press a test button in my main activity:

Intent intent = new Intent(getApplicationContext(), to_call_when_alarm_goes_off.class);
PendingIntent pIntent = PendingIntent.getBroadcast(getApplicationContext(),0, intent, 0);
AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarms.cancel(pIntent);

alarms.setRepeating(
        AlarmManager.RTC_WAKEUP,
        System.currentTimeMillis()+1000, 
        AlarmManager.INTERVAL_DAY, 
        pIntent);

This should mean that some code called to_call_when_alarm_goes_off will get executed one second after I press the button…. Now this is where I’m a little confused. I’m not sure quite how/where to set up “to_call_when_alarm_goes_off”. What I did was simply add a new class to my project as follows:

package com.mycompany.alarmprogram;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class to_call_when_alarm_goes_off extends BroadcastReceiver
{

    @Override
    public void onReceive(Context arg0, Intent arg1) 
    {
        // TODO Auto-generated method stub
        Log.i("ALARM","TIME TO WAKE UP!!!");

    }

}

All the code compiles, and when I press the button all the code in the first code snippet gets executed without crashing – but one second later the broadcast receiver code is not executed. Clearly I am misunderstanding something.

  • 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-07T01:45:40+00:00Added an answer on June 7, 2026 at 1:45 am

    I assume you are missing registering your receiver in Manifest file, With appropriate action string. as given below.

             <receiver android:name=".to_call_when_alarm_goes_off" > 
                   <intent-filter>
                      <action android:name="com.android.whatever.WHAT_EVER_NAM_YOU_WANNA_GIVE" />
                    </intent-filter>// can change name/action string as par ur requirement.
            </receiver>
    

    you need to set same action string in your intent, Remember Action string must be same in Manifest and here intent.setAction("com.android.whatever.WHAT_EVER_NAM_YOU_WANNA_GIVE"); in java also. then only it will tringger receiver.

    Your code can be changed like given below.

    Intent intent = new Intent(getApplicationContext(), to_call_when_alarm_goes_off.class);
    intent.setAction("com.android.whatever.WHAT_EVER_NAM_YOU_WANNA_GIVE");// added line
    
    PendingIntent pIntent = PendingIntent.getBroadcast(getApplicationContext(),0, intent, 0);
    
    AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    
    alarms.cancel(pIntent);
    
    
    alarms.setRepeating(
            AlarmManager.RTC_WAKEUP,
            System.currentTimeMillis()+1000, 
            AlarmManager.INTERVAL_DAY, 
            pIntent);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to make a Google Map which allows the user to check off
I am attempting to make a program in C which presents a GUI and
I am attempting to make an app in which you can load an image
I am attempting to make it so that we can have our application to
I am attempting to make it so a user can say Modify X ,
I am attempting to make a simple accordion where the user clicks on level
You can see my project here - http://www.inluxphoto.com/custom/jsgallery/index.php I am attempting to make the
I've been attempting to make a folder for each architecture my code can support.
I'm attempting to make a drop shadow for a custom NSView subclass. So far,
I'm attempting to make a custom ContentProvider so that more than one application (activity?)

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.