首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Android小部件上处理多个按钮点击

在Android小部件上处理多个按钮点击
EN

Stack Overflow用户
提问于 2010-03-19 01:09:42
回答 1查看 22.2K关注 0票数 18

我按照描述的那样saw this topic并实现了IntentService,但是如果我想要多个按钮怎么办?如何区分按钮?我正在尝试setFlags,但无法在onHandleIntent()方法中读取它:

public static class UpdateService extends IntentService {
...

    @Override
    public void onHandleIntent(Intent intent) {
        ComponentName me = new ComponentName(this, ExampleProvider.class);
        AppWidgetManager manager = AppWidgetManager.getInstance(this);
        manager.updateAppWidget(me, buildUpdate(this));
    }

    private RemoteViews buildUpdate(Context context) {
        RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.main_layout);

        Intent i = new Intent(this, ExampleProvider.class);
        PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
        updateViews.setOnClickPendingIntent(R.id.button_refresh, pi);

        i = new Intent(this, ExampleProvider.class); 
        pi = PendingIntent.getBroadcast(context, 0, i, 0);
        updateViews.setOnClickPendingIntent(R.id.button_about, pi);

        return updateViews;
    }
}

在这一小段代码中,我有两个与setOnClickPendingIntent链接的PendingIntent,我能区分不同操作和处理的意图吗?感谢你的帮助

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2471875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档