我有一个扩展了
下面是我的Application类实现:
Application
类的Android应用程序,其中有许多应用程序组件(服务、活动和广播接收器)运行在三个不同的进程中。
每个进程在启动时都会实例化Application
类。因此,我一直在寻找如何在Application
类代码内部检查实例是否由主应用程序进程拥有,但我没有找到任何信息。
我的清单看起来像这样:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name=".MyApplication"
android:theme="@style/AppTheme" >
<activity
android:name="...">
...
</activity>
<activity
android:name="...">
...
</activity>
<service android:name="..." >
</service>
<service android:name="..."
android:process=":SecondProcess" >
</service>
<service android:name="..."
android:process=":ThirdProcess" >
</service>
下面是我的Application类实现:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
if (is this instance being ran on the main process?) {
// Do something
}
}
}
有人知道如何检查实例是否在主进程上运行吗?