how can we block previous activity
how can we block previous activity "if one go from ActivityA to ActivityB then he want come back previous activity means ActivityA so he shou开发者_运维知识库ld not able to come back" in android
If you want an activity to be removed from the activities stack when going to another one, use flag noHistory in your manifest.xml.
Like this:
<activity android:name=".MyActivity" android:noHistory="true" ... />
That way, if you doing A -> B -> C, and activity B has noHistory set to true, when pressing back on activity C, you'll get back directly to A. Or, if you have A -> B, you will exit the app, when pressing back while in activity B
You question is not really clear, but i'm interpreting it as follows:
You have an activity A, and then you start an activity B. If B is opened, normally you can go back to A by pressing "back". You want to prevent this.
You have at least 2 options.
1) capture the 'back' button in B and do something other then 'back' in your code
override the onKeyDown
(on 2.0+ you can use onBackPressed()
i think) , and add something like this:
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
//your alternative code here
}
return super.onKeyDown(keyCode, event);
- Stop acitivity A with
finish()
after loading B, so it's not there anymore.
精彩评论