Getting Context in onCreate in SQLiteOpenHelper
Asked Answered
A

2

8

In my android app: How can I get access to Context in the onCreate method of the SQLiteOpenHelper?

Armbruster answered 14/6, 2011 at 20:54 Comment(0)
S
8

You extend SQLiteOpenHelper and in your own constructor, save it to a field. Then, later, in onCreate() you have access to the context.

Sholeen answered 14/6, 2011 at 20:57 Comment(1)
This doesn't seem to work for me. I get a NPE when trying to access the member field during onCreate().Lyrist
C
1

You can extend that class and pass the context to the constructor, which stores it inside a variable. You then can access it from within the onCreate method.

Citizenship answered 14/6, 2011 at 20:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.