Android的活动周期:ONSTART() - >的onStop()可能吗?周期、Android、ONSTART、onStop

2023-09-05 00:49:31 作者:゛物是人非的伤,

在 Android的应用程序基础它说,在调用后,在ONSTART() - 活动周期的方法,无论是回调方法 onResume()的onStop()被调用。如果是一个正常的启动活动的系统调用的onCreate() ONSTART() onResume()。 但是否有人知道一个例子,其中 ONSTART() - 的onStop()是一个接一个执行

解决方案

从你的活动,开始另一项活动,是不是全屏幕(例如给它的android:主题=@安卓风格/ Theme.Dialog)。

在这一点上你的第一个活动已在onPause()调用但不是的onStop(),因为它是不是在前面,但仍清晰可见。

preSS回家。

在这一点上的onStop()被调用你的第一个活动。

重新启动你的应用程序。

在这一点上ONSTART()被调用你的第一个活动,但不onResume(),因为它仍然在它之上的非全屏幕活动。

preSS回家。

在这一点上的onStop()调用的第一个活动,而无需通过onResume()已经走了。

In the Android Application Fundamentals it says that after the call to the onStart()-method of the activity lifecycle either the callback method onResume() or onStop() is called. In case of an "normal" Start of an activity the system calls onCreate(), onStart(), onResume(). But does somebody know an example where onStart() - onStop() are executed one after another?

解决方案 android开发之三 Activity的生命周期 onCreate 和onStart

From your activity, start another activity that is not full-screen (for example give it android:theme="@android:style/Theme.Dialog").

At this point your first activity has had onPause() called but not onStop() because it is not in the front but still visible.

Press home.

At this point onStop() is called for your first activity.

Relaunch your app.

At this point onStart() is called for your first activity, but not onResume() because it still has the non-full-screen activity on top of it.

Press home.

At this point onStop() is called on the first activity, without having gone through onResume().

 
精彩推荐
图片推荐