Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Widget Service Class to bind Collection not being Called By Provider
    primarykey
    data
    text
    <p>Please bear with me because I am new to Android development.</p> <p>I am building a widget that opens up a Configuration Activity upon placement on the home screen. When I am finished configuration and have pressed "done", the widget provider (onUpdate) is supposed to call the widget service class to bind a list of drawables to a gridview. However, the service class is not being called and the gridview is coming up empty. Any help on this is appreciated, code is included below:</p> <p>*Note: i have a main.xml that has the gridview in it and another xml that has the template (imageView and textView) the gridview cell.</p> <p><strong>Manifest:</strong></p> <pre><code>&lt;service android:name=".WidgetService" android:permission="android.permission.BIND_REMOTEVIEWS" android:exported="false" /&gt; &lt;receiver android:name=".WidgetProvider" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt; &lt;/intent-filter&gt; &lt;meta-data android:name="android.appwidget.provider" android:resource="@xml/button_widget_provider" /&gt; &lt;/receiver&gt; </code></pre> <p><strong>Provider:</strong></p> <pre><code>public class WidgetProvider extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int i=0; i &lt; appWidgetIds.length; i++){ Intent intent = new Intent(context, WidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main); remoteViews.setRemoteAdapter(appWidgetIds[i], R.id.gridview, intent); appWidgetManager.updateAppWidget(appWidgetIds[i], remoteViews); } super.onUpdate(context, appWidgetManager, appWidgetIds); } ......(omitted code)} </code></pre> <p><strong>Service:</strong></p> <pre><code>public class WidgetService extends RemoteViewsService { @Override public RemoteViewsFactory onGetViewFactory(Intent intent){ return new VZRemoteViewsFactory(this.getApplicationContext(), intent); } } class VZRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory{ public VZRemoteViewsFactory(Context context, Intent intent){ thisContext = context; appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } public void onCreate(){ // code to add drawables to list here } public RemoteViews getViewAt(int position){ RemoteViews remoteView = new RemoteViews(thisContext.getPackageName(), R.layout.vzwidget_item); // setting the image view resource this way for now just for testing remoteView.setImageViewResource(R.id.launcher_icon, R.drawable.vzicon); remoteView.setTextViewText(R.id.textview, "test"); return remoteView; } .....(omitted code)} </code></pre> <p>Thank You!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload