[英]Android widget Intent without layout
is it possible to make an Intent whic runs in background? 是否可以在后台运行Intent? Like a service i assume. 我想像一项服务。
I need to perform an action (call webservice) when the user clicks on a widget. 当用户单击窗口小部件时,我需要执行一个操作(调用Web服务)。
My code below 我的代码如下
Intent intent = new Intent();
intent.putExtra("webServiceId", mWSId);
PendingIntent pending = PendingIntent.getActivity(context, 0,intent, 0);
views.setOnClickPendingIntent(R.id.btnWidgetToggle, pending);
appWidgetManager.updateAppWidget(mAppWidgetId, views);
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
Should I make my intent to perform an action to a service or something like that? 我是否应该对某项服务或类似内容采取行动? Thanks! 谢谢!
UPDATE: Im trying to do it by calling an IntentService now, but it doesnt calls it. 更新:我试图通过立即调用IntentService来做到这一点,但它没有调用它。 My code below: 我的代码如下:
Intent intent = new Intent(context, widgetService.class);
intent.putExtra("webServiceId",mWSId);
PendingIntent pending = PendingIntent.getService(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.btnWidgetToggle, pending);
any idea? 任何想法?
widget(view)
我是对的,您想在单击小部件时调用小widget(view)
onClick
action of a widget and place the web-service
invocation code inside the onCllickListener
这可以通过调用小部件的onClick
动作并将web-service
调用代码放在onCllickListener
内的简单方式来实现 Sample 样品
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//Place your webservice invocation code here
}}
If you want to use service in some way have a look at android documentation on how to use it 如果您想以某种方式使用服务,请查看有关如何使用服务的android文档
Hope this helps ! 希望这可以帮助 !
I solved it by calling a IntentService. 我通过调用IntentService解决了它。
Here is my code: 这是我的代码:
Intent intent = new Intent(context, widgetService.class);
intent.putExtra("webServiceId",mWSId);
PendingIntent pending = PendingIntent.getService(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.btnWidgetToggle, pending);
Thanks @Karakuri 谢谢@Karakuri
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.