私のAndroidアプリケーションには、DefaultApplication
を拡張するクラスがandroid.app.Application
あり、そのonCreate()
中に、このアプリの他のアクティビティで使用されるいくつかのサービスをバインドします。
また、BroadcastReceiver
C2DMメッセージをリッスンして受信するがあります。この受信者は、アプリケーションが実行されていないときにメッセージを受信すると、次のメッセージを表示するダイアログを起動し、アプリケーションのアクティビティを開始します。
私の質問は、との対話なしでアクティビティを開始すると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>