Search code examples
android-intentandroid-tabhostandroid-tabs

How to Programmatically go back to a Tab Activity from sub activity


I created 4 tabs using tabHost in my application,when i click a button in the the first tabActivity(Request.class), it will go to another class called Edit.class, I want to go back from Edit.class to Request.class i tried intent to pass from one activity to another

   Intent intent = new Intent(Edit.this,Request.class);
 startActivity(intent);

it worked, but it doesnt show the tabs in the Request class, it load only the xml corresponding to Request.class. How to solve this?

                   |Tab1|Tab2|Tab3|Tab4|

                     |
                Edit.class

Here Tab1 is the Request.class, I need to go back from Edit.class to Request.class, How it possible?


Solution

  • Try the following code:

    public boolean onKeyDown(int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
    
             Intent i = new Intent(Activity1.this,Activity2.class);
                 startActivity(i);  
    
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }