does Alarm Manager persist even after reboot?

一世执手 提交于 2019-11-26 13:08:54

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 android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
    </receiver>

Yes , you can make AlarmManager to work even after rebooting. Perhaps this is the easiest way : add the below code in your AndroidManifest.xml:

<receiver android:name=".AlarmReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>

don't forget to include user-permission to the AndroidManifest.xml as:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

in some phones only adding

<action android:name="android.intent.action.Boot_COMPLETED" />

does not work you also have to add

<action android:name="android.intent.action.QUICKBOOT_POWERON" />

along with previous one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!