Can Android kill my app while it is in the middle of a loop?

When Android decides to remove an application from the stack in order to free some of the RAM , what happens if the application being destroyed is currently running some kind of loop in the background? Will the loop complete at run time or will the VM wait for it to complete?

+5
source share
1 answer

Will the loop end at run time or will the VM return to end it?

The cycle ends, otherwise it does not completely โ€œkillโ€.

A simple test:

 public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new Thread(new Runnable() { @Override public void run() { try { while (true) { Log.i("LOOP", "Running"); Thread.sleep(1000); } } catch (InterruptedException e) {} } }).start(); } } 

Deploy the app from the latest apps.

+4
source

Source: https://habr.com/ru/post/1239199/


All Articles