Xamarin 简明教程
Xamarin - Android Activity Lifecycle
当用户浏览一个 Android 应用时,会发生一系列事件。例如,当用户启动一个应用,例如 Facebook 应用,它会启动并且对用户在前台可见, onCreate() → onStart() → onResume() 。
When a user navigates through an Android App, a series of events occurs. For example, when a user launches an app, e.g., the Facebook App, it starts and becomes visible on the foreground to the user, onCreate() → onStart() → onResume().
如果另一个活动启动,例如电话呼入,那么 Facebook 应用将进入后台,通话进入前台。我们现在有两个正在运行的进程。
If another activity starts, e.g., a phone call comes in, then the Facebook app will go to the background and the call comes to the foreground. We now have two processes running.
onPause() --- > onStop()
当通话结束时,Facebook 应用返回前台。会调用三个方法。
When the phone call ends, the Facebook app returns to the foreground. Three methods are called.
onRestart() --- > onStart() --- > onResume()
Android 活动中有 7 个生命周期进程。它们包括如下:
There are 7 lifecycle processes in an Android activity. They include −
-
onCreate − It is called when the activity is first created.
-
onStart − It is called when the activity starts and becomes visible to the user.
-
onResume − It is called when the activity starts interacting with the user. User input takes place at this stage.
-
onPause − It is called when the activity runs in the background but has not yet been killed.
-
onStop − It is called when the activity is no longer visible to the user.
-
onRestart − It is called after the activity has stopped, before starting again. It is normally called when a user goes back to a previous activity that had been stopped.
-
onDestroy − This is the final call before the activity is removed from the memory.
下面的插图展示了 Android 活动生命周期:
The following illustration shows the Android Activity Lifecycle −