Can Android Kill My App While It Is In The Middle Of A Loop Execution?
When Android decides to remove an application from the stack in order to free up some RAM, what happens if the application that is being destroyed is currently running some loop in
Solution 1:
Will the loop be terminated amid execution or will the VM wait for it to finish?
The loop is terminated, otherwise it isn't quite "killing".
Simple test:
publicclassMainActivityextendsActivity {
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
newThread(newRunnable() {
@Overridepublicvoidrun() {
try {
while (true) {
Log.i("LOOP", "Running");
Thread.sleep(1000);
}
} catch (InterruptedException e) {}
}
}).start();
}
}
Swipe the app out from the recent apps.
Post a Comment for "Can Android Kill My App While It Is In The Middle Of A Loop Execution?"