1

I have Widget that uses a service to update. It has a button on it to open the activity. It works perfectly. However, sometimes I click on the widget to open the activity and it won't work or update.

What kills an app widget? And if the widget is dead, why is it still showing on the screen? Is there a way to relive that specific widget without creating another?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mark Ismail
  • 700
  • 4
  • 9
  • 22
  • If a widget is not responding anymore. Is it dead? Is there a way to relive it. – Mark Ismail Jun 15 '12 at 18:43
  • The service is stilling working and sending the updates to the widget. But the widget won't update. Unless i delete it, and enable another widget. – Mark Ismail Jun 15 '12 at 18:45

2 Answers2

2

Android will stop your widget when it faces a low memory situation. Then it will restart your home widget after cleaning the RAM automatically. But this time, your home widget will get a different pid from the last one, so it cannot respond the broadcast.

Updating app widget using AlarmManager

Community
  • 1
  • 1
Software_Designer
  • 8,490
  • 3
  • 24
  • 28
0

I had to include this code in my service class. Basically, it sends the update to every single widget. It’s been over a year now; the button on my widget always works and the widget updates without any problem.

int[] arrayOfInt = AppWidgetManager.getInstance(getBaseContext())
                     .getAppWidgetIds(new ComponentName(this, mywidget.class));

AppWidgetManager localAppWidgetManager = AppWidgetManager.getInstance(this);

new WebView().onUpdate(getBaseContext(), localAppWidgetManager, arrayOfInt);

int i = arrayOfInt.length;
for (int j = 0;; j++) {
    if (j >= i)
        return;
    int k = arrayOfInt[j];
    RemoteViews localRemoteViews = new RemoteViews(getBaseContext()
                                       .getPackageName(), R.layout.xx);
    localRemoteViews.setTextViewText(R.id.tv, tv_text);

    localRemoteViews.setOnClickPendingIntent(
        R.id.Button01,
        PendingIntent.getActivity(getBaseContext(), 0, new Intent(
            getBaseContext(), LicenseCheck.class), 1));
    localAppWidgetManager.updateAppWidget(k, localRemoteViews);
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mark Ismail
  • 700
  • 4
  • 9
  • 22