RemoteViews上的partialUpdateAppWidget无法正常工作

时间:2017-09-19 16:28:15

标签: android android-appwidget android-remoteview android-appwidget-list

RemoteViews AppWidget AdapterViewFlipper我有一个AppWidget,当用户点击RemoteViews中的按钮时,该AppWdiget会被翻转。根据官方文档,这应该通过致电showNext()上的showNext来完成。然后应使用partiallyUpdateAppWidget更新public class WidgetProvider extends AppWidgetProvider { public static final String NEXT = "next"; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int appWidgetId : appWidgetIds) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); Intent nextIntent = new Intent(context, WidgetProvider.class); nextIntent.setAction(NEXT); views.setOnClickPendingIntent(R.id.next_button, PendingIntent.getBroadcast(context, appWidgetId, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT)); views.setRemoteAdapter(R.id.view_flipper, new Intent(context, WidgetRemoteViewService.class)); appWidgetManager.updateAppWidget(appWidgetId, views); } super.onUpdate(context, appWidgetManager, appWidgetIds); } @Override public void onReceive(Context context, Intent intent) { if(intent.getAction().equals(NEXT)) { RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); remoteViews.showNext(R.id.view_flipper); AppWidgetManager.getInstance(context).partiallyUpdateAppWidget( AppWidgetManager.getInstance(context).getAppWidgetIds( new ComponentName(context, WidgetProvider.class)), remoteViews); } super.onReceive(context, intent); } } ,其中partiallyUpdateAppWidget函数作为示例在文档中。我已经尝试过实施这一点,而且我很可能犯了一些我无法理解的愚蠢错误。

updateAppWidget

当用RemoteViews替换import pymysql import json conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='', db='mydb', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = conn.cursor() select_query = "select * from users where id = " ids = ["10", "20", "34", "1"] for x in ids: var = select_query + str(x) # here # print(var) print(list(cursor.execute(var))) 时,下一个按钮正在工作,直到方向改变或手机进入睡眠状态,这会强制重绘最后存储的confirm("message");//for confirm you should have to click ok to do other things alert("message");//it will alert whatever inside . 。这让我相信我所犯的错误与部分更新有关,但我无法弄清楚我做错了什么。

1 个答案:

答案 0 :(得分:2)

您在测试哪个API级别?

可能withpartiallyUpdateAppWidget的问题与此问题issuetracker.google.com/issues/37136552

有关