Search code examples
androidmobileapk

How to best handle data models in an an Android App?


I have a college project where the idea is to allow gym-goers to record their progress/evolution in several machines/exercises (e.g. first week I ran 6km in the treadmill in 15 minutos; second week I ran 6.5km, and so forth). I want the user to be able to create an activity plan by selecting several machines/exercises from a list, and each machine/exercise has properties (such as repetitions, muscle groups trained, time, weight, distance, etc).

So, my question is: what is the best way to store the different types of machines/exercises on the apk? Is it to create models for each generic type and load them from a local JSON? Define each exercise outside the app and connect it to a database and have the app fetch the list to the user?

In a prior project I created a Truth or Dare game where the questions (truths or dares) where loaded from a local JSON and turned using a factory to actual questions (using a Question model) to display in-game, but I never found out if that's the best/correct approach.

P.S.: there exists both the possibility that the App is solely local OR that it will be connected to a server + db. Unfortunately, due to the nature of the project I cannot give a concrete answer to this question, but would instead appreciate an answer to both cases...

Thanks in advance!


Solution

  • Using apk's local storage for data storage/retrieval

    In such case you can either use JSON for storage/retrieval or android's SQLiteDatabase . If you use SQLiteDatabase for storage your app will contain db file which is a small database embedded in apk

    If your data contains multiple entities related to each other then you have to go for SQLiteDatabase as using a plane JSON in such case would not be simple

    Using remote storage for data storage/retrieval in apk

    In this case you can setup database server in remote machine for your app.

    Or

    You can use Firebase

    It depends what type of app you are making, if user doesn't have to update its exercise progress to remote machine then local SQLiteDatabase would be sufficient in your case