The deleteDatabase method needs a context in order to work. So in my class there is a context declared called ourContext. This class does not extend any other class like
Activity so I guess you could call it a helper class.
The only place in the class that uses context is the one method shown below that is called deleteData. and this calls the deleteDatabase method that needs a context to work.
ourContext.deleteDatabase(DATABASE_NAME);
Is it possible to not declare a context for the class in this situation? Can I use this for the context?
public class PlayGame {
private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;
public PlayGame(Context c){
ourContext = c;
}
public void deleteData(){
ourContext.deleteDatabase(DATABASE_NAME);
}
No, Context is a class, you have to be derived from it to use this as a context. I suggest making deleteData take a Context as a parameter. I assume its going to be called from an Activity, Service, or something like a view that has a reference to a Context.