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

前端 未结 3 1482
余生分开走
余生分开走 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: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.

提交回复
热议问题