Mousa Jafari
Mousa Jafari

Reputation: 677

Service stops, once removed from the list of recent activities

I've an IntentService that should works indefinitely, even if application stops working.

This is my service:

public class TestService extends IntentService {

    public TestService() {
        super("test");
    }

    @Override
    protected void onHandleIntent(Intent intent) {

        while (true) {
            // do works
            SystemClock.sleep(60000);
        }
    }
}

And manifest:

<service android:name=".TestService" />

My service works well as long as I did not remove my application from the list of recent activities, but I want it works at all times.

Based on my searches I realized that if I set android:stopWithTask to false in the manifest and overriding onTaskRemoved method in the service, I'll be able to handle my service.

<service
    android:enabled="true"
    android:name=".TestService"
    android:exported="false"
    android:stopWithTask="false" />

But this requires API level 14 or higher and my app API level is 8.
How can I solve my problem?

Upvotes: 1

Views: 320

Answers (1)

Roll no1
Roll no1

Reputation: 1393

If you want service to be run indefinetely then why you have use IntentService. You should be using Service which will run indefinetlely. IntentService will be closing itself after completing the task it was asked to do and will pack another request from quene if any request comes.
Please check below link or link

Upvotes: 1

Related Questions