문제

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!

도움이 되었습니까?

해결책

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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top