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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:48:49+00:00 2026-06-05T06:48:49+00:00

I have to following code to call the BroadcastReceiver: public class WorkItemAlarmManager { …

  • 0

I have to following code to call the BroadcastReceiver:

 public class WorkItemAlarmManager {
    ...
        public void initAlarm(HelpMe helpMe, String delay,String period,WorkItem workItem){
            //HelpMe = Activity
helpMe.registerReceiver(new WorkItemAlarmHandler() , new IntentFilter("WORK_ITEM_ALARM"));

            Intent intent = new Intent("WORK_ITEM_ALARM");
            intent.setClass(helpMe, WorkItemAlarmManager.class);
            intent.putExtra("work_item", workItem);
            PendingIntent mAlarmSender = PendingIntent.getService(helpMe, 0,intent, 0);

            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(System.currentTimeMillis());
            //System.out.println("START"+System.currentTimeMillis());   
            calendar.add(Calendar.SECOND, calcDelayMillis(delay));
            //System.out.println("END"+calendar.getTimeInMillis());
            AlarmManager am = (AlarmManager) helpMe.getSystemService(Context.ALARM_SERVICE);
            am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), mAlarmSender);
        }
    ...
    }

and the BroadcastReceiver:

public class WorkItemAlarmHandler extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        ....
    }

}

But the WorkItemAlarmHandler is never called.

Update:
I tried to register the BroadcastReceiver in the manifest at first. But that didn’t work:

<receiver
            android:name="de.helpme.alarm.WorkItemAlarmHandler"
            android:enabled="true"
            android:label="WorkItemAlarmHandler" >
            <intent-filter>
                <action android:name="WORK_ITEM_ALARM" />
            </intent-filter>
        </receiver>

Thanks for your answers :). Now it works – but i dont yet know which one is the correct because i implemented both answers at once. If a figure out which was the right one i mark the right as answer.

Update:
The cause of the problem as i see it was:

PendingIntent mAlarmSender = PendingIntent.getService(helpMe, 0,intent, 0);

With this code it works fine:

PendingIntent mAlarmSender = PendingIntent.getBroadcast(helpMe, 0, intent, 0);

Thanks again for all your help!

  • 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-05T06:48:51+00:00Added an answer on June 5, 2026 at 6:48 am

    try this :

    In WorkItemAlarmManager ;

    public class WorkItemAlarmManager {
        ...
            public void initAlarm(HelpMe helpMe, String delay,String period,WorkItem workItem){
                Intent intent =new Intent(helpMe, WorkItemAlarmHandler.class);
                intent.setAction("WORK_ITEM_ALARM");
                intent.putExtra("work_item", workItem);
                PendingIntent mAlarmSender=
                PendingIntent.getBroadcast(helpMe, 0, intent, 0);
                Calendar calendar = Calendar.getInstance();
                calendar.setTimeInMillis(System.currentTimeMillis());
                //System.out.println("START"+System.currentTimeMillis());   
                calendar.add(Calendar.SECOND, calcDelayMillis(delay));
                //System.out.println("END"+calendar.getTimeInMillis());
                AlarmManager am = (AlarmManager) helpMe.getSystemService(Context.ALARM_SERVICE);
                am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), mAlarmSender);
            }
        ...
        }
    

    and in WorkItemAlarmHandler:

    public class WorkItemAlarmHandler extends BroadcastReceiver{
    
        @Override
        public void onReceive(Context context, Intent intent) {
            if(intent.getAction().equals("WORK_ITEM_ALARM")){
                Toast.makeText(context, "WORK_ITEM_ALARM", Toast.LENGTH_LONG).show();
                }else{
                Toast.makeText(context, "repeating alarm",
                Toast.LENGTH_LONG).show();
                }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code: public class readSensorsData extends Activity implements SensorListener { /** Called
in c++ i have following code class Foobar{ public: Foobar * operator()(){ return new
I have taken to the following code which will call CFRelease after a delay.
I have following code: [TestMethod] public void StartWorkInFirstThread() { if (SynchronizationContext.Current == null) SynchronizationContext.SetSynchronizationContext(
Lets say we have following sample code in C#: class BaseClass { public virtual
I have the following code to make a jsonp call. var contacts; $.ajax({ url:
I have come up with the following code to call a webservice using client/server
I have the following code in html, I cannot get the Function call back
On Blackberry 6.0, I have used the following code to delete all the call
I have the following shortened classic ASP code that makes a SQL insert call...

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.