2017-06-01 3 views
3

私のアプリケーションウィジェットonUpdate関数に移動しない テスト用に3000ミリを追加しますが、最初に追加する場合を除いて、 はonUpdate関数には決して行きません。appwidget onUpdateに移動しない

何が間違っていますか?

私のマニフェスト・ファイル:

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme.NoActionBar"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

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

     <meta-data 
      android:name="android.appwidget.provider" 
      android:resource="@xml/clock_widget_class_info" /> 
    </receiver> 
</application> 

私clockWidget:

/** 
* Implementation of App Widget functionality. 
*/ 
public class ClockWidgetClass extends AppWidgetProvider { 

    static void updateAppWidget(final Context context, final AppWidgetManager appWidgetManager, 
           final int appWidgetId) { 

     //getting shered prefrences 
     SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); 
     String name = preferences.getString("randomString", ""); 
     if(!name.equalsIgnoreCase("")) 
     { 
      name = name; /* Edit the value here*/ 
     } 

     // Construct the RemoteViews object 
     RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.clock_widget_class); 

     //set chosen design visible 
     //set all visibility to 0 
     views.setViewVisibility(R.id.AnalogClock0, View.INVISIBLE); 
     views.setViewVisibility(R.id.AnalogClock1, View.INVISIBLE); 
     views.setViewVisibility(R.id.AnalogClock2, View.INVISIBLE); 
     views.setViewVisibility(R.id.AnalogClock3, View.INVISIBLE); 

     //turning on the correct clock 
     if (name.equals("1")) { 
      views.setViewVisibility(R.id.AnalogClock0, View.VISIBLE); 
     } else if (name.equals("2")) { 
      views.setViewVisibility(R.id.AnalogClock1, View.VISIBLE); 
     } else if (name.equals("3")) { 
      views.setViewVisibility(R.id.AnalogClock2, View.VISIBLE); 
     } else { 
      views.setViewVisibility(R.id.AnalogClock3, View.VISIBLE); 
     } 

//  views.setTextViewText(R.id.appwidget_text, name); 

     //updateting the widget 
     appWidgetManager.updateAppWidget(appWidgetId, views); 

    } 


    @Override 
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 
     // There may be multiple widgets active, so update all of them 
     for (int appWidgetId : appWidgetIds) { 
      updateAppWidget(context, appWidgetManager, appWidgetId); 
     } 
    } 

    @Override 
    public void onEnabled(Context context) { 
     // Enter relevant functionality for when the first widget is created 
    } 

    @Override 
    public void onDisabled(Context context) { 
     // Enter relevant functionality for when the last widget is disabled 
    } 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     // Chain up to the super class so the onEnabled, etc callbacks get dispatched 
     super.onReceive(context, intent); 
     // Handle a different Intent 
     Log.d("reciving", "onReceive()" + intent.getAction()); 

    } 


} 

私のウィジェットのxmlファイル:

<?xml version="1.0" encoding="utf-8"?> 
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" 
    android:initialKeyguardLayout="@layout/clock_widget_class" 
    android:initialLayout="@layout/clock_widget_class" 
    android:minHeight="110dp" 
    android:minWidth="250dp" 
    android:previewImage="@drawable/example_appwidget_preview" 
    android:resizeMode="horizontal|vertical" 
    android:updatePeriodMillis="3000" 
    android:widgetCategory="home_screen"></appwidget-provider> 

答えて

2

正確でないかもしれないでください。あなたがそれが起こることを期待している時に起こることはありません。

documentation for updatePeriodMillisを使用すると、重要な注意点を見つけることができます更新は30分ごとよりも多く配信されませんupdatePeriodMillisと要請しました。

したがって、onUpdate()への別の呼び出しが行われるまでに30分待たなければならない場合があります。

関連する問題