Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have seen that intent service usually restarts if we destroy the app in the middle of service execution. But here I tried doing the same and I expected it to restart but that doesnt happen.

What's wrong here ? Am I missing something.


here's full service code :


package com.deepesh.startedserviceapp;

import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
import android.widget.TextView;


public class MyIntentService extends IntentService {


    public MyIntentService() {
        super("MyIntentService");
        //This restarts the service is the app is terminated.
        setIntentRedelivery(true);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d("Keyy","Oncreate executed " + "Thread : " + Thread.currentThread().getName());
    }

    @Override
    protected void onHandleIntent(Intent intent) {

        Log.d("Keyy","This is from intent service." + "Thread : " + Thread.currentThread().getName());

        for (int i=0;i<10;i++){
            try {
                Thread.sleep(1000);
                Log.d("keyy","Counter : " + i);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d("Keyy","OnDestroy executed " + "Thread : " + Thread.currentThread().getName());
    }
}


What I have tried:

Tried google but their is no new updated solution for this problem
Posted
Updated 16-Jul-20 1:47am

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900