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.

Community
  • 1
  • 1
Jacek KwiecieĊ„
  • 12,397
  • 20
  • 85
  • 157

2 Answers2

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.

Gangnus
  • 24,044
  • 16
  • 90
  • 149
0

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

Community
  • 1
  • 1
Mirza Dobric
  • 1,467
  • 1
  • 14
  • 36