首先调用哪个活动方法?
Android 中哪个 Activity 方法首先被调用?例如,如果是 iPhone,则首先调用 viewWillAppear
。
另外有人可以告诉我当我从一个活动返回到上一个活动时,首先调用哪个方法?我不想每次返回活动时都一次又一次地加载所有内容。
谢谢,
石头
Which activity method is called first in Android? For example viewWillAppear
is called first in case of IPhone.
Also can someone tell me when I come back from an activity to previous activity, which method is called first? I don't want to load everything again and again each time I come back to an activity.
Thanks,
Stone
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当你进入你的应用程序时,生命周期流程将是这样的:
onCreate() -> onStart() ->; onResume()
现在,如果您使用意图从当前 Activity 移动到下一个 Activity,则将执行以下当前 Activity 的方法:
onPause() ->; onStop()
当您返回同一个 Activity 时(例如,使用返回键事件),这些是将执行的当前 Activity 的方法:
onStart() ->; onResume()
当您退出应用程序时,流程如下所示:
onPause() -> onStop() ->; onDestroy()
When you enter your app, the life cycle flow will be like this:
onCreate() -> onStart() -> onResume()
Now if you are using an intent to move from your current Activity to the next Activity, these are the methods of the current activity that will be executed:
onPause() -> onStop()
When you come back to the same activity(e.g., using back key event), these are the methods of the current activity that will be executed:
onStart() -> onResume()
And when you exit your app, the flow goes like this:
onPause() -> onStop() -> onDestroy()
Activity 生命周期 文档中提供了您需要的所有信息。您应该阅读它,因为理解它很重要。顺便说一下,viewWillAppear 在 iPhone 上并不是首先被调用的。在此之前调用了几个方法。
All the information you need is provided in the documentation on Activity lifecycle. You should read it as it is important to understand. Incidentally, viewWillAppear is not called first on the iPhone. There are a couple methods called before that.
我猜你是安卓新手。这是一个描述活动生命周期的链接。 LINK
简而言之 onCreate 被调用首先,当您从活动中返回时 onResume 将被调用。 onResume 也将在第一次被调用。每当活动进入后台时,onPause就会被调用。
i guess you are new to android. here is a link which describes about the life cycle of an activity. LINK
in short onCreate is called first and when you comeback from an activity onResume will be called. onResume will also be called the first time as well. onPause will be called whenever an activity goes background.
如果先前的 Activity 在后台消失时已被操作系统杀死,则再次调用
onCreate()
方法。或者它的onResume()
方法被调用。if the prevoius Activity has been killed by OS when its gone background then again
onCreate()
method is called. or else itsonResume()
method which gets called..