1

I am looking for the smartest (and most effective) way to implement the following project:

I want to develop an app that accesses to about 100 different sport exercises. The exercises are available in an xml-file. The access to the exercises can be in different ways on different activities:

  • show all
  • show only exercises of a special category
  • mark as favorite and show favorites
  • show details of an exercise
  • sort
  • etc.

Loading the xml-file and creating the exercise-objects is already working and its not problem. But I think about the most effective way to implement things like that. Thinking about RAM and performance...

  • Parsing the xml-file once the app is started, creating the 100 objects and dealing with them during the app is running (of course ensure to reload the data if the objects where cleaned up by the garbage collector in the meantime). Is this possible and recommended? How can such a central point, where I can pick up the objects in all activities, look like? Can I find an example anywhere?
  • Parsing the xml-file every time an activity (that is using the exercises in any way) is created?
  • completely different way?

Maybe someone can give me a keyword.

vitr
  • 6,766
  • 8
  • 30
  • 50
Raspberry
  • 139
  • 1
  • 11
  • I would advice to think about storing XML to DB and working with DB in your APP. And after this won't be problem with reparsening your XML file and won't be a problem about all the actions you want. – xAqweRx Aug 19 '16 at 10:51
  • I get the file from an external resource and it is going to be updatet from time to time. So I thought using this file in my app is an easy way... – Raspberry Aug 19 '16 at 12:08
  • Easier is to update this info from time to time. – xAqweRx Aug 19 '16 at 12:25
  • you mean,to update the database from time to time? So you recommend not using an xml-file at all? I'm new to sqllite in android and already tried to pick up information about it. Using and delivering the existing file seemed to be so easy (and its only 100 data sets)... - using a database with provided data is no problem? - updating it from time to time with new data sets is no problem? Do you recommend a good tutorial about sqllite with delivered data? I found a lot tutorials about sqllite, but all of them only used sqllite for user input... Thank you a lot, Raspberry – Raspberry Aug 20 '16 at 09:52
  • For this you can look through this http://stackoverflow.com/a/19196178/2685996 – xAqweRx Aug 22 '16 at 06:48
  • But I can say, that you just need to combine 2 things : downloading XML from server + inserting data to SQLite DB. And after this, you just should check timestamp of your records, or just call server endpoint to check whether XML was changed or not. And if YES -> update your DB. – xAqweRx Aug 22 '16 at 06:52
  • Thanks xAqweRx for your answer. I dont't want to download xml from a server. Its part of the app (it contains about 100 exercises) and its just updatet from time to time (with some additional exercises). So it can be delivered with the app... – Raspberry Aug 25 '16 at 06:10
  • You convinced me and I'm trying to switch to sqlite. I have to ask again: What is the best way to fill the database? Creating insert statements (out of the xml?) after creating the tabel and execute in "onCreate" (respectively in "onUpgrade")? Or better using asset folder? – Raspberry Aug 25 '16 at 06:10

2 Answers2

0

It is just my suggestion If possible can you please make change that XML into JSON format, so in that case you can be able to use the GSON Converter and libraries to get rid of the performance issues.

Rajendhiran Easu
  • 273
  • 4
  • 14
0

What I understand from your question is you want to parse XML as app starts every time and generate 100s of Object that time, which you want to use in all other activity.

You can extend Application class for accessing same object for more than one activity. Take look at this question

Application is base class of your app and it is the first one to call. So, you can call your service here and also setter/getter of your objects here. By which you can access it in all activities.

Learn more about Application

Also, you can use SharedPreference or SQLite to store your data in database.

Community
  • 1
  • 1
Shaishav Jogani
  • 2,111
  • 3
  • 23
  • 33
  • Thanks for your answer! Using Application is an interesting thing, I didn't knwo about that. Yes, I wanted to parse XML as app starts, but I'm not sure anymore. For me (an android beginner) it sounded good not parsing the file again and again. I'm interested in the best way implementing requirements like that. – Raspberry Aug 20 '16 at 09:59
  • Look at the question I posted in answer. you'll get rough idea about how to use application class – Shaishav Jogani Aug 20 '16 at 10:16
  • I read a lot about XML, JSON and Sqlite and decided to use a database. Your information about Application is very useful for me elsewhere. Thanks for that. – Raspberry Aug 25 '16 at 06:13
  • First, XML and JSON are not database. They are data-interchange format between client & server. Second, SQLite and SharedPreferences are local databases of Android. Third, `Application` class is not way to store your data but it's a way to fetch info. from server and define methods to store you data in database. You can use these methods throughout application. Lastly, if you find my answer helpful then you can up-vote/Accept it. – Shaishav Jogani Aug 25 '16 at 06:37
  • Sorry, maybe I used a not-quite-correct term. Of course XML and JSON are not a database. I just wanted to say, that I decided not to use XML, but using SQLite. Thanks, I'm going to use Applicatin on another position in my app to load data and use it in every activitiy. – Raspberry Aug 26 '16 at 13:29
  • Bingo.. If you found my answer useful than,I would appreciate if you accept/upvote it. – Shaishav Jogani Aug 27 '16 at 11:04