The developer’s site says that onUpdate method is invoked after time updatePeriodMillis. But when I write in the method onUpdate, for example, Log.e ("tag", "update");, he writes in the log only when you run a widget.
Why is that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
onUpdate()is more like a “resume this widget now” handler. It should (re)initialize/start the widget’s resources and services. The system will absolutely NOT respect very lowandroid:updatePeriodMillisvalues, so usingonUpdate()as mainloop for your widget will not work!What you want to do is:
In
onUpdate(): create a newAlarmManagerwith aPendingIntentwith a custom action. Set theAlarmManagerto repeat as fast as you need.In
onReceive(): pick up the custom action, and callLog.e()or whatever you want.Note: After creating the custom action, don’t forget to add it to your
<Intent-Filter>in your Manifest.xml. Because otherwise,onReceive()will not be able to receive it.Somewhat dated but still partly relevant: http://kmansoft.com/2010/04/10/processing-widget-events-with-pendingintents/