In android there is option in
Settings->application->your app-> force close
Does anyone know how does it work programmatically?
I tried a lot of things to close my app and those not working properly.
And those shutting down app completely with all threads/services.
Anyway I need something what close my app with threads sevices and everything.
public void turnOffApp() {
try {
for (IThreadController thread : Objects.threadList) {
thread.stopThread();
}
Log.d(Objects.context.getString(R.string.complete), Objects.context.getString(R.string.turningOffThreads));
finish();
} catch (Exception e) {
Log.d(Objects.context.getString(R.string.error), Objects.context.getString(R.string.throwErrorWhileStoppingThreads), e);
}
}
Objects.threadList is a globalObject where i store all my created threads. Btw is fire also when app closeing or crashes and then it's work corectly but i want to have it also in button and here isn't work so well
There is no direct way to kill application, though you can achieve this by let say on pressing a button you load First activity and clear all other activities in stack. Now you are left with one activity to deal with, to finish that you can do as following :
The above code removes all activities from stack except for FirstActivity. To finish the FirstActivity enter the below code in Firstactivity's oncreate
Hope it helps!