Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

launch an activity using intent and disable back button press from launching the previous activity

In my application. I have a login screen. If the login is successful, a tab activity will launch, in that there are 4 tabs. When I press one of the buttons in the tab, a new activity will launch. there is an event in my login class that will get fired in some cases. I want to go back to the tab activity when the event get fired. I have written a code using Intent. That code is working fine. But after reaching the tab activity I don't want to go back to the activity when back button is pressed. I want to remove this. I want to show login when Back is pressed. Is there any way to do this? This is the code I have used:

Intent tabi=new Intent(getApplicationContext(),Tab.class);
startActivity(tabi);

The code onkeydown in tab activity is:

    @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {


        super.onKeyDown(keyCode, event);
        return true;
    }
    return false;
}
like image 737
irfan Avatar asked Jan 16 '14 06:01

irfan


1 Answers

Intent tabi=new Intent(getApplicationContext(),Tab.class);
            startActivity(tabi);
finish();
like image 104
Digvesh Patel Avatar answered Sep 28 '22 04:09

Digvesh Patel