android小部件的作用,android – 为什么小部件在重启后不起作用?

我有这个简单的小部件,当我点击它时,它应该打开我的活动,它工作,但它重新启动后不起作用.我必须删除然后再次将小部件添加到我的主屏幕,因为当我点击小部件小部件时没有响应并且不会打开我的活动.那问题出在哪里?

码:

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

final int N = appWidgetIds.length;

for(int i=0; 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));

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值