How to navigate from activity in one activity group to another activity in android

前端 未结 3 1480
余生分开走
余生分开走 2021-01-16 16:18

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 wi

相关标签:
3条回答
  • 2021-01-16 17:11

    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

    0 讨论(0)
  • 2021-01-16 17:15

    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.

    0 讨论(0)
  • 2021-01-16 17:18

    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.

    0 讨论(0)
提交回复
热议问题