Вы можете создать service
и переписать onTaskRemoved()
метод
Из Documentation
пользователь удалила задача означает ударяя приложение из из задачи список. Остановка службы из настроек телефона не запускается Service.onTaskRemoved().
Код:
public class AppStopped extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("Service", "Service Started");
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d("Service", "Service Destroyed");
}
@Override
public void onTaskRemoved(Intent rootIntent) {
Log.e("Service", "END");
Toast.makeText(getApplicationContext(), "App Stopped", Toast.LENGTH_SHORT).show();
//Code here
stopSelf();
}
}
В манифесте:
<service android:name="com.example.AppStopped"
android:stopWithTask="false" />
Запустите службу в своей деятельности, как:
startService(new Intent(getBaseContext(), AppStopped.class));
http://stackoverflow.com/questions/5593115/run-code-when-android-app-is-closed-sent-to-background Это должно содержать все необходимые вам ответы – Nico