4

my apps background process stops on device rebooting. What to do to make it always running also after device booted. Because my notification did not show on device boot

Umesh
  • 43
  • 3

2 Answers2

0

You have 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 uses permission.

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Umesh Suryawanshi
  • 934
  • 1
  • 7
  • 21
0

Example code for manipulate your application onBoot of your application -

public class OnBootReceiver extends BroadcastReceiver 
{
   @Override
   public void onReceive(Context context, Intent intent) {
      Log.d("OnBootReceiver", "Hi, Mom!");
   }
}

Add the below permission for onBoot service -

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

And, in your manifest file, you've to add the OnBootReceiver class for register it like below -

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

A perfect example from Commonsware available on GitHub

Community
  • 1
  • 1
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173