Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid service crashes after app is swiped out of the recent apps list
    primarykey
    data
    text
    <p>I have a service that gets started (not bound) by an activity. If the activity gets destroyed (e.g. by pressing the back button), the service continues to run, this is of course intended. However, if I swipe the activity out of the 'recent apps' list, the service gets restarted immediately. This is reproducible, every time the activity/app is swiped out of the list, there is a new call to the service's onCreate-method. No call to onDestroy in between!</p> <p>First I thought the service gets killed by android, even though I saw no reason for the kill (neither the activity nor the service do resource consuming things, in fact they are minimalistic and do nothing). But then I noticed that the service actually crashes.</p> <pre><code>V/MainActivity(856): onDestroy // swipe out of the list I/ActivityManager(287): Killing 856:com.example.myapp/u0a10050: remove task W/ActivityManager(287): Scheduling restart of crashed service com.example.myapp/.TestService in 5000ms </code></pre> <p>The code is not noteworthy, but here it is</p> <p>Activity:</p> <pre><code>public class MainActivity extends Activity { private static final String TAG = "MainActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.v(TAG, "onCreate, starting service..."); startService(new Intent(this, TestService.class)); } @Override protected void onStart() { super.onStart(); Log.v(TAG, "onStart"); } @Override protected void onDestroy() { super.onDestroy(); Log.v(TAG, "onDestroy"); } //[...] } </code></pre> <p>Service:</p> <pre><code>public class TestService extends Service { private static final String TAG = "Service"; // onBind omitted @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.v(TAG, "onStartCommand"); return super.onStartCommand(intent, flags, startId); } @Override public void onDestroy() { super.onDestroy(); Log.v(TAG, "onDestroy"); } } </code></pre> <p>In short: My service is independent of the activity's lifecycle, but only as long as I don't swipe out the app of the recent apps list. In that case, the service gets restarted but without a call to onDestroy.</p> <p>Every time this happens, not only the state of the service, but also the work the service is doing is lost. I just want to know why the swipe is the reason for this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload