I'm writting simple music player. There is a fragment in the app, where user can search for tracks. I want to show last 5 (for example) user queries. SharedPreferences only allows to save unordered data. I'm not sure but using SQLite only for 5 strings sounds strange.
What is the best way to save user queries?
Related
I have set of data stored in Firebase Realtime Database (snapshot attached).
Click to View
I want to read this data when I press a button in my Android app and store it according to the person name, for example storing that Jack is 20 years old and Marry is an engineer, but I need to do this for more than just 3 users.
I'm able to call the data and read it but storing it in the way I described above is not working.
EDIT:
I added part of the code I'm working with, my main goal is when I click a button to call the data from Database, I'm able to do this but I can't figure out the best way to store this data in a way that I can use it. For example I want to display the name of the user and his role and age but I want to do this for as many users as available in database.
Code here
I'm designing a fitness app where a trainer would upload workouts to a database and a client could access those workouts via an app. This is easy enough to setup, however, I'm struggling to find a good way to upload workouts to a database in a way that someone who is non technical could easily do. I've been primarily playing around with FirebaseDB, but I'm open to suggestions. I'm trying to avoid having to create my own app for the trainer to input data and upload to the database as it will take extra time. Is this the best approach?
If you are thinking to expand your app in near future i suggest you to avoid FirebaseDB. Go with MS-SQL. Create User Table and add a Field may be called as 'Member_Types' (Admin|User). If the logged in user is Admin then Show him Different Page from where He can Upload Data by just inserting in Textboxes/Dropdowns/etc,etc and Clicking One Button Click. Whereas if the user logged in as a USER type show him the page which shows the data uploaded by Admin.
Using FirebaseDB is OK but If you want to deal with really complex data which this app can (In case to want to expand this app and want to add more and more features). I even Suggest if u are going with MS-SQL , Create your Own WebAPI to handle the requests.
All the Very Best for your App.
I have an activity which is a form, there are some radio inputs in this form, each one have dependent activity, for example, there is a button named favorite sports, when the user clicks it, he will open a new activity to see the radio inputs as (football, basketball...), - actually I am not the father of this dummy idea, but the client made it- so I want save to results of all user inputs, I am asking if using sharedPreferences is a good idea, or if there is an alternative way to reach what I need?
You should only use SharedPreferences to store small bits of data related to user configuration/basic user input. It can only store basic data types, so if you have more complex bits of information, you should probably switch to another mechanism.
Also, you should not store large amounts of data in SharedPreferences; it's not made for that. Instead, use an SQLite database for a more robust solution.
I am building an audio player where user can select a song which he wants to listen from a ListView. After he clicks on a song, audio player starts playing that song.
Audio files are not stored locally, they are fetched from some online audio library. After user opens a list of songs, he receives a lot of urls who look like this:
http://audiolibrary.com/user/1/77.mp3
http://audiolibrary.com/user/1/567.mp3
http://audiolibrary.com/user/1/34.mp3
Each song is identified with unique id as you can see. It's easy to temp download that song and play audio and that is working fine. The thing I want to accomplish is something like this:
User clicks on a song1 in list view and song1 starts playing
In the middle of the reproduction, user decides he had enough of song1 and switches to song2
He closes the app while song2 is still not finished
Next time when he opens an app, if he clicks on song1 or song2, reproduction starts from the place where he stopped listening for the song1 or song2
How to efficiently accomplish something like that on Android? Should I create an SQLite database for this situation, use SharedPreferences or something else? How do you usually handle similar situations?
Thank you :)
You need to store the time he pressed pause at in a permanent fashion. The options for this are database, shared preference, web service or file. Each has pros and cons.
Database pros: easily extensible with other information if needed, no difficult parsing code
Database cons: lots of setup code for what's a fairly simple amount of data, additional dependencies on 3rd party code
Shared preference pros: minimal code to setup and use
Shared preference cons: not really meant for dynamic string names, slow to parse and performance will degrade as the number of strings decrease, not easily capable of storing additional data.
webservice pros: would be available across devices/platforms
webservice cons: requires a server and the most code to do, requires an internet connection
custom file format pros: absolutely optimized for your needs, easily extensible if you design the format well
custom file format cons: all custom code and you'll have to write all of it.
Pick the one that weighs out the best for you.
I'm building an app which helps in searching just like Google's search widget. In my app I have an auto-suggest which brings the typed data from wiki-suggest URL in json format. I'm able to populate it, but I want to know that how can I save my recent searches and display it on the app, just like Google's search widget do. I don't have any idea about this. Any suggestion or tweak will be helpful at this point.
Can I do one thing, typed query after pressing search button, save it simultaneously in the database or something and again if user comes back then I can populate the string in the app. Is that possible?
If yes, can some point me to how to store and retrieve string from the SQLite database.
You could use SQLite to store the search keys in a table along with a column for the time they were searched for. You could then access the most recent searches by limiting by time. A google search for SQLite Android will return a lot of resources on this issue. This tutorial might be useful to start: http://www.vogella.com/articles/AndroidSQLite/article.html.
You could use either a file you write or use SharedPreferences to store data outside off your app lifecycle: SharedPreferenes | Android Developers