update listview automatically when a new data is inserted in the database

Asked

Viewed 241 times

1

I created a webservice and the application and all this worked right, however I would like my application to update the listview as soon as a new data is entered in the database (this data may come from another device) and I would like you to send a notification as well, however, my problem is in updating the listview, I think I should create an Asynctask or a Service, however, I’ve read about them but I’m having difficulty to understand them and use them, so, there is some other way to do this list update without using Asynctask or Service, if not, someone has a good example to give me?

I have an application that shows me the tasks I should do today, and this information is stored in a database that access through a webservice, but when a new task is inserted in the database I have to go in the application and click on the button to update the listview and so appear the new task.

I would like when the new task is inserted in the bank my mobile app updates the listview automatically and displays a notification or plays an audio or vibrates the phone and etc...

1 answer

0

You can create a ContentProvider in your app, to access/manipulate database data (in place of direct queries to the database) and implement a CursorLoader in your Activity (which will get the data through Contentprovider) and change your Listview Adapter to use the data from that cursor returned by the Loader. With this, Listview will always be updated as a system is automatically created for the database in this implementation.

It is complicated to detail all the steps here as there are several, so I suggest taking a look at this course that explains perfectly well how to implement this:

https://br.udacity.com/course/android-basics-data-storage--ud845/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.