Can a home widget have a Context?

坚强是说给别人听的谎言 提交于 2019-12-12 10:37:39

问题


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!


回答1:


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




回答2:


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);
}


来源:https://stackoverflow.com/questions/2366442/can-a-home-widget-have-a-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!