1

all are known difference between SQLite, Content provider and Shared Preference.

But i want to know when i need to use SQLite or Content provider or Shared Preference by situation.

Please explain with some examples.

Krishna
  • 343
  • 1
  • 2
  • 9

2 Answers2

4

Its all depends on your data usage,

  • Content Provider is used to Share data between applications
  • SharedPreference is used to Store small size of information like "read me" option in Login page, where you store userId & password in SharedPreference to skip login screen in future
  • Sqlite is used when you have large size of structure data. Sqlite also allows you to use query for searching particular data.
Lucifer
  • 29,392
  • 25
  • 90
  • 143
  • Well you really shouldn't really store sensitive information like a password in SharedPreferenecs given that any device with root access will be open to just open up that file and read it straight up... – rperryng Apr 09 '14 at 13:14
  • 2
    @Rperryng, A smart developer will store these information in MD5 kind of encrypted format :) – Lucifer Apr 09 '14 at 13:15
  • Can we share data between applications using SQLite? – Krishna Apr 09 '14 at 14:40
  • you can create sqlite on SD card and then use same path for two different applications. – Lucifer Apr 09 '14 at 15:05
0

shared preferences are the location where you can store the secret information for your app, like setting cookies in the browser, this can be used for login credentials and other.

where as content provider stores and retrieves the data and make it available to other applications also. like suppose you want to access the contacts available in the android phone, they can be accessed by content providers

Reference Links: Difference between Shared Preferences and Content Providers in android

Community
  • 1
  • 1
ngrashia
  • 9,869
  • 5
  • 43
  • 58