开发者

Can a home widget have a Context?

开发者 https://www.devze.com 2022-12-21 21:59 出处:网络
In an activity it\'s (usually) easy to get the Conte开发者_运维问答xt. What if I am working with a home widget class?

In an activity it's (usually) easy to get the Conte开发者_运维问答xt.

What if I am working with a home widget class? These are classes that extends AppWidgetProvider, which don't contain a Context!


An instance of Context is passed to all the methods in AppWidgetProvider for you to use.


For those who can't access developer.android like me, here's where you can get context in app widget:

Android provides context in onReceive method in widget class.

@Override
    public void onReceive(Context context, Intent intent) {
        super.onReceive(context, intent);
}
0

精彩评论

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

关注公众号