在我的 Android 应用程序中,我有一个DefaultApplication
扩展类android.app.Application
,并且在其中onCreate()
我绑定了一些服务,这些服务将由我在这个应用程序中的其他活动使用。
我还有一个BroadcastReceiver
监听和接收 C2DM 消息的设备。当此接收器在应用程序未运行时收到消息时,它将触发一个对话框,显示即将到来的消息,并将启动我的应用程序的 Activity。
我的问题是,当我在没有任何交互的情况下启动Activity 时,会因为该应用程序的 Activity 启动而调用DefaultApplication
我DefaultApplication
的Activity 吗?onCreate()
以下是 my 的定义和清单DefaultApplication
:
public class DefaultApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
doBindService();
}
void doBindService() {
// Establish a connection with the service. We use an explicit
// class name because we want a specific service implementation that
// we know will be running in our own process (and thus won't be
// supporting component replacement by other applications).
bindService(new Intent(DefaultApplication.this, SocketService.class),
socketServiceConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
}
void doUnbindService() {
if (mIsBound) {
// Detach our existing connection.
unbindService(socketServiceConnection);
mIsBound = false;
}
}
}
清单看起来像这样:
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:name="com.mypackage.DefaultApplication"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:debuggable="true">
<service android:name="com.mypackage.services.SocketService"></service>
<activity android:name="TestActivity"
android:screenOrientation="landscape"></activity>
</application>