How do I avoid onCreate() being called when starting an Activity?

后端 未结 5 401
难免孤独
难免孤独 2021-01-13 14:27

I want to reload an activity from stack.

I use startActivity() to start new activities. When I\'m on Activity D I want to reload Activity A

5条回答
  •  死守一世寂寞
    2021-01-13 14:54

    The following is not true. startActivityForResult() and startActivity() only differ in the return target of the called Activity

    try using startActivityForResult() rather than startActivity(). I believe this does not completely end the activity and start it again. I would recommend using this link in order to further read on how to implement such a method.

    So point 2 of @Kgrover does not hold too.

    The Intent flag http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_REORDER_TO_FRONT does exactly this.

    Keep an eye out on the Intent flags whenever you have requirements centered around Activity transitions. The system has excellent support.

    This is equivalent to Sam Quest's solution, the only difference being that if you set the launchMode, the stack-behavior of your Activity is hardcoded i.e. your Activity A is always in the singleTask mode.

提交回复
热议问题