Android context from a non activity class

android, android-activity, android-context, sqlite

Solution

pass application Context like this

SetSql PlayerObject = new SetSql(this.getApplicationContext());

now it should work fine.

Problem

In my SQLite setup class I have a DbHelper that requires a Context as a part of it. To Setup the context, I just use a constructor in my SQLite class that requires a context as a part of it parameters. But I just encountered a problem. When trying to call my SQLite class from a class which is not an Activity, I can't use as the `context classname.this`, and it is bugging me. I also tried to do this to declare a context: ``` protected Context context; ``` And then later on call it like this: ``` SetSql PlayerObject = new SetSql(This.context); ``` But this didn't work either. Any suggestion please?

Original source

Related problems