0

is there any pro and cons of using both in a single program can we use both shared preference and sqlite in android ? Is this even possible to use ?

Rakshit Nawani
  • 2,604
  • 14
  • 27

4 Answers4

0

is there any pro and cons of using both in a single program ?

Yes, and they depend on your usage, Normally Shared preferences are used for storing information which is smaller in size (typically in bytes), where you don't want to do extra work of involving SQLite in picture. SQLite is preferred for storing bulkier information.

can we use both shared preference and sqlite in android ?

Yes,

Is this even possible to use ?

Yes

Amit
  • 13,134
  • 17
  • 77
  • 148
0

Its possible, you should store settings , flags and one line String in SharedPrefrence and any other relational data with multiple filed should go in sqlite

Saqueib
  • 3,484
  • 3
  • 33
  • 56
0

Yes you can use both depending upon your needs,sqlite basically for storing heavy info like big texts picture,audio files and shred pref for simple key value pairs,infact when your data is huge you should consume content through rest services in your android app.

Srishti Roy
  • 576
  • 5
  • 17
0

Yes, you can use both SharedPreference and SQLite at the same time depending on your requirements. You can read about different storage options used in android from here

This question is asked before. Pros and Cons of SQLite and Shared Preferences but I want to add some links for you to understand more specifically.

SharedPreferences: SharedPreference is used to store small data. You can use more than one SharedPreference in your application depending on your requirements. You can learn about it from Android Developer site.

SQLite: Sqlite is a database use by android to store some how large amount of data as compared to sharedpreferences. There are many tutorials about SQLite one of the popular tutorial you can follow this link

For Example: There is a common scenario mostly used in android applications is User Login process. You can maintain session of user login using SharedPreference and you can store User Bio data in SQLite like Username, email, contactNo, Organization etc and perform updation, deletion using SQLite database queries. There is an complete implementation of User Login Session Management you can follow this link.

Hope it will help you.

Community
  • 1
  • 1
Zubair Ahmed
  • 2,857
  • 2
  • 27
  • 47