Store last played songs Android media player app - android

I'm currently developing a media player application for Android. Now, I would like to store the last played songs. Which approach for persistence should I take to do this ? I mean, should I use SharedPreferences, o perhaps SQLLite database, or something else ?
I would settle for save the songs ID in some specific order. It's not necessary to save the title, artist or album of the song.

You must have seen all the Storage Options that android provides. If you read the SharedPreference part, it provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. It also supports saving sets and ArrayList. See Save ArrayList to SharedPreferences questions. If you just want to store the last played song ID's, then using SharedPreference might be preferable. It is also faster than using database.
However, if you have more structured data, then using database might be better to manage. To know more about when SharedPreference would be good to use and when SQL Lite database, read Pros and Cons of SQLite and Shared Preferences .

Related

Android saving user's choices as favorites

I am developing a music app wherein a user can select choices of songs to play. One feature I want to implement is to save a song as favorite. Once favorite is clicked upon, it should save the user's choice and display it next time when the user logs in. None of the data is stored on the app. Everything is fetched from a server. What I intend to store is just the names of the songs. I read the Android Documentation http://developer.android.com/guide/topics/data/data-storage.html for various storage options and those which seem applicable to my case are:
Internal Storage
Database SQLLite connections
as these will store the data private to the application.
Which among these should I use? Are there any other suggestions?
How did you populate the song list? Did you have any cache or you just fetch it from the server every time? To improve the performance and be able to use your application when there is no internet connection - at least can view the song you have ,I suggest you have to provide some sort of cache. Once you have the cache, SQLite is the way to go, for both song data and favorite data.
Both of them works fine. But since your data will be a single text, i would recommend Shared Preferences, which keeps the data as in XML format and it's easy to use.

What method should i use to store text and pictures on the phone?

I am making an expense log application. The user can create a log by adding a picture of an object and then add the price and some comments to it.
I would like to know if I need to use database to store that data or i can store it directly to the phone.
There are several ways you can store data in Android application: SharedPreferences, files, SQLite databases, etc. Which one you choose, depends on your requirements, amount of data you need to store, etc. I suggest you read Data Storage section in the Android developer's guide to get started.
For your case a databse is the best fit. You could put all expenses in a String array in the SharedPreferences but this would be horrible to use. You would always need to load all expenses to memory if you are searching for one and so on. A database allows searching, filtering and ordering through SQL. It is a bigger initial amount to create the Database but the management of the data will be much nicer afterwards.
Demonick is right about the images, only store the path to the image file in the database and then retrieve the images from there. If you are storing images on the SD-Card the user or other apps can access and delete them so don't count on them to be available later.

Android Preferred Storage

We are developing an application in android,We have to save some lists and data to be used by application.We have saved it in sqlite and we use that data by using cursor.
Now my question :
What is more efficient to store data in we should continue with sqlite or to store data on strings.xml or we should use shared preferences ??
Sql Lite is for sharing your data as a datasource. It does not make sense
otherwise as you have the overhead of writing queries to serialize your objects.
Shared Preferences is a preferred way to store internal data.
You can't use assets as said by someone else before because its read only.
Well It Depends on your requirements. If your requirements are dynamic then you should try Sqlite for Storing the Datas.
You should use String.xml to store constant strings, which are not going to change easily ( i mean by increment or decrement of Strings ).
In your scenario, I think best way to store is in asset folder. Means store that data in txt file in key-value pair and while displaying in list, your just have to read that and display in the list. So that saving step can be avoided.
Shared Preferences are generally used to store primitive data. I'd suggest you to go with SQLite .

How to store data from my app

Actually i want to know how to store data from my app in the device so that i can review the store data when i run the application again..
means in simple terms i want to say that suppose i have text box where i write some information..now when i click the submit button, this information will be save,so that when i open the application the stored data should be appear in the text box..
In all terms i want to say that i just want to stored data in the way that we are using database for storing data..so please anyone suggest me how that can be done in android.
if possible show with an example
Regards
Anshuman
If you have to store small amount of data, you can use SharedPreferences in Android.
If the data that you have to store is big/complex enough, try using SQLite database.
Still need help?
UPDATE: There's a tutorial that I wrote to demonstrate how to use SQLite database. check it out here. Although it copies existing database into device's memory, but other versions of it, which create database through code can also be devised from it.
A better tutorial is here : http://www.vogella.com/tutorials/AndroidSQLite/article.html
1) If you want to store data in table format then you can use SQLite database in android
2) If you don't want to store data in table format then you can store in SharedPreference
more info about SharedPreference here and here
Android comes with a built in SQLite database that you can use. I advice you to go trough this notepad tutorial. It teaches the basics of using Android SDK including different states of the android application as well as how to use SQLite with Android.
For storing simple key = value pairs, you can use Properties.
For data storage as in a database, you can use sqlite on android.
Android provides several options for you to save persistent application data. The solution you choose depends on your specific needs, such as whether the data should be private to your application or accessible to other applications (and the user) and how much space your data requires.
Your data storage options are the following:
Shared Preferences
Store private primitive data in key-value pairs.
Internal Storage
Store private data on the device memory.
External Storage
Store public data on the shared external storage.
SQLite Databases
Store structured data in a private database.
Network Connection
Store data on the web with your own network server.
Data Storage

How should I save scores and settings on android?

I'm creating the specification for a game I'm about to start creating on android, my main concern is how should I keep scores and settings on android? I assume they would be two different things.
The game has players that will have their settings and scores stored and then a settings menu (for the person setting up the game, not necessarily the player).
How would I go about storing these things? What type of data storage means should I be looking into?
Settngs of your game should be stored in SharedPreferences, also you can use default preferences to set some default setting, just use
PreferenceManager.setDefaultValues(context, R.xml.preferences, readAgain);
What about scores I think you sould store it into SQLite database. In future if you plan you can export scores, sync with server etc. If you will use preferences for storing scores it could be more difficult.
By the sounds of it I would be looking into using a SQLite database, that is if you want to save settings for each user along with a score.
If there are very few settings and it is only a simple int score, you could use SharedPreferences like mentioned, but if you want to start storing more data for each user, it will get confusing quickly, as they are really quite a simple data store.
For the general application settings the SharedPreferences should be what you'Re looking for for the scores ... well it depends on what kind of data that is. It is is really just a score (integer) then you can of course save it in the SharedPreferences too.

Categories

Resources