Alarm Manager does not work in background on Android 6.0

There are a couple of things you can try which, when used in concert, should be able to cut through all of the idle/standby/doze modes (irrespective of OS version). 1. Use a WakefulBroadcastReceiver instead of an ordinary BroadcastReceiver. Make sure you include the WAKE_LOCK permission to use it correctly. 2. Use the setExactAndAllowWhileIdle() method (on … Read more

Start AlarmManager if device is rebooted

Create Boot Receiver using following code : public class BootBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context pContext, Intent intent) { if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){ // Do your work related to alarm manager } } } In your Manifest, register this Broadcast receiver : <receiver android:name=”com.yourapp.BootBroadcastReceiver” android:enabled=”true” > <intent-filter> <action android:name=”android.intent.action.BOOT_COMPLETED” /> </intent-filter> </receiver> And don’t forget to … Read more

Samsung “App optimisation” feature kills background applications after 3 days

I’ve owned (and currently own) Samsung devices, so I know a little as to how it works from the user’s point of view. The technical specifications and how it works on the inside is an entirely separate issue, and one I can’t answer. The system can detect if you open an app. Samsung uses that … Read more

How to setup Alertbox from BroadcastReceiver

Although you can not show AlertDialog from Receivers because it needs ActivityContext. You have an alternate solution to show an Activity like AlertDialog from Receiver. This is possible. To start Activity as dialog you should set theme of activity in manifest as <activity android:theme=”@android:style/Theme.Dialog” /> Style Any Activity as an Alert Dialog in Android To … Read more

Android Set Multiple Alarms

If you want to set multiple alarms (repeating or single), then you just need to create their PendingIntents with different requestCode. If requestCode is the same, then the new alarm will overwrite the old one. Here is the code to create multiple single alarms and keep them in ArrayList. I keep PendingIntent‘s in the array … Read more

does Alarm Manager persist even after reboot?

A simple answer would be NO. But yes you can achieve this by creating a BroadCastReceiver which will start the Alarm while booting completes of the device. Use <action android:name=”android.intent.action.BOOT_COMPLETED” /> for trapping boot activity in BroadCastReceiver class. You need to add above line in AndroidManifest.xml as follows, <receiver android:name=”.AutoStartUp” android:enabled=”true” android:exported=”false” android:permission=”android.permission.RECEIVE_BOOT_COMPLETED”> <intent-filter> <action … Read more

android prevent immediate trigger of alarm service if alarm time has passed for the day

You don’t need to create Timestamps. You can do it with your Calendar. Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); calendar.set(Calendar.MINUTE, minute); if(calendar.before(Calendar.getInstance())) { calendar.add(Calendar.DATE, 1); } alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingDinnerIntent); I would also mention that as of KitKat, if your targetSdkVersion is 19 or above, the AlarmManager#set() method is not exact. If you want your alarm … Read more

Android: How to use AlarmManager

“Some sample code” is not that easy when it comes to AlarmManager. Here is a snippet showing the setup of AlarmManager: AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent i=new Intent(context, OnAlarmReceiver.class); PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0); mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), PERIOD, pi); In this example, I am using setRepeating(). If you want a one-shot alarm, you would just use set(). Be … Read more