내 Android 애플리케이션에서 android.app.Application
을 확장하는 DefaultApplication
클래스가 있으며 onCreate()
에이 앱의 다른 활동에서 사용할 일부 서비스를 바인딩합니다.응용 프로그램의 onCreate() 메서드가 언제 호출됩니까?
나는 또한 BroadcastReceiver
을 수신하여 C2DM 메시지를 수신합니다. 응용 프로그램이 실행되고 있지 않을 때이 수신자가 메시지를 받으면 다가오는 메시지를 보여주는 대화 상자가 열리고 응용 프로그램의 활동이 시작됩니다.
제 질문은 DefaultApplication
과 아무런 상호 작용이없는 활동을 시작할 때 내 DefaultApplication
의 onCreate()
이 (가) 해당 응용 프로그램 활동이 시작 되었기 때문에 호출됩니까?
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;
}
}
}
매니페스트는 다음과 같습니다 : onCreate
이 here를 호출 할 때
<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>
네, 그것은이 작동, 내가 다른 사람 보지 못했 ... – atasoyh
나는 unserstand하지? '활동'을 확장해서는 안됩니까? – Caner
@LAS_VEGAS 나머지 DefaultApplication에서는 일부 데이터를 저장하고 응용 프로그램 전체에 사용되는 몇 가지 메서드를 정의합니다. 나는 그것의 일부만을 여기에 복사했다. –