Tanmay Joshi
Tanmay Joshi

Reputation: 11

In android lifecycle, is there any unique method gets called when app is swiped from recent app list?

In android lifecycle, is there any unique method that gets called when the app is swiped from the recent app list? We initially thought we would use onDestroy but it gets called during other activities as well.

Upvotes: 0

Views: 108

Answers (1)

Hamid-Ghasemi
Hamid-Ghasemi

Reputation: 294

Add a service like below and start it. When app close onTaskRemoved run your code.

Manifest

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

Service class

public class ExitService extends Service {

@Override
public void onStartService() {}

@Override
public void onTaskRemoved(Intent rootIntent) {
    super.onTaskRemoved(rootIntent);
    this.stopSelf();
}}

Upvotes: 0

Related Questions