My background application process terminates when the device is loaded

my background application process stops when the device reboots. What to do so that it always works after the device is booted. Since my notification did not appear when booting the device

+4
source share
2 answers

You need to use BroadcastReceiver. and call your process inside this class. And in your manifest,

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

And add use permissions.

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

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

0
source

Source: https://habr.com/ru/post/1439979/


All Articles