开发者

Android Using Application Context Inside Widget For Pending Intent

开发者 https://www.devze.com 2023-02-12 14:40 出处:网络
A WidgetProvider button will use a PendingIntent to communicate. Inside the onUpdate(Context ...) method开发者_StackOverflow社区 of the WidetProvider the following line appears:

A WidgetProvider button will use a PendingIntent to communicate.

Inside the 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消