Widget Activity
I have a problem that I have a widget that needs to make a http request using an activity and get some updates fr开发者_StackOverflowom internet.My problem is widget is doing the updates only using the activity.I put a button to start the activity but that's not the solution actually.I need that activity to start himself and terminate periodically when the widget is working.How can I achieve that?
I think your idea of a widget is not right assuming you are talking about app widgets; a widget is basically just a view and nothing more, so it cannot request data from anything. If you want to update the data presented by the widget you can use a service to do the httprequest, and then serve it to the widget either by broadcasting your own action intent and handling that in the onRecieve of your AppWidgetProvider or update the widget directly.
Ofcourse if your activity is active it can update the widget as well, and you can start the activity by setting a repeating alarm in the AlarmManager, but if you don't have to display anything whilst doing the HttpRequest i would recommend against using an activity.
See if it helps: http://developer.android.com/resources/articles/timed-ui-updates.html
精彩评论