android - 从另一个进程中的应用程序上下文启动 Activity

标签 android process

为了在 Activity 上下文之外启动 Activity ,我们将使用应用程序上下文。就像 applicationContext.startActivity(new Intent(TestActivity.class ....))

如果调用startActivity的服务在另一个进程中,那么applicatioContext也属于另一个进程吗? android会为每个正在运行的进程组件创建applicationContext吗?

如果我们不指定TestActivity正在运行的进程,它是否也能够从另一个进程启动?

最佳答案

应用程序上下文不属于任何进程。但所有进程都属于应用程序。 Android 应用程序上下文是 Singleton,因此,您只有其中之一可用于所有用途。

如果您从服务或其他不是另一个 Activity 上下文的其他内容启动 Activity,则应使用 Intent.FLAG_ACTIVITY_NEW_TASK 标志。

用法如下:

Intent dialogIntent = new Intent(this, MyActivity.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialogIntent);

关于android - 从另一个进程中的应用程序上下文启动 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45095873/

相关文章:

windows - 如何根据子线程的线程 ID 查找进程的 pid?

java - 恢复倒计时

android opengles 将图像显示为纹理

linux - 如果iowait现在是99%,CPU还能执行其他进程吗

c - Windows : trouble with command line arguments 上的进程和线程 C 编程

linux - init 的僵尸 child

Android Intent 打开图库在 KitKat (4.4) 上不起作用

android - 自定义类上的不可序列化异常 - Android

android - 交换安卓 View

c# - 从 Threadpool 工作线程启动进程(并在需要时等待)