私はAppWidgetProviderを持っており、ホームスクリーンにウィジェットが最初に追加されたときに初期化を行う必要があります。私はそれを行う場所がonEnabled(コンテキストコンテキスト)メソッドにあることを理解しています。私の問題は、このメソッドが呼び出されないことです(私がlogcatで見る限り)。ここでAppWidgetProviderの問題
は私のコードです:
public class MyMonitorWidget extends AppWidgetProvider{
@Override
public void onEnabled(Context context) {
super.onEnabled(context);
Log.v("LOG", "Widget onEnabled");
Intent intentToFire = new Intent(UpdateAlarmReceiver.ACTION_UPDATE_ALARM);
context.sendBroadcast(intentToFire);
}
...
}
そして、私のappwidget・プロバイダーのxml:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/widget_layout"
android:minWidth="146dp"
android:minHeight="74dp"
android:label="Monitor Widget"
/>
とマニフェストで:
<receiver android:name="MyMonitorWidget" android:label="Monitor Widget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<intent-filter>
<action android:name="com.android.myMonitor.ACTION_NOTIFY_WIDGET"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/monitor_widget_info"/>
</receiver>
あなたは問題は何だと思いますか?
CommonsWareの答えが正しいですが、障害のあるコードをいじってきた場合、あなたはおそらく、それが作業を開始する前のアプリをアンインストールする必要がありますしたとき、私は
onDelete()
を受信しませんでした。 –