Can a home widget have a Context?

2019-06-16 21:35发布

In an activity it's (usually) easy to get the Context.

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

2条回答
beautiful°
2楼-- · 2019-06-16 22:07

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

查看更多
做自己的国王
3楼-- · 2019-06-16 22:17

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);
}
查看更多
登录 后发表回答