在我的Android应用程序中,我有一个
我还有一个
我的问题是,在没有与
以下是
DefaultApplication
类,它扩展了android.app.Application
,并且在其onCreate()
中绑定了一些服务,这些服务将被该应用程序中的其他活动使用。我还有一个
BroadcastReceiver
,它监听和接收C2DM消息。当该接收器在应用程序未运行时接收到消息时,它将触发显示即将到来的消息的对话框,并启动我的应用程序的Activity。我的问题是,在没有与
DefaultApplication
进行任何交互的情况下启动一个活动时,因为该应用程序的活动已启动,是否会调用DefaultApplication
的onCreate()
?以下是
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>
Application
?难道不应该扩展Activity
吗? - Caner