2011-12-17 20 views
3

AppWidgetProviderに関する問題があります。電話機が起動すると、AppWidgetProvideronUpdate()メソッドが連続して4回呼び出され、すべて同じものが含まれます。appWidgetId。なぜそれが起こっているのか分かりません。誰かが手掛かりを持っていますか?AppWidgetProvider、起動時にonUpdateが何度か呼び出される

私は super classesを拡張super classesMainMainScroll、およびfour classes(widgets)の2種類を得ました。

例ウィジェット

public class WidgetMedium extends Main { 

    public void onReceive(Context context, Intent intent) { 
     super.onReceive(context, intent); 
    } 

} 

マニフェスト

 <receiver android:name=".activity.Main"> 
     <intent-filter> 
      <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
     </intent-filter> 
    </receiver> 

    <receiver android:name=".activity.MainScroll"> 
     <intent-filter> 
      <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
     </intent-filter>  
    </receiver> 

    <receiver android:name=".activity.WidgetMedium" 
     android:label="Swedroid Widget 4x3" 
     android:icon="@drawable/widget_application"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <intent-filter> 
      <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
     </intent-filter> 
     <meta-data 
      android:name="android.appwidget.provider" 
      android:resource="@xml/widget_provider_medium" /> 
    </receiver> 

    <receiver android:name=".activity.WidgetScrollMedium" 
     android:label="Swedroid Widget 4x3 Scroll" 
     android:icon="@drawable/widget_application"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <intent-filter> 
      <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
     </intent-filter> 
     <meta-data 
      android:name="android.appwidget.provider" 
      android:resource="@xml/widget_scroll_provider_medium" /> 
    </receiver> 

    <receiver android:name=".activity.WidgetLarge" 
     android:label="Swedroid Widget 4x4" 
     android:icon="@drawable/widget_application"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <intent-filter> 
      <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
     </intent-filter> 
     <meta-data 
      android:name="android.appwidget.provider" 
      android:resource="@xml/widget_provider" /> 
    </receiver> 

    <receiver android:name="com.swedroid.widget.activity.WidgetScrollLarge" 
     android:label="Swedroid Widget 4x4 Scroll" 
     android:icon="@drawable/widget_application"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <intent-filter> 
      <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
     </intent-filter> 
     <meta-data 
      android:name="android.appwidget.provider" 
      android:resource="@xml/widget_scroll_provider_large" /> 
    </receiver> 
+0

あなたのAppWidgetProviderのonUpdateメソッドからコードを投稿できますか?ウィジェットをループして、それぞれのウィジェットを更新している可能性があります。 – ekatz

+0

onUpdateメソッドは本当にシンプルですが、私はウィジェットをループして、それぞれに対してIntentServiceを開始しています。このような問題は起こらないはずです。 – user634545

答えて

0

私はあなたのケースではすべての4個のレシーバがアクティブであることを考えると、彼らはすべてのあなたのウィジェットを更新するために、同じ意図を受けます。アプリケーションに更新インテントを作成するコードを追加してください。

1

Mainの場合とMainScrollクラスは唯一のスーパークラス、彼らはそれゆえ、receiver定義はマニフェストでそれらのために必要とされていないAppWidgetProvidersはなくabstractクラス、すべきではない私の事です。

また、以下のintent-filterは他の4つの定義には必要ないと思います。

<intent-filter> 
    <action android:name="android.intent.action.MAIN" /> 
    <category android:name="android.intent.category.LAUNCHER" /> 
</intent-filter> 
関連する問題