provide custom application object and use its context (so Application Context).
in your AndroidManifest file, provide a class that extends Application.
<application android:label="@string/app_name"
android:name=".MyApp"
>
MyApp class looks like this:
public class MyApp extends Application {
private static MyApp instance;
public MyApp() {
instance = this;
}
public static MyApp getInstance() {
return instance;
}
....
so now whenever you need context in your app, you can call MyApp.getInstance
. As long as you call it after MyApp's onCreate
is called, you will be safe. Keep in mind that instance
is your application context so it will be alive as long as your app is alive. (e.g. no danger of leaking)
new DaoMaster.OpenHelper(MyApp.getInstance(), "test-db", null)