1

Question is about context, it return null on first time running after installing app. Do I need permissions? Earlier versions work. Android developer preview v3 (nexus5)

public class App extends Application {

    private static App application;

    @Override
    public void onCreate() {
        super.onCreate();
        Log.e("APP::", "CREATE");
        application = this;
        Log.e("APPLICATION ::", "" + application);
    }

    public static Context getContext() {
        return application != null ? application.getBaseContext() : null;
    }
}
Gaëtan Maisse
  • 12,208
  • 9
  • 44
  • 47

1 Answers1

1

You're calling getContext() before onCreate() is called. Don't do that. If possible, don't use a static reference to App at all.

nhaarman
  • 98,571
  • 55
  • 246
  • 278