Saving Information Android - android

I am still fairly new to android and trying to learn day by day. I am trying to create a simple test application that you register for with an email/password to learn how to use save data from users.The app I am making is going to be simple, once they register and login, the user can search through a list of items I created on my MainActivity, and when they click on the listview item it will open a new activity. On the new activity, there will be a favorites button that I want to be able to click on and it will store that listview item information onto a favorites fragment I created and it will show the user a list of movies the user saved as favorites.
I am just trying to find out the best way I can do this. I have looked into SQLite and Firebase, hoping someone can explain to me which way would be the best way to approach this and maybe link me to a tutorial if possible.
Also the adding favorites to a listview item, if any one has a tutorial on that. I have already created my main listview and using Intents take the information and pass it to the new activity. It just clicking on the favorites button and saving the information into a new listview I do not know how to do, especially for when the users closes and re-opens the app the favorites will still be there.
Any help will be greatly appreciated.

To save favourite items in a new ListView you have to store the information somewhere. If you're using SQL, then store the Primary Key value in a favourites table that you can then use to find the corresponding information from the initial ListViews table.
If you are using firebase then each item in your list should have a unique key. Save that key and then when loading the favourites ListView, use the saved key to get the key's child data.
To summarise:
Store in a favourites table/branch the items the user selects as favourites and use that table/branch then to populate the favourites ListView.
I hope this helps

Another approach you could consider doing is storing your favorites using SharedPreference. The logic that would then follow is you have each row in your list view be an object that has an ID. Anytime a user favorites that object you save it into a set and store that set into SharedPreference that are corresponding to the current account username. You can then retrieve that set and show only the favorite objects for the user later on.
As for the SQLite vs Firebase question, I have not worked with Firebase yet, most of my interactions have been custom API calls. Having said that, I think SQLite would be a nice way to handle this as it would keep things easy and give you a good understanding of both sides of the equation.
Check out this tutorial. This very next one also covers SQLite:
https://www.youtube.com/watch?v=4SwAvFYMsXE

Related

Firebase User Favourites List

Looking for a push in the right direction for creating a list of user favourites in Android. I have a list of items from a database which a user can scroll through and add to their favourites so when they log into their account they will be presented with a list of their favourite items. Is it possible to add an array or collection of some sort to the user so when they favourite an item then the primary id is added to some favourites parameter in their account which can be retrieved when they log in?
Sorry if this question is a bit basic, I am still new and am really only making this app to teach myself how to write android apps that use a database.
Thanks in advance!
Since you already have a database. I would add a new table or column to your existing table that would be set to 'true' or 'false' depending on whether or not the item is a user favorite.
This is better than a SharedPreferences because if you store row IDs you now have to manage that information in two places.
Additionally it's easy to get all items or just favorited items using an SQL query.
https://developer.android.com/training/data-storage/sqlite.html

Usin SimpleCursorAdapter confusion

I have a ContentProvider implementation in my app which works fine. I have a table called elements where the user can store a bunch of information.
What I am doing is when the user opens the app, I pull this data out of the database, process it using the display options set by the user (Like change the string formats, time formats, date formats, number decimals etc), and then put it in ListFragment which using my own implementation of ArrayAdapter. User can of course change the preferences in the middle of the session, where I reload the data and reformat it and present it to the user. The user can click on an item in the list, and see more details of that item. I accomplish this by overriding ListFragment.onListItemClick().
I have been reading about SimpleCursorAdapter. I am confused if the use of this would be more correct than using an ArrayAdapter for what I am doing. I am confused because I am not directly mapping the database data to the view. So should I be using a SimpleCursorAdapter? Also, the _ID column seems to be a requirement. I don't want to rename my table at this point. After a few articles and tutorials, I am not sure what to do. So any suggestions are appreciated.

Managing a sqlite database using activity list

Ok, I have a database with id column as timestamp
I made an activity list from the db.
I want to manage the db (delete rows) using the list, but the thing is I don't want to
View the whole timestamp, in every row I'll put only the time with some info and
I want to group the list ,as in contacts grouped by alphabet, by the date.
First, how can I make group in an activity list? (Making groups to the output list not the db)
Second, what is the best way to implement this? When user chooses an item and confims delete
I should delete it from the db but I have only patial timestamp...
(My only link to the db is the timestamp - I don't actually know where to store it in the list and I don't want to put it as a string in the text view, do a substring to get it back - is there another way to do this?)
I tried to search tthe web for some examples but I only found a simple ones.
Thnx :-)
?
I think what you're trying to do is create a database of tasks identified by a timestamp. You probably don't want to use a timestamp as a unique ID for the row. Instead, use an integer and qualify it as "PRIMARY KEY" when you create the database.
group the list? I'm not sure why you want to do this in the structure of the database. It's more common to group the list in the output, and leave the db itself in as flat a structure as possible.
Retrieve the primary key when you display a list of tasks. When the user clicks a task, use the primary key to choose the task to delete. You don't have to display the primary key; it serves as a behind-the-scenes "link" between the displayed info and the db row.
http://www.vogella.com/articles/AndroidListView/article.html
I should use cursor adapter for managing db.
And this one for grouping a list:
http://code.google.com/p/android-amazing-listview/
Thnx for the efforts

If no search result, then add item

In my android app I have a search screen.
The content is stored in a database, and a listview is populated via a ListAdapter.
This all works correct.
But I want the following functionality.
When a user searches, but gets no result, I would like to give him/her the option to add the search item.
for example:
list in listadapater is: [monkey, donkey, mouse]
when the user searches for: lion, he will see no results.
But I want the option to add lion to the database list.
Hopefully someone can get me in the right direction.
Thanks in advance,
Goldhorn
You simply add the new item into the database. Then you requery the database for a new cursor which you then pass to the adapter.

How to save database information to a file in android?

I have an application that uses a pre-polulated database to list events. The app allows people to save these events to their favorites by setting a '1' to the column isFavorite. Then the user can view only a list of 'favorited' events which searches for all rows that have isFavorite = 1.
If any changes happen to the events or I need to add more to the list, I have to make those changes and then push the update to the app which completely writes over the table, clearing out their favorites.
Is there any way that I can, on upgrade, save a list of id's of all the events that they have set to their favorites, then after the new database has been loaded, to set all id's in that list to 1 so the user doesn't lose their favorited data?
If there are any other better solutions to this problem I would really appreciate it, this has been the biggest hurdle for me so far.
I guess, you have a SQLiteOpenHelper-class? This class must be extended and then provides two functions: onCreate (which is called when the Database is queried and it doesn't exist (Normally creates your Database in the first place)) and onUpdate (which is queried when the Database structure should be updated).
The onUpdate-method has an SQLiteDatabase-Object parameter, which is your Database. You can then Query the information you need, save them and then create the new Database-tables. After that, you can insert your saved data back into the Database.
Can't you cope with thus in your DB design? Have a user favourites table that holds id's. So long as these id's don't change upgrade won't affect it surely?
One possible solution is backing up part or all of your database to restore at a later time. I found this guide quite handy http://www.screaming-penguin.com/node/7749
Alternatively, you may save their favorites as a SharedPreferences. http://developer.android.com/reference/android/content/SharedPreferences.html for more information on that.

Categories

Resources