Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Remove all the previous activities from the back stack in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 775
    Comment on it

    Whenever you switch from one activity to another using intent and specially in the case of logout and sessions related android applications you will find activity back stack issue. Here i will show you a small piece of code which will help you to close all the activity running in the background and clear all the backstack. You just have to follow instruction given below.

    First you have add this piece of code in all your activities which you want to kill from the background.

     IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("CLOSE_ALL");
        BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
              Class.this.finish();
          }
        };
        registerReceiver(broadcastReceiver, intentFilter);
    

    Now you just call this method from where you want to close all the activity from background.

     public void closeAllActivity()
    {
        Intent intent1 = new Intent("CLOSE_ALL");
        this.sendBroadcast(intent1);
    }
    

    Hope it solve you problem. :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: