0

How can I update my ListView automatically when I update my mysql database ? for example: "when I receive a new mail, Gmail app updates the mails ListView automatically !"

atrw sr
  • 141
  • 1
  • 10

1 Answers1

0

Call this when ever you add or remove data from the database:

YourListView.invalidateViews();
LordMarty
  • 1,551
  • 1
  • 12
  • 17
  • I should make things more clear : When the database is updated ! all the clients should receive a notification and get their listview updated automatically (like chat apps : whatsapp ..etc) – atrw sr Jul 19 '13 at 01:23
  • I'm guessing the database isn't stored locally? Do you have a function where you check if there is any changes in the database, or is that really what you are looking for? – LordMarty Jul 19 '13 at 01:27
  • I have a shared mysql database ! I add/update data using webservice (php files stored in server ) – atrw sr Jul 19 '13 at 01:32
  • Well, you have to have some function that checks the database. Unless you want to have the server notify all the users. – LordMarty Jul 19 '13 at 01:38
  • Ok! I can send a notification using JSON to clients whenever one of them add/update data, but my question is : how to receive this notification? Can I use Broadcast receiver ? – atrw sr Jul 19 '13 at 01:43
  • This is really not my field. But I can suggest this: Create a JSON function that calls the server every 15min or what ever, and the response should give you a the size of a given table or something that you can use to compare the last check with. This link might help: http://stackoverflow.com/questions/3027066/how-to-send-a-json-object-over-request-with-android – LordMarty Jul 19 '13 at 01:51
  • I found the solution : Google Cloud Messaging http://developer.android.com/google/gcm/gs.html – atrw sr Jul 20 '13 at 01:36