Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid widget fetching data with service, cannot work with more than one at once
    text
    copied!<p>My widget gets data from the internet every 3 minutes, some are displayed directly on the widget and others are stored in SharedPreferences so when the user taps on the widget that information appears as a dialog. When having more than one widget running, no matter which widget I click the log says the appWidgetId comes from one of them <strong>always</strong></p> <p>My problem seems to be the way I'm declaring the widget's setOnClickPendingIntent(). I'm doing this inside the service, right before fetching the data and since the same service is run by every (widget) AlarmManager, every widget gets the PendingIntent from the last service ran. </p> <pre><code>public class WidgetService extends Service { @Override public void onStart(Intent intent, int startId) { Intent intentUmbrales = new Intent(context, LaunchUmbralesDialog.class); intentUmbrales.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); PendingIntent pendingIntentUmbrales = PendingIntent.getActivity(context,0,intentUmbrales,0); // Get the layout for the App Widget and attach an on-click listener to the button RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); // views.setOnClickPendingIntent(R.id.energia_widget, pendingIntentImei); views.setOnClickPendingIntent(R.id.imageLogo_widget, pendingIntentUmbrales); //..then I fetch data, store the rest in SharedPreferences and update widget remoteViews } } </code></pre> <p>How can I avoid this? How can I make an individual "button" for each widget with getting them overlapped? Also note that I've already tried to declare those PendingIntents in the AppWidgetProvider's onUpdate() method (inside a loop for every appWidgetId from the array given by the method)</p> <p>Thanks in advance!</p> <p>Regards, Rodrigo.</p>
 

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