Donny Dominic Donny Dominic - 2 years ago 148
Android Question

Service not restarting using START_STICKY on devices above API Level 25(Nougat)

I have got a service in my app which needs to be restarted after app removed from recent task list. Service restarts for API level 25 and below but not for 25 and above versions.Please help me with this issue and would like to know the best way to restart a service which is compatible to all OS versions.`public class XMPPMainService extends Service {

private static final String TAG = "XMPPMainService";

private static final int RECONNECT_TRY_INTERVAL_MS = 900; // 5 Seconds

private PendingIntent pendingIntent;

public void onCreate() {
Log.e(TAG, " onCreate ");


public IBinder onBind(Intent intent) {
return null;

public void onDestroy() {
Logger.LOGD(TAG, "onDestroy: ");
public int onStartCommand(Intent intent, int flags, int startId) {

//**********Manifest file

android:exported="false" />`

Answer Source

I don't know why it's not restarting for API 25 and above but, you can add android:stopWithTask="false" to your <service> tag in the manifest.

this will prevent the service to be destroyed when the user remove your app from recent tasks list

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download