Android AppWidget无法更新控件

自定义的类AppWidgetProvider中经常性无法更新桌面组件的RemoteViews,有时候添加多几个才出现一次正常显示和响应点击事件的,如下:

@Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        super.onUpdate(context, appWidgetManager, appWidgetIds);
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
        views.setImageViewResource(R.id.img, R.drawable.pic);
        views.setOnClickPendingIntent(R.id.layout, startActivity(context));
        appWidgetManager.updateAppWidget(appWidgetIds, views);
    }

网上的文章基本都查过了,所有方法我都测试过了,我在activity中发广播也能够接收,但就是没办法更新RemoteViews。

Intent intent = new Intent(this, WidgetProvider.class);
        intent.setAction(action);
        sendBroadcast(intent);

https://blog.csdn.net/chengjiamei/article/details/50222955