13

Google App widget'ı dönüşür.
Android 4.4.4 çalıştıran bir Genymotion Nexus 4 emülatöründe her şey iyi çalışıyor. Android 4.4.4 çalıştıran Nexus 4 Cihazda
Ben ana ekranda widget koymak ve onu Google App widget'ı dönüşür.
Ardından widget'ım sonra tekrar Google App widget'ına ve benzerlerine dönüşüyor. Widget'ı ana ekrandan kaldırana kadar bunu yapar.
Ayrıca ben veri elde edilecek görünmüyor çevrimiçi depolama gibi ve telefonuma parse.com kullanıyorum. Widget sürekli değiştiğinden emin olamıyorum.
Widget'ım 3 dosya içeriyor.Android widget'ı emülatörü iyi çalışır ancak telefonda ben bir Android widget oluşturduk

public class MyApp extends Application 
{ 
    private MyModel model; 

    @Override 
    public void onCreate() { 
     Parse.enableLocalDatastore(this); 
     ParseObject.registerSubclass(GdbdData.class); 
     Parse.initialize(this, "-", "-"); 

     if(model == null) { 
      Intent intent = new Intent(this,GdbdWidgetProvider.class); 
      intent.setAction(WidgetUtils.WIDGET_REFRESH_STORAGE); 
      intent.putExtra("userId",123); 
      sendBroadcast(intent); 
     } 

     super.onCreate(); 
    } 

Bir WidgetProvider: Uygulama sınıfını genişleten
Bir

@Override 
public void onReceive(Context context, Intent intent) { 
    super.onReceive(context, intent); 
    final String action = intent.getAction(); 
    if (action.equals(WidgetUtils.WIDGET_REFRESH_STORAGE)) 
    { 
     MyApp app = ((MyApp)context.getApplicationContext()); 
     int userId = intent.getIntExtra("userId",0); 
     TryGetModelFromRemoteStorage(userId,context); 
    } 

} 


static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) 
{ 
    MyApp app = ((MyApp)context.getApplicationContext()); 
    MyModel model = app.getModel(); 

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

    PendingIntent clickerPendingIntent = buildButtonPendingIntent(context); 

    // I change some textviews and imageviews inside the widget here 

    appWidgetManager.updateAppWidget(appWidgetId, remoteViews); 
} 

public static PendingIntent buildButtonPendingIntent(Context context) { 

    // initiate widget update request 
    Intent intent = new Intent(); 
    intent.setAction(WidgetUtils.WIDGET_UPDATE_ACTION); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0); 
    return pendingIntent; 
} 

Ve Widget'teki bir düğme kolları tek broadcastreceiver:

@Override 
public void onReceive(Context context, Intent intent) { 
    if (intent.getAction().equals(WidgetUtils.WIDGET_UPDATE_ACTION)) { 
     updateWidget(context); 
    } 
} 

private void updateWidget(Context context) { 


    MyApp app = ((MyApp)context.getApplicationContext()); 
    MyModel model = app.getModel(); 

    //I update some fields in the model based on some business rules at this point 

    MyWidgetProvider.SendUpdateMessageToWidgets(context); 


} 

kimse benim ne biliyor mu yanlış mı yapıyorsun?

Düzenleme 1:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.my.app.main" > 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

    <application 
     android:name="MyApp" 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <receiver android:name=".GdbdWidgetProvider" > 
      <intent-filter> 
       <action android:name="android.appwidget.action.APPWIDGET_ENABLED" /> 
       <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 

      </intent-filter> 

      <meta-data 
       android:name="android.appwidget.provider" 
       android:resource="@xml/the_widget_info" /> 
     </receiver> 
     <receiver 
      android:name=".TapMarkDayIntentReceiver" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="com.my.app.intents.UPDATE_WIDGET" /> 
      </intent-filter> 

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

</manifest> 

Edit 2 istendiği gibi tezahür dosya ekleme, katma Widget xml dosyası: Geçen yorumlarınızı yanıtlayan ama işim değildi için

<?xml version="1.0" encoding="utf-8"?> 
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" 
    android:minWidth="140dp" android:minHeight="140dp" 
    android:updatePeriodMillis="1000000" 
    android:previewImage="@drawable/example_appwidget_preview" 
    android:initialLayout="@layout/the_widget" android:widgetCategory="home_screen" 
    android:initialKeyguardLayout="@layout/the_widget"></appwidget-provider> 
+0

Manifest'inizde –

+0

@DavidWasser şimdi – Para

+0

da 'the_widget_info.xml' gönderilmesi için lütfen eklendi sonrası. –

cevap

0

üzgünüm.
Yardımlarınız için herkese teşekkür ederiz. Ne oldu
Ben onDisabled ve orReceive yöntemleri ve görünüşte bu kötü bir şey olduğunu, benim WidgetProvider en OnUpdate içinde return ifadesi vardı onEnabled olmasıydı. Onları kaldırdıktan sonra bu artık oluşmadı.