Switching between activities in android?

前端 未结 7 568
有刺的猬
有刺的猬 2020-12-18 10:22

In my android application, I have following requirement.

Activity A --> Activity B(Go to A Option) --> Activity C(Go To A Option,Go To B Option)

<
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 11:01

    Why can't you use,

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //Save your current instance
    }
    

    "...This method is called before an activity may be killed so that when it comes back some time in the future it can restore its state. For example, if activity B is launched in front of activity A, and at some point activity A is killed to reclaim resources, activity A will have a chance to save the current state of its user interface via this method so that when the user returns to activity A, the state of the user interface can be restored via onCreate(Bundle) or onRestoreInstanceState(Bundle)..."

    I think that is what you wanted. With this you can use Intent from Activity C. Yes then it goes to onCreate method, BUT there you are checking whether there is any saved instance. If there are any saved instance you no need to load the rest of the onCreate items. It will speed your application.

提交回复
热议问题