问题
I have two tabs. In these two tabs I have different activity groups. How to navigate from an activity in one activity group to another activity in android? Please help me with suitable examples.
回答1:
To programmatically switch between tabs use the TabHost
method setCurrentTab(int index)
or setCurrentTabByTag(String tag)
. The user can also click the tab UI (if used) to switch between them.
回答2:
in my case i did like this when i click on finish/submit button in last activity of parent group ,,i submitted values(storing values into server /database ) and i finished parent activity like getParent().finish();, and starting tabs activity and setting current tab like setCurrentTab(int)
it may not best approach but it may useful
sorry for my language
回答3:
The best way of handling this is to use
startActivityForResult(intent, int);
Along with overriding your activity's
protected void onActivityResult (int requestCode, int resultCode, Intent data)
Whenever you're activity finishes, you will want to set the result to a certain code:
public final void setResult (int resultCode)
When the activity finishes, the previous activity's onActivityResult call will be invocated with the result code passed. Here, you can check for the result code and request code and then perform an action. In this case, you will want to do a cascading activity pop until you reach the first activity in the list. You can then set the result for this previous activity and finish it which will then trigger the next activity's onActivityResult. You can then do this until you reach the 'first' activity in your activity stack.
This method is also flexible because it lets you conditionally pop to certain points in your activity stack depending on how you handle the request code and result code.
来源:https://stackoverflow.com/questions/9435630/how-to-navigate-from-activity-in-one-activity-group-to-another-activity-in-andro