Why My Android App Force Stopped After Swiping From Recent Tray
<p>My android app is force stopped on the second attempt i clear the  recent tray. On my first it doesn't being force stopped.. what may be the reason??<br>
<strong>My service class</strong></p>

<pre><code>public class TheService extends Service {
 @Override
public void onCreate() {
    super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.v("myapp","service started");
    return START_STICKY;
}
@Override
public void onTaskRemoved(Intent intent)
{
    Log.v("HAHAHA","TASK IS REMOVED");
    stopService(new Intent(getApplicationContext(),this.getClass()));
        Intent restartService = new Intent(getApplicationContext(),
                this.getClass());
        restartService.setPackage(getPackageName());
        Random generator = new Random();
        PendingIntent restartServicePI = PendingIntent.getService(
                getApplicationContext(), generator.nextInt(), restartService,
                PendingIntent.FLAG_ONE_SHOT);
        AlarmManager alarmService = (AlarmManager)getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() +1000, restartServicePI);
    super.onTaskRemoved(intent);
}
@Override
public void onDestroy() {
    Log.v("HAHAHA","APP KILLED");
}

@Nullable
@Override
public IBinder onBind(Intent intent) {
    return null;
}
</code></pre>

<p><strong>in first attempt LogCat</strong></p>

<pre><code>10-24 06:44:11.742 6958-6958/miniproject.gazastreet V/HAHAHA: TASK IS REMOVED
10-24 06:44:11.752 6958-6958/miniproject.gazastreet V/HAHAHA: APP KILLED
10-24 06:44:12.752 6958-7148/miniproject.gazastreet V/myapp: service started
</code></pre>

<p><strong>in second attempt LogCat</strong></p>

<pre><code>10-24 06:46:48.508 6958-6958/miniproject.gazastreet V/HAHAHA: TASK IS REMOVED
10-24 06:46:48.518 6958-6958/miniproject.gazastreet V/HAHAHA: APP KILLED
</code></pre>

<p>why is it like that every time?
Thanks in advance.</p>