Design choice for Android app - android

I am new to Android (but proficient in programming) and I have been reading the Google documentation.
I am trying to build a small app, just to get familiar with Android (not a very fancy app, just for learning app dev).
The app would have an initial activity containing a list of items, and the user can view them (through another activity), edit them (again another activity) or create new ones (again another activity). My concern is how to store this list of items in the phone.
I do not intend (at the moment) for the app to be synced with any external service, so I am happy to store all the data in a file. Typically I would be looking at 200 items of small size, so a text file (maybe XML or JSON) would be enough I think (SQL would probably be overkill here).
My question is: if I have an XML file with all the items, do I need to parse it and load it in memory for every activity?
For example:
the user enters the app to see the list of items -> must load the XML
the user wants to add a new item-> I need to load the XML again to be able to add an XML child
Is this the most natural way of doing this in Android? having to load the same resource over and over in each activity?
Thanks

If you want to reuse files you may use adapter. You can either create custom adapter or use default one. Besides that you may know programming concepts such as Design Patterns. My point is to reuse in android can be done programmatically.
In your for storing data would be better to use SharedPreferences here tutorial to understand idea about it

If you don't want to use SQL to store your data, you can try SharedPreference.
And yes, you have to load all values in everytime you read or write. But don't worry, it won't be hard for mobile phone hardware.

Related

The most effective way to load and use objects from an xml-file

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.
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.
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.

What's the proper way of importing option lists into an Android app?

I have been storing option lists for my Android app in a cloud table. For example, categories like "historical fiction","biography","science fiction", etc. I see the following pros and cons:
Pro:
I can make changes to the list without sending an app update to Google Play
Not normalized - I can use the text in my other data tables instead of a reference ID
Con:
App needs to take time to download from the web each time (or at least check for changes)
English only
I believe the "proper" way to do this is the use the XML resource files. But I need to make sure the selection references correctly with my data. That is, my app needs to understand that "Poetry" and "Poesía" are the same thing.
Is the correct thing to do:
Forget about it since I'll never get to the point where I'm translating my app anyway
Use a string-array and use the index (0...x) to know what the selection is
Use a 2-dimensional string-array with a reference ID in the first column and the text in the second?
If you are handling the category list online, then why not handle the translations online as well. Here is what I would suggest:
In your application options, have a list of supported languages (each in their native translation). These language options should be stored on whatever server application is handling your web requests. Each language is associated with an integer ID that the user does not see, but is stored in the app.
Whenever you issue a web request to get a list of options, include the language id in the message. This will allow you to know what language the user has picked and can use a 2D array or some other structure to handle the conversion to and from the chosen language.
I'm not sure if this helps at all, since I don't know exactly what you are making or how you are designing it, but from the given description, this is an easy and effective course of action.

Split up forms for user input in Android

This is an easy question, but I don't know how to word it to get a result from Google.
I am currently building an app in Android. One of the features of the app includes inputting a large amount of personal data (i.e. emergency contact information, social security number, and others). The file will include around 40 fields, but I don't want the user to have to scroll through one layout to fill all this information out. Thus, how do I create new "forms" to populate without having to create a new activity and xml layout for each set of data?
Any help is appreciated. Thank you for your help.
Thus, how do I create new "forms" to populate without having to create a new activity and xml layout for each set of data?
You are welcome to create a new fragment and XML layout for each set of data, if you prefer.
At the end of the day, your code is largely the same in all cases:
You need all 40 fields in an XML layout file somewhere. Whether this is one file, two files, or ten files, is up to you.
You need to your controller logic for handling that input from those 40 fields somewhere. Whether that is in one activity, N activities, or N fragments, is up to you.
If you are expecting Android tools to be able to magically generate all this for you, just by you thinking really hard and staring at your monitor, Google's Project Synapse has not yet been released yet. :-)

Data Storage - which approach for a song-lyrics-app?

I want to write an android app that basically shows titles of songs in a list view, and by selecting one song in the list, the lyrics of that sing are shown in a textview. In a second step there would be maybe a translation of the lyrics for every song.
So far nothing too complicated, but since I'm completely new to android programming, I wonder what's the best approach to store the data (i.e. the song titles/lyrics). I thought about a single (xml?)-file for each song where the filename is the title and the file contains the lyrics. I think that would make it easy to add new songs. where would such files be stored typically? /res/xml?
Or would another approach be more suitable? database storage? content provider?
I would use a database and a content provider since it becomes very trivial to bind the content to ListViews using the Loader API.
According to the documentation about Data Storage, you have several options.
But the storage strategy that seems to meet your needs is an SQLite Database.
You can make use of SQLiteOpenHelper and ContentProvider to get it working.
It will require quite an amount of work and understanding to implement it but it's worth the effort :
Esier than other solutions to manipulate data once it stored.
A lot of android component are designed to work with databases cursors.
Easy to add new data and structures as your application evolves.
You will learn a lot about how develop android apps "the right way".
If i were you i would avoid :
SharedPreferences because this is not suited for list of data as there isn't any "id mechanism". On the other hand it is pretty easy to use for small settings.
Internal Storage because it is difficult to manipulate the data once it is stored. Also it is not the recommended way to store that type of data.

Can I display multiple screens content using single activity

Iam developing an android application wherein i need to manage good amount of data. I have 2 doubts.
I planned about 25 screens(pages) in this application. To display each and every screen do I need to create a seperate Activity or can i manage it with single activity. Which option will increase the performance of the application and which one is better.
I have very good amount of data. Do I need to store in SqlLite database or can I store it in string.xml resources file.
While designing the screens are there any constraints that are to be followed. Please suggest me.
1) IT is always better to have a separate activity for different tasks as it increase the readability and maintainability of your application code.
2) I would not recommend using one single activity because it will make your class very cluttered and at some point of time it will become very difficult to make further amendments in your code.
3) You can use strings.xml as a replacement of database as it is not meant database purposes. If you have a large amount of data than you have 2 options:
i) If this data is static and not going to change in near future than use sqlite database.
ii) if this data is dynamic in nature and requires frequent update and sync than you must choose a web based service for handling this data.
i want to add that you can do this but it's not a good idea as mudit said ,
you can do something like this :
this.setContentView(R.layout.home);
//do some work here ,Click on a button for example
this.setContentView(R.layout.detail);

Categories

Resources