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??
My service class
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;
}
in first attempt LogCat
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
in second attempt LogCat
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
why is it like that every time? Thanks in advance.