首先调用哪个活动方法?

发布于 2024-11-30 20:53:26 字数 167 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

流云如水 2024-12-07 20:53:26

当你进入你的应用程序时,生命周期流程将是这样的:

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()

给妤﹃绝世温柔 2024-12-07 20:53:26

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.

傲性难收 2024-12-07 20:53:26

我猜你是安卓新手。这是一个描述活动生命周期的链接。 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.

挽容 2024-12-07 20:53:26

如果先前的 Activity 在后台消失时已被操作系统杀死,则再次调用 onCreate() 方法。或者它的 onResume() 方法被调用。

if the prevoius Activity has been killed by OS when its gone background then again onCreate() method is called. or else its onResume() method which gets called..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文