2
我有這個簡單的小部件,當我點擊它,它應該打開我的活動,它的工作原理,但它重新啓動後不起作用。我必須刪除,然後再將小部件添加到我的主屏幕,因爲當我點擊小部件時,小部件沒有響應,也沒有打開我的活動。那麼問題在哪裏?重新啓動後,爲什麼小部件無法使用?
代碼:
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
for(int i=0; i<N; i++){
int appWidgetId = appWidgetIds[i];
context.startService(new Intent(context, WidgetService.class));
Intent intent = new Intent(context, WidgetDialog.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setOnClickPendingIntent(R.id.layout_widget, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
@Override
public void onEnabled(Context context){
context.startService(new Intent(context, WidgetService.class));
}
@Override
public void onDisabled(Context context){
context.stopService(new Intent(context, WidgetService.class));
}
更新所有部件重新啓動後你有沒有找到解決方案? – zys 2016-03-10 07:37:09
是的,我做到了。無論如何,謝謝你的提問。 – Adam 2016-03-11 22:55:41
你應該發佈你的解決方案,而不是說「謝謝你問」。 – Sean 2016-12-26 23:01:00