【发布时间】:2012-10-31 18:50:14
【问题描述】:
按照here 的示例,我轻松地创建了我的小部件。
然后我在我的小部件中添加了一个按钮,这个按钮应该启动一个服务,所以我将以下代码添加到我的 WidgetProvider 中
@Override
public void onEnabled(Context context) {
Log.e("ERROR", "REMOVE ME"); // TODO remove. This is for eclipse logcat recognition
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
Intent intent = new Intent(context, RepairService.class);
PendingIntent pi = PendingIntent.getService(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.widget_boost, pi);
}
代码肯定会被调用,但服务没有启动。我确定我可能错过了服务 PendingIntent 的实现,但我看不到什么。还有人知道吗?
【问题讨论】:
标签: android android-widget android-service android-pendingintent