1

Possible Duplicate:
Static Way to get Context on android?

Not sure if the answer is correct, but this thing is stopping me from progress for days already.

I got two classes:

  • public class CfmDbAdapter which consist:
    • private static class DatabaseHelper extends SQLiteOpenHelper
    • series of methods to service the database
  • public class DataToArray extends Application

I extended Application just to have access to Context but I have to access methods from CfmDbadapter. In all my Activity classes I do it by:

private CfmDbAdapter db;    
db = new CfmDbAdapter(this);
db.open(); //one of the methods I need to access

I can't do that in my DataToArray class since it's parent is not a Context class (I gues). I can't acess methods staticly aswell, it would fck up whole code.

0

2 Answers 2

0

Check out these links
Using Application context everywhere?
Static way to get 'Context' on Android?

Sign up to request clarification or add additional context in comments.

Comments

0

You can make the db: a) final b) belonging to the class Or you can declare some other variable, (static or final) and put a reference to db in it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.