How to handle an alarm triggered each day in android

I want to set an alarm in my application which will be triggered each day. According to the doc, I have to set a one-time alarm, and in the BroadcastReceiver which will receive the alarm signal, reset the alarm for the day after. Is that correct ?

My BroadcastReceiver handles well the wakelock and launch a service which releases this wakelock. Everything works fine here.

However I have problems. In my application there is a checkbox which is checked when alarm is up. To know if my alarm is up, I use the following condition :

Intent intent = new Intent( context, AlarmReceiver.class );
boolean alarmUp = (
PendingIntent.getBroadcast( context, 0, intent, PendingIntent.FLAG_NO_CREATE) != null)

But this doesn't seem to work very well, is that a good way to know if an alarm is up ?

Thanks in advance


Asked by: Maria590 | Posted: 24-01-2022






Answer 1

For the first part of your question, you could just use a repeating alarm, or schedule a new alarm whenever one fires like you are doing. Either way works.

You may also want to setup a broadcast receiver that receives ACTION_BOOT_COMPLETED so you can reschedule your alarms when the phone reboots.

As for checking if the alarm exists, the PendingIntent with FLAG_NO_CREATE is exactly how you would do that.

Answered by: Julia178 | Posted: 25-02-2022



Similar questions

android - BroadcastReceiver for screen lock not being triggered

I'm trying to turn the GPS location updates off when the screen locks. Having read the answer to this question Android - how to receive broadcast intents ACTION_SCREEN_ON/OFF? I've written some code to implement a BroadcastReceiver but it's not working when the screen goes off. I've regist...


java - How to find out which activity started the intent that triggered your BroadCastReceiver?

I have an app, where some calls can be made when you press a button. I call a number with: Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:"+o.getTel())); startActivity(callIntent); I have a broadcast receiver that detects end of call. But this broadcast receiver also receives calls started from other apps (e.g. dialer app). How can i diff...


android - BroadcastReceiver not triggered by Alarm

I am trying to set up an alarm that will run in the background and trigger (eventually) a save event. At the moment I simply have this code attached to a button. Press the button and the alarm should start leaving Toast messages behind as an indication that it is functioning. At the moment everything runs except the onReceive in the BroadcastReceiver is never triggered. Here is my code: The class setting up...


android - Can I check what exactly is causing a broadcastreceiver to be triggered?

I have a BroadcastReceiver that's registered like this in my manifest: <receiver android:name="xxx.xxx.xxx.LaunchReceiver" android:enabled="true" android:label="@string/app_name" > <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> <intent-filter> <action andr...


broadcastreceiver - Wifi Receiver not triggered Android 4.x.x works on 2.2.1

Ive created a wifi broadcastreceiver to check for wifi state changes. This app runs fine on Android 2.2.1 device but does not receive broadcast on 4.x.x devices, I have tested on a 4.1.1 and android 4.4.2 device, no luck? I must be missing something small here. Thanks in advance! AndroidManifest.xml <manifest xmlns:android="http://schemas.android.com/apk/re...


java - BroadcastReceiver triggered twice

I have an Android project in which I use a service in order, I'm currently using this service to watch the MediaPlayer and events go through the BR. package com.uk.jacob.groovebuddy; import android.app.Service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.IBinder; import android.util.Log; impo...


android - BroadcastReceiver not triggered when screen off - possible reasons?

Try to find out what keeps my BroadcastReceiver from being triggered when screen is off. The trigger "arrives" delayed, the moment the screen gets unlocked. When screen is on, the receiver gets triggered in time. Issues occur on android 4.4.2 (Danew Dslide 710), code works well on many other devices The PendingIntent is passed to the AlarmManager like so: Context co...


broadcastreceiver - Android: Alarm is not triggered sometimes

