私が構築しているAndroidアプリケーションで奇妙な問題が発生しています。アプリケーションは基本的にホームスクリーン代替アプリケーションです。AndroidアプリケーションonCreateが再起動時にホームスクリーンランチャーアプリに呼び出されない
<application android:persistent="true" android:icon="@drawable/icon"
android:label="@string/app_name" android:name="com.webgyani.android.MyApplication"
android:debuggable="true">
<activity android:name=".HomeTabActivity" android:launchMode="singleInstance"
android:stateNotNeeded="true" android:theme="@style/LightTabsTheme"
android:screenOrientation="landscape" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
:マニフェストファイルの
public class MyApplication extends Application implements ExternalStorageListener {
private ExternalStorageObserver externalStorageObserver;
public void onCreate() {
Log.i("MyApplication", "Starting application");
super.onCreate();
externalStorageObserver = new ExternalStorageObserver(this);
if(externalStorageObserver.isExternalStorageAvailable()) {
// this builds a list of files present in the SD card
// which is being used through the application to do
// some work
buildData();
File externalFileDir = getApplicationContext().getExternalFilesDir(null);
if(externalFileDir != null && externalFileDir.isDirectory()) {
// do something...
}
}
//Register listener to observe external storage state
registerExternalStorageObserver();
Log.i("SyncService", "Starting sync service...");
ComponentName cmp = startService(new Intent(getApplicationContext(), SyncService.class));
Log.i("SyncService", cmp.toString());
}
private void registerExternalStorageObserver() {
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
filter.addAction(Intent.ACTION_MEDIA_REMOVED);
registerReceiver(externalStorageObserver, filter);
}
private void buildData() {
// builds a list
}
}
内容:私は、Android Applicationクラスを拡張してきたし、onCreate()
方法で、私は基本的にいくつかのオブザーバーを登録し、サービスを開始していますいくつかの初期化作業を行うために、ここでのコードですこれは、Eclipseを使用してアプリケーションをインストールするか、apkをデバイスに手動でインストールするときにうまく動作します。アプリケーションがインストールされると正常に動作しますが、上記のonCreate()
メソッドが呼び出され、サービスも正常に開始されますが、今度はデバイスを再起動するとonCreate()
メソッドが呼び出されません(ログステートメントは表示されません)開始されていません)。いくつかのデバッグの後、私はデフォルトのランチャー/ホームスクリーンアプリとしてアプリケーションを設定してからデバイスを再起動すると、これが起こることに気付きました。私の場合、アプリケーションは起動されますが、そのコードは実行されません。
デバッガを使用しようとしましたが、デバイスを再起動するとデバッガが切断され、USBデバッグが有効になるまでにアプリケーションが既に起動されているため動作しませんでした。
Logcatをダブルチェックしてもエラーは表示されませんでした。私は、その部分を初期化するためにBOOT_COMPLETEDインテントを持つことを考えましたが、解決策がない限り、この時点ではやりたくないコードリファクタリングが必要になります。
私はこれが標準的な動作であるかどうか、またはこれを引き起こす既知のバグがあるかどうか不思議です。アプリケーションのonCreate
メソッドが常に呼び出されるということです。私は午前中にできることは何でも試しましたが、何も働かず、問題を正確に指摘できませんでした。
おかげ