Skip to content

Instantly share code, notes, and snippets.

@Takhion
Created June 1, 2015 16:34
Show Gist options
  • Save Takhion/8495ad44ace53ba8fff7 to your computer and use it in GitHub Desktop.
Save Takhion/8495ad44ace53ba8fff7 to your computer and use it in GitHub Desktop.
Task killer for Android
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity android:name=".TaskKiller"/>
</application>
</manifest>
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
public class TaskKiller extends Activity {
public static void killTask(Context context) {
final Intent intent = new Intent(context, TaskKillerActivity.class);
intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= 21) finishAndRemoveTask();
else finish();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment