is it possible to make an Intent whic runs in background? Like a service i assume.
I need to perform an action (call webservice) when the user clicks on a widget.
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. 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)
onClick
action of a widget and place the web-service
invocation code inside the 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
Hope this helps !
I solved it by calling a 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.