-6

I have started learning Android development and I have a very newbie question. I understand that Android can store data in SQLite for example, but what other approaches are there to the storage of data within your application?

Do Android apps ever have data 'embedded' within the application, in which case what sort of data structure or concept would this use?

I am thinking of a scenario where the data is static but is perhaps not a large enough dataset to warrant a database..e.g. an app with general knowledge questions and answers

Any guidance much appreciated Rowan

Rowan
  • 463
  • 3
  • 8
  • 20
  • 1
    *not a large enough*? `SharedPreferences` can be useful in this case. It save data in xml form (Key-value pair). Going with database is a good approach if complex queries needed(Try android-room). For static data (Pre bundled with application) you can also use `assets`. – ADM Mar 08 '18 at 05:25

3 Answers3

0

Yes You are correct You can use SqLite Database for storage other ways to store data is SharedPreferences But in your case you wanrted to save questions and answers which is static one so you can create a text file and put that in your assets folder and you can read that file as any other text file in java

Refer this link how to read file from assets folder

1.Sqlite Database

2.Shared preferences

3.Internal memory

4.external memory i.e sd card

Community
  • 1
  • 1
Bhagyashri
  • 182
  • 1
  • 15
0

i would suggest you to go with Database. as it will let you store as much data as your app needed, There are some other option also present like

  1. Sharedpreference i.e. cookies in general term. It let u store only few KB data and not good to store much data. When u retrieve data from cookies. All data will be store into ram and use app memory. that is use less when u do not need all data to retrieve and store into ram and then remove
  2. Store into file and ship that file with your app. Yeah. this could be better idea again. you need to read it byte by byte. and hence reading to mid or last line will store all data into ram and hence will take memory.
  3. Use Web Service to download data. It will let you store Large data and you have to download using Web APi. Hence it could be better idea. But this requires active Internet connection to play game to run app.
  4. There must be some other option also present. You can search. surely you will find them :)

Overall Database it good solution for all app. As it will let you do search store delete and let you do other operation in less amount of memory. In Mobile Development Memory is very Important thing we have to take care of.

Let me know if you have other unclear thought.

item

Ashu Kumar
  • 832
  • 19
  • 38
0

You could also store info in a server.

Pros :

  • You can change the content without needing user-side update of the app.

Cons :

  • Your app (mostly the UI) would need to manage connection problems.
  • You may need to implement async tasks for querying data from server.
Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
D. LaRocque
  • 397
  • 5
  • 16