RSS

Remove app from recent apps programmatically

01 Sep

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)

Advertisements
 
2 Comments

Posted by on September 1, 2016 in Android Source Code

 

2 responses to “Remove app from recent apps programmatically

  1. ashwinukey

    September 1, 2016 at 12:01 PM

    awesome bro . . . .

     
  2. Jayesh

    September 2, 2016 at 6:50 AM

    awesome

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: