且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

设置活动不启动

更新时间:2023-01-24 07:43:20

把code,它确保了 PendingIntent 设置,在的OnUpdate()方法来代替。这可以确保一旦部件放置在主屏幕上的 PendingIntent 设置。

Put the code that makes sure the PendingIntent is set, in the onUpdate() method instead. This makes sure that as soon as the widget is put on the homescreen that the PendingIntent is set.

所以:

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgets) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_activity);
    Intent intent = new Intent(context, Info.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
    remoteViews.setOnClickPendingIntent(R.id.Widget, pendingIntent);

另外:

如果您也想拥有信息活动时,首先添加窗口小部件到主屏幕自动弹出,你应该阅读的这个Userful公司资料片的。

If you would also like to have the info Activity pop up automatically when first adding the widget to the home screen, you should read this userful piece of information.