Sample code for managing your application onBoot your application -
public class OnBootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.d("OnBootReceiver", "Hi, Mom!"); } }
Add permission below for onBoot service -
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
And in your manifest file, you have to add the OnBootReceiver class to register, as shown below -
<receiver android:name=".OnBootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
Great example from Commonsware available on GitHub
source share