Android Using Application Context Inside Widget For Pending Intent
A WidgetProvider button will use a PendingIntent
to communicate.
onUpdate(Context ...)
method开发者_StackOverflow社区 of the WidetProvider the following line appears:
PendingIntent buttonPendingIntent = PendingIntent.getBroadcast(context, 0, buttonIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Which context is being passed in by the widget manager android?
Is it ok to use context.getApplicationContext()
for the PendingIntent
? As I have found that the widget freezes are a certain about of time and different application conditions, even though onUpdate gets called. Using context.getApplicationContext()
seems to help.
Your WidgetProvider.onUpdate()
is called as a result of AppWidgetManager.ACTION_APPWIDGET_UPDATE broadcast. See source, line 52.
Javadoc of 'BroadcastRerceiver.onReceive()` says:
...you should never perform long-running operations in it...
So, check that you are not doing any long running tasks inside onUpdate()
as this might be the cause of freezes you are experiencing.
精彩评论