2

Android has openOrCreateDatabases in two different classes: SQLiteDatabase and Context. May I ask what are the differences between them?

Meanwhile, I am using a singleton class for maintaining my database. If I want to use that one database across many activities, which version of openOrCreateDatabase will be more suitable?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
JSong
  • 348
  • 3
  • 19
  • https://stackoverflow.com/questions/7058267/why-use-sqliteopenhelper-over-sqlitedatabase I think This is Similiar question – Tomin B Azhakathu Jan 09 '18 at 07:49
  • 1
    @TominB no? This question is about the differences between a method with the same name (that in theory should do the same thing) in two completely different classes, not SQLiteHelper... – Zoe Jan 09 '18 at 07:53
  • Possible duplicate of [Why use SQLiteOpenHelper over SQLiteDatabase?](https://stackoverflow.com/questions/7058267/why-use-sqliteopenhelper-over-sqlitedatabase) – Nawrez Jan 09 '18 at 08:10
  • 1
    @HadjKhelilNawrez No. SQLiteOpenHelper is not even mentioned in this question. As Zoe commented above, this question is about two methods with a same name under different classes. – JSong Jan 11 '18 at 03:07

1 Answers1

4

Regarding your question about the difference between Context.openOrCreateDatabase and SQLiteDatabase.openOrCreateDatabase the answer lies withing this sentence:

Open a new private SQLiteDatabase associated with this Context's application package.

Context.openOrCreateDatabase creates the database file which is located in the application's private data folder whereas SQLiteDatabase.openOrCreateDatabase can create the database anywhere your app has write access to.

As for your second question I think it matters not which one you choose to use.

2hamed
  • 8,719
  • 13
  • 69
  • 112