Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Context in onCreate in SQLiteOpenHelper

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

like image 792
yydl Avatar asked Jun 14 '11 20:06

yydl


2 Answers

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

like image 151
Steve Prentice Avatar answered Oct 17 '22 18:10

Steve Prentice


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.

like image 1
Will Kru Avatar answered Oct 17 '22 16:10

Will Kru