0

I am in AppWidgetProvider class. I want to call a static block before any callback method, but I need the context inside my static block. How can I get that?

Below is my code:

public class widgetClass extends AppWidgetProvider {

    static
{
// here i want the context

}

    @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds){
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Shakeeb Ayaz
  • 6,200
  • 6
  • 45
  • 64
  • What are you trying to do in the static block? Generally it's not possible what you're attempting, although you might be able to use the `Application` context by setting it up with `Singleton`-like access. Perhaps it's an idea to execute the logic in the static block the first time `onUpdate()` gets hit? – MH. May 15 '13 at 08:13

1 Answers1

1

Override onEnabled instead of using a static block.

alex
  • 6,359
  • 1
  • 23
  • 21