2

I'm developing an android application which contains a tabhost having 4 tabs. All 4 tabs navigate to same class Activity1 which extends activitygroup.

From Activity1 i'm again navigating to another activity Activity2 using following code,

Intent intent = new Intent(arg1.getContext(), Activity2.class);
            replaceContentView("sample", intent, Intent.FLAG_ACTIVITY_CLEAR_TOP);

public void replaceContentView(String id, Intent newIntent, int flag) {
    View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(flag)).getDecorView(); 
    this.setContentView(view);

Now from this new activity i need to come back to Activity1 when device back button is pressed. I overrided onbackpressed() method in Activity2 with following code,

Intent intent = new Intent(this, Activity1.class); 
    Activity parentActivity = (Activity1)getParent(); 
    parentActivity.replaceContentView("sample", intent, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT );

When i run the code, it actually move out of Activity2 but it also move out of Activity1. what i need is to come back to Activity1 from Activity2...can anyone help me?

akh
  • 2,478
  • 3
  • 23
  • 23
  • can u explain way you used replaceContentView() for navigating through activity.. you can simply start activity and finish it. – NaserShaikh Mar 01 '13 at 11:48
  • Because i want the tabs in Activity1 to be shown on the top of the new activity.... – akh Mar 01 '13 at 12:07

2 Answers2

0

Try this code

    public boolean onKeyDown(int keyCode, KeyEvent event)  
    {
     if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
     {
        this.moveTaskToBack(true);
        return true;
     }
    return super.onKeyDown(keyCode, event);
   }
androidgeek
  • 3,440
  • 1
  • 15
  • 27
  • Thanks for your response.......I tried it, but still it is moving out of application.. – akh Mar 01 '13 at 12:27
0

A simple call to finish() can address your needs.

You can refer Android: Go back to previous activity for detailed description.

Community
  • 1
  • 1
Divya Motiwala
  • 1,659
  • 1
  • 16
  • 24