Android Activites 的 onPause() 和 onStop() 有什么区别? [英] What is the difference between onPause() and onStop() of Android Activites?

查看:27
本文介绍了Android Activites 的 onPause() 和 onStop() 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从这里的 android 文档 http://developer.android.com/reference/android/app/Activity.html,它说活动进入前台"将调用 onPause(),活动不再可见"将调用 onStop().

From android doc here http://developer.android.com/reference/android/app/Activity.html, it said 'Activity comes into foreground' will call onPause(), and 'Activity is no longer visible' will call onStop().

活动进入前台"与活动不再可见"是否相同?你能告诉我它们之间有什么区别吗?

Isn't 'Activity comes into foreground' same as 'Activity is no longer visible'? Can you please tell me what is the difference between them?

推荐答案

不,如果某个 Activity 进入前台,并不一定意味着另一个 Activity 完全不可见.考虑以下情况:

No, if some activity comes into foreground, that doesn't necessarily mean that the other activity is completely invisible. Consider the following case:

在这里,我们同时看到了这两个活动.带有字段的第一个活动被另一个活动遮挡,用户无法再与其交互.但是,它仍然可以看到所有由此产生的后果.

Here we see both activities at the same time. The first activity with the fields is obscured by another activity, and the user can no longer interact with it. However, it is still visible with all the resulting consequences.

这就留下了一个问题,哪些活动被认为是完全不透明的并覆盖了整个屏幕,哪些不是.该决定基于包含活动的窗口.如果窗口有标志 windowIsFloatingwindowIsTranslucent,则认为 Activity 没有使底层的东西不可见,否则会导致 onStop() 被调用.相关代码可以在com.android.server.am.ActivityRecord中找到:

That leaves a question which activity is considered fully opaque and covering the whole screen and which isn't. This decision is based on the window containing the activity. If the window has a flag windowIsFloating or windowIsTranslucent, then it is considered that the activity doesn't make the underlying stuff invisible, otherwise it does and will cause onStop() to be called. The relevant code can be found in com.android.server.am.ActivityRecord:

fullscreen = ent != null && !ent.array.getBoolean(
        com.android.internal.R.styleable.Window_windowIsFloating, false)
        && !ent.array.getBoolean(
        com.android.internal.R.styleable.Window_windowIsTranslucent, false);

这篇关于Android Activites 的 onPause() 和 onStop() 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