Someone know here, I'm a newbie for android development. Now I'm trying to create a simple fitness application. The first thing is my app will do is getting some data from user. For example; weight, height, age etc. And Program will return something that can change by data what we got from user. I wonder, how do need I storage the data? Need I use PreferenceActivity, database or another?
Also I want to ask, do we need to use term of preference as suffix for layout elements when create layout to use for PreferenceActivity?
How many users do you support in your app on one device? If just one, go for shared preferences: it's easy to use and you store very little data.
If you support multiple users, you may start thinking about a SQLite database. Also, think whether you want to expand your app in the future and maybe add some fitness goals, track weight progress over time, etc. In this case, you may want to use a database as it is much easier to expand.
As for your second question, if you use PreferenceActivity, you don't need a layout at all. You define all preferences in xml file. Check this link for more info: http://developer.android.com/guide/topics/ui/settings.html
Just take sharedPreferences for this little amount of data
If you need to save only that kind of data I suggest you to use sharedPreference (here a nice tutorial http://www.vogella.com/articles/AndroidFileBasedPersistence/article.html).
Then, if you need to save some history, I suggest you to create a database, Android use SQlite (http://www.vogella.com/articles/AndroidSQLite/article.html).
No, you don't need to use your preference name as a suffix for layout elements, but could be useful for you to use similar name.
Related
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.
I am working on an app and I basically want to implement some type of function like the note apps do. Basically I have a listview set up that has a link to different xml files. I want the user to have a create new option where they can add some text to an edit text and be able to save the text and add it to the listview I have set up.
My question is how do apps like the Note Pads and Memos ect. do this. Do I need to set up some type of database or?
I have googled it quickly and did a quick search on stack but I don't know if I'm even searching for the right thing. I am just looking for a step in the right direction please!
Thanks!
They all save their data in a database. For android you should use an SQLite database because it is included in the SDK. There are a lot of great tutorials for SQLite out there, but I think that this is the best one
http://www.vogella.com/articles/AndroidSQLite/article.html
It is possible to do this using SharedPrefernces, but I would not recommend it, for efficiency and simplicity
I have a custom object, "TimeSheet", which itself contains Calendar, DateFormat, and int fields. The App is designed to use several of these objects, so I'm planning on storing them in a List as they're created and I'd like the App to be able to save these objects to internal storage when the App closes and reload them when it opens.
I'm still something of a novice when it comes to Android development (I've only published one App so far), so I'm not entirely sure of the best way to go about this. I'm guessing an ObjectInputStream and its Output counterpart are probably the best options, but I'm not entirely sure. I'm completely willing to change my design strategy to store a collection of these TimeSheet objects in the easiest way possible.
Can anyone recommend a good direction to go from here, and if possible, provide brief, simple examples?
Thanks!
There is no single right answer for something like this. A lot of it depends on the amount of data that you are storing. If you don't have much data, used SharedPreferences, if you have lots of data and it is complex, use a database. I wouldn't use a database if you don't have much data. You want to keep things as simple as possible and adding a database can complicate things. Here is a link that talks about the different options. Check it out. Hope it helps:
http://developer.android.com/guide/topics/data/data-storage.html
There are 2 ways to do this
Save it in a SQLite database..
Save the objects in a json format in a file
See this discussion
I'd honestly recommend using a SQLiteDatabase to store them: write functions to map your 3 fields to the database (Calendar would become a NUMERIC, DateFormat would be a String, and the int fields would all be NUMERICs) and to rebuild your object fields from a row in the database. Its a bit heavy up front but will make the inevitable feature expansion much easier.
I'm pretty new to android can some one give me a better idea which one is a better way to save 2 edit texts on activity 1 and 24 edit texts on activity 2.
i need to save it with date / time stamp
and
be able to open by linking with onClick of a button.
what is the best option: shared preferences, sql db or file?
Please help me out here.
Really it depends on what your application is going to do with that information and how you intend to use it.
Based on what you've briefly described, I'd recommend using an SQLite DB (with or without a Content Provider) to store the information just based on the fact that you're looking for a date/time stamp. Plus, it gives you a lot of flexibility going forward and it's not like there is a ton of overhead in that approach.
Shared Preferences are great too, but mainly are for key/value pairs and aren't nearly as flexible.
Last but not least, this question has some good info on using SQLite DB on Android and the differences in using a content provider vs. not.
I am new to android. I am creating ToDoTasks application in android. i have crated Gui of the application and it is working perfectly. I am able to add tasks in it. Now i want to know that i want to save 'task list' in an area so that every time user comes on it , than it should maintain the list of previous tasks which were added in it. What is the best way to do this ?
Whether i should go for database in android or is there any other way to do this ?
Please suggest me. Please don't mind , i know this is a silly question but i have no other way to solve it.....
You have multiple options with varying degree of complexity.
Do you foresee sharing your todolist with another application. If yes then you need to host your data as a content provider.But I digress.
The most simplest option is Shared Preferences. The api is very simple to use and you do not need to write a whole lot of plumbing code. You can directly store an list of string in the shared preference of your activity.
The more elaborate solution is using sqllite. If you foresee your domain model to become more complex than just a list of strings, then you should see if the additional complexity is worth it.
Look here for more details. (I will not worry about the file options, the other two mentioned here are superior to that solution)
You can use sqlLite db for android. See this or this for example.
Here is another example of an SQLite implementation:
http://p-xr.com/android-tutorial-simple-but-persistent-data-storage/