I have been searching around for a way to kill my application after the user put it in the background for at least 30min.
So far what i have found things like :
getActivity().finish();
Process.killProcess(Process.myPid());
System.exit(1);
private void stopServices() {
final ActivityManager activityManager = SystemServices.getActivityManager(context);
final List<ActivityManager.RunningServiceInfo> runningServices = activityManager.getRunningServices(Integer.MAX_VALUE);
final int pid = Process.myPid();
for (ActivityManager.RunningServiceInfo serviceInfo : runningServices) {
if (serviceInfo.pid == pid && !SenderService.class.getName().equals(serviceInfo.service.getClassName())) {
try {
final Intent intent = new Intent();
intent.setComponent(serviceInfo.service);
context.stopService(intent);
} catch (SecurityException e) {
// handle exception
}
}
}
}
Pretty much what i have figered so far is taht after API 21 use
finishAndRemoveTask();
before that use this.finishAffinity();
But how to start timer once the app is put in the background
for X time and then call the app kill method.