user387184
user387184

Reputation: 11053

How to start an IntentService from a press on an app widget

I would like to start an IntentService when pressing on my app widget.

I know how to update the widget with pressing on it but I don't have any idea how I would actually start an IntentService.

This is how to initiate the widget update

        Intent intent = new Intent(context, MyWidgetProvider.class);

        intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

        PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
                0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.update, pendingIntent);
        appWidgetManager.updateAppWidget(widgetId, remoteViews);

What would I have to change to start an INtentService instead?

ps I also started an activity based on the press, but this shows on the screen - which I do want to avoid.

Many thanks!

Upvotes: 3

Views: 1673

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006664

Use getService() instead of getBroacast(), and use an Intent that identifies your service.

Upvotes: 5

Related Questions