Widget does not respond

喜欢而已 提交于 2019-12-03 21:35:53
Software_Designer

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

I had to include this code in my service class. What it does basically it sends the update to every single widget. Its been over a year now, the button on my widget always works and the widget updates without any problem. I'm posting this hoping it will help someone with the same problem. It took me over a year to solve it.

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);
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!