I have an application which schedule some activities using AlarmManager service. It works most of times, however sometimes it does not send broadcast and so broadcast receiver does not receive anything (even when the app is up and running and is front activity). I read the alarm time from a TimePicker widget. Here are my code snippets: Set Alarm: private void setAlarm(int hour, int...


android - SMS BroadcastReceiver not triggered when phone hasn't been used for a while?

I have an app that registers a BroadcastReceiver in the manifest <receiver android:name=".smsprocessing.SmsBroadcastReceiver" android:exported="true" android:permission="android.permission.BROADCAST_SMS"> <intent-filter android:priority="999"> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> <actio...


android - BroadcastReceiver not being triggered when app is closed

I'm attempting to make it so my app runs some code once per day at 6AM. This works just fine when the app is open and in the foreground, but if the app is closed by swiping it away, the code is never called at the appropriate time. AlarmReceiver.java (For testing purposes, I have it just trying to display a Toast to verify it runs) public class AlarmReceiver extends BroadcastReceive...


Android - Passing changing data from BroadcastReceiver to another Object?

I have a Wifi class that has a couple of broadcast receivers that listen out for changes in Wifi connection state, Wifi Rssi levels etc... I want to be able to pass this data to another "Engine" Object and still keep the data changing dynamically. I currently create a Wifi object within the "Engine" class and run its methods, the data is then dynamically displayed fine in Log statements in the log cat. ...


android - Calling an inputMethod's method when a BroadcastReceiver gets called

I added a BroadCastReceiver to my application. I want to call my inputMethod's method but I can't find a way to access it's instance. I read I can get an InputMethodManager by: InputMethodManager manager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); but I couldn't find a way to get the the InputMethod instance from the InputMethodManager. Is...


Android : Why BroadcastReceiver crashing?

I have this Broadcast receiver registered public class NotifyAlarmBroadcast extends BroadcastReceiver{ public Context context; public static final String NOTI = "android.intent.action.MAIN"; // actually i want NOTI = "com.sumit.timekeeper.NotifyAlarm" // this too is not working // help me here please @Override public void onReceive(Context _context, Intent intent) { context = _context; Uri ...


android - Inform Activity from a BroadcastReceiver ONLY if it is in the foreground

Maybe it's easy, but I couldn't really figure this out right so far... I got a BroadcastReceiver waiting to get triggered by the AlarmMangager - this works fine. Now: because the event, if it occurs, needs to refresh some elements on screen of the main Activity, I would like to send an Intent from that background BroadcastReceiver to my Activity - but only if it is currently in the for...


java - Get from Android BroadcastReceiver to a UI

I have a receiver that works well, but I can't seem to show a proper UI, although the toast appears correctly. As far as I can tell, this is caused by Android requiring the class to extend Activity, however, the class already extends BroadcastReceiver, so I can't do this. So, I tried to do an Intent, but this failed too. There are no errors, but the screen doesn't show. Source code is below. Broadcast (Method i...


android - How do I pass data from a BroadcastReceiver through to an Activity being started?

I've got an Android application which needs to be woken up sporadically throughout the day. To do this, I'm using the AlarmManager to set up a PendingIntent and have this trigger a BroadcastReceiver. This BroadcastReceiver then starts an Activity to bring the UI to the foreground. All of the above seems to work, in that the Activity launches itself correctly; but I'd like the BroadcastReceiver to notify the...


broadcastreceiver - How to use Broadcast Receiver in different Applications in Android?

I have here two applications in two different projects in eclipse. One application (A) defines an activity (A1) which is started first. Then i start from this activity the second activity (B1) in the second project (B). This works fine. I start it the following way: Intent intent = new Intent("pacman.intent.action.Launch"); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(intent);


android - Calling background service from BroadcastReceiver

I am trying to call a push notification background service from BroadcastReceiver class, but my application crashes. The code is given below: public class AlarmReceiver extends BroadcastReceiver { static int count=1; @Override public void onReceive(Context context, Intent intent) { Intent myIntent=new Intent(context,NotifyService.class); myIntent.setFlags(Intent.FLAG_ACTIVITY...


android - Service and a BroadCastReceiver

I have seen several examples of how to implement a BroadCastReceiver, but how should I implement a Service that has to react to some pending Intent (for example incoming phone call)... Actually I was wondering about the same "problem" but in an Activity.. You obviously have a class which extends a Service or an Activity) so it cannot also extend BroadCastReceiver... It looks like we cannot make "platform-aware" services an...


android - AlarmManager and BroadcastReceiver instead of Service - is that bad ? (Timeout)

BACKGROUND INFO: I need to update some data from the web, about every hour or so, even when my app is closed. The update of the data itself takes about 40 seconds to 1 minute. It is then saved as a Serializable to a file. This file is read when my app starts. THIS IS THE APPROACH I TOOK FOR THE MOMENT (not using a Service) use the AlarmManager and BroadcastReceiver ...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top