gpt4 book ai didi

android - Android中任务和进程的区别

转载 作者:IT王子 更新时间:2023-10-28 23:44:51 26 4
gpt4 key购买 nike

我对 Android 中的任务和进程之间的区别有点困惑。

如果我理解正确,任务只是一堆 Activity 。从我目前阅读的内容来看,我认为一项任务可能如下所示:

| Activity A running in Process P1 |
| Activity B running in Process P2 |
| Activity C running in Process P3 |

所以基本上来自不同进程的 Activity 可以包含在同一个堆栈中。我说的对吗?

另一个问题:“应用程序上下文”的真正含义是什么?过程还是任务?

还有最后一个问题:应用程序类(基本上是一个单例)代表进程还是任务?

最佳答案

我所学到的一切,我都在这个 page. 上学到了

编辑:我也偶然发现了Activity and Task Design Guidelines.它看起来涵盖了您询问的确切主题。我学到了很多:)

So basically activities from different processes can be contained in the same stack. Am I correct?

根据我的理解,您是正确的。我的理解是,流程是实际执行的单元,而任务是关于完成事情的关联。作为上述页面的示例,如果您创建打开网页的 Intent ,则它创建的 Activity 是在 Web 浏览器进程上创建的,但与您的应用程序任务相关联。因此,根据提供 Activity 的应用程序,任务会变成在不同进程上运行的虚拟 Activity 堆栈。


Another question: What is the real meaning of "application context"? The process or the task?

这是个好问题。根据阅读上面的页面,我的理解是应用程序上下文与流程相关联。我基于该页面对这一行的解释,但可能还有其他信息:

Normally, a new instance of an activity is launched into the process of the application that defined it, so all instances of the activity run in the same process


And final question: The application class (which is basically a singleton) represents the process or the task?

按照与上述相同的解释,我猜为什么 Application 对象代表 Singleton 是因为您的所有应用程序 Activity 都在单个进程上运行,并且该进程与应用程序相关联。我不知道这是一个设计点,但它似乎至少是当前设计的结果。

编辑:对此有一些警告。看来您的应用程序可以分布在多个进程中,所以我的猜测是应用程序对象和上下文充当将所有进程绑定(bind)在一起的机制。我很确定您的心智模型已经允许这样做,假设进程来自不同的应用程序,因此允许它在单个进程中只有很小的区别。

manifest元素有属性android:process,描述如下:

The name of the process in which the activity should run. Normally, all components of an application run in the default process created for the application. It has the same name as the application package. The element's process attribute can set a different default for all components. But each component can override the default, allowing you to spread your application across multiple processes. If the name assigned to this attribute begins with a colon (':'), a new process, private to the application, is created when it's needed and the activity runs in that process. If the process name begins with a lowercase character, the activity will run in a global process of that name, provided that it has permission to do so. This allows components in different applications to share a process, reducing resource usage.

关于android - Android中任务和进程的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4936581/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com