Quantico
Quantico

Reputation: 2436

clear all past activities

I am trying to add a lock feature to my application from some of the actives, and I want to make sure that if a user presses the lock button, the user won't be able to press back and go to any of the past activities. So a return on the user's phone after lock will take the user to the phone's home.

I tried CLEAR_TOP but this is not doing the trick, any ideas why?

    Button lockButton = (Button) findViewById(R.id.lockButton);
lockButton.setOnClickListener(new Button.OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent(AccountListActivity.this, LockActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
    }
});

Upvotes: 1

Views: 779

Answers (1)

Jambaaz
Jambaaz

Reputation: 2848

  FLAG_ACTIVITY_CLEAR_TOP    

It would clear the stack only when you are going to relaunch the first activity , but in your case You are launching a new activity .so It would not clear the previous activities.

You can do one thing to implement your requirements -

Create an Interface and implement in all activities.

then when you are going to launch the LockActivity , before that call the delegate of Interface to finish all the activities.

Upvotes: 1

Related Questions