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.
Related
I have an app that gives to the user all chapters of a book. I want to make each chapter downloadable if the user wants to download it, with a button. I would like to know how to do this. I'm using Firebase Realtime to get these chapters from an online DB. Should I save the downloaded chapters in a local database on phone or have another way? I'm already using dbref.keepSynced(true) and FirebaseDatabase.getInstance().setPersistenceEnabled(true). But I want to save in cache just the chapters name, not the text of the chapter.
I want to make each chapter downloadable if the user wants to download it, with a button.
You can indeed create a local database like Room, but I don't think that's really necessary since the Realtime Database already provides an offline persistence mechanism.
Should I save the downloaded chapters in a local database on phone or have another way?
This is what the Firebase Android SDK already does.
According to Yigit Boyar excellent talk at Google IO 2016, the Mobile App should be usable whether online or offline. On top of that, the data should only come from disk (local storage) to display on screen.
Currently I am implementing e-book store Android app. In my App, I would like to pull data from network about 10 books to show in the list (RecyclerView).
With endless scrolling feature (like Facebook), the app will pull more data from the network when the user scrolls down to the end of the list.
If I keep all the data in local storage (sqlite database), the database will be loaded with thousands of records of books eventually.
Is it normal to store thousands of records in the local storage just only for offline support?
So should I keep the data in Local Storage according to Yigit Boyar's guidelines? Or is it enough to be based on Network cache (references by this article)?
Is there any other solutions that you would like to suggest for my scenario?
It is essential to provide local storage for the eBooks, as the users can read at anytime and anywhere once they downloaded the book.
You can separate the eBook data into two: one for the list and other for detail, in a way that the data for the list is as minimal as possible -- only the required fields for the list. Only if the user clicks on a book and goes to the detail page, download the entire data of the single book.
So storing 1000s of books data wouldn't take more storage as you are storing only minimal data required for the list.
And you can purge the old data based on Least recently accessed books after a certain time period, say, every week or month.
I newbie to android programming and I have question which might sound silly.
I am writing app for a shopping store, which communicate with store's website
Every user must sign in to use the app.
In sign-in process, I save information like user name, address to send products and phone number in website's database.
I have 2 questions:
should I also save user information in local database(sqlite), so in case user would like to change stuff, I won't need to fetch it from web server?(or fetching it every time is better approach??)
The app, display list(picture+description) of products the user can buy(total 12 products).
the list can change every 2 weeks or month. should I save the images locally and have an AsyncTask to check if something changed and only then to download the delta, or should I download them every time.
Thanks in advance
Android provides support for user accounts so it's hard to say whether you can use that or whether you need to implement a custom solution without more details. Have a look here for some information on implementing authentication accounts
As for question 2, I would store the images locally as you say there are only 12. You could then have the server notify the mobile app (check out GCM) when there is an image update to pull from the server. You can also have a look at the Volley library which will assist you in retrieving and displaying images from a web server.
you can store any information in sqlite and use some cache(private/public) to store images for first time store images in cache and from second time onwards load images from that cache use volley library for server calls and image cache
http://developer.android.com/training/volley/index.html
for question two: no you don't need to save the pictures locally to keep your app using the minimum storage space.
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 .
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.