I'm working on a SQLiteOpenHelper
from which I'll read databases via static methods (since the databases are shared anyway). Is it possible to get the application context to something like:
public static final Context context = XXX;
It should be possible right? Since I'm obviously only calling from the current app and both resources and databases are shared inside the app.
To be clear: I want to access Resources and the SQLiteDatabases
(if I happen to be wrong about the context approach).
Is it possible to achieve?
Edit: Is it possible to get the context from inside something like this (without passing it as a parameter)
public class foo{
foo(){
XXX.getResources();
}
}
Edit2: Trying @britzl:s fist idea
public class SpendoBase extends Application{
private static Context context;
public SpendoBase(){
System.out.println("SPENDOBASE: " + this);
System.out.println("SPENDOBASE: " + this.getBaseContext());
}
public static Context getContext(){
return this.context;
}
}
How do i get hold of the context? Either in the constructor or form the getContext();
Ps the getBaseContext()
returns null, and getApplicationContext
thows a nullPointerException
.