I want to set an alarm via AlarmManager
class. Normally, It works fine and everything is OK.
But if my application process stops or Phone turns off and turns on again, The alarm wont start. Any help?
or other service that android provides?
thanks
Android will erase all intent of alarm manager if you will restart your phone.
You have to create a receiver for start BOOT_COMPLETED
and then you will get onReceive() method when your device will start.In this method you can create all alarm again.
You have to declare receiver in manifest
<receiver android:name=".MyStartupIntentReceiver" android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
And your receiver will be
import java.util.Calendar;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class MyStartupIntentReceiver extends BroadcastReceiver{
@Override
public void onReceive(final Context context, Intent intent1) {
// You can update pending intent here
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With