Add New Activity:
public class ExitActivity extends Activity{
@Override protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if(android.os.Build.VERSION.SDK_INT >= 21){
finishAndRemoveTask();
}
else{
finish();
}
}
public static void exitApplicationAnRemoveFromRecent(Context mContext){
Intent intent = new Intent(mContext, ExitActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NO_ANIMATION);
mContext.startActivity(intent);
}
}
Now exit from other Activity:
@Override
public void onBackPressed() {
ExitActivity.exitApplicationAnRemoveFromRecent(mContext);
super.onBackPressed();
}
Disclaimer: Hiren Patel (http://stackoverflow.com/questions/13385289/remove-app-from-recent-apps-programmatically)
No comments :
Post a Comment