Should one use an Activity or a Service when using a button in a Widget?

I'm been trying to figure this out for a while now, and have just become more and more confused.

I have made a Android Widget which displays two articles (title + image). In addition to this, I have buttons for flipping backward and forward through the articles. What I don't understand is how I can change the Widgets RemoteViews when the buttons are pressed. Which should be one of the most basic operations in a widget, however, I can't seem to figure it out.

So...

  • Can I do this with just a OnClickListener in the AppWidgetProvider?

  • Or do I have to create an Activity without a window (visibility = false)?

Please excuse my stupidity. This is probably very basic.

Answers


I don't think this is basic at all - it's something I thought about for a while in relation to the Headset Blocker app I wrote, which is just a widget that you toggle on/off.

I ended up looking through Google's source code for what they did. The answer is to use the AppWidget's receiver nature to receive updates via setOnClickPendingIntent(). Then in onReceive(), you react differently to your own clicks than someone trying to create a widget. You can see a sample of what I did in the Headset Blocker source.

Ultimately, an Activity or a Service is too heavy weight for what you want. Using the same BroadcastReceiver as the app widget itself is much better.


Need Your Help

How to pass a string containing double quotes from a jsp to a servlet through URL using get method

jsp servlets el

I want to set a jsp parameter to an attribute value which may contain special symbols, then use a form GET submit to pass the parameter to a servlet controller. For example, the parameter is:

Open source mp4 player

open-source mp4

Can you suggest an open source project dealing with playing "just" mp4? I don't want to have many available codec embedded in, just mp4 is adequate.