0

My program need to check online if something has been added to a database by someone.

A simple

checkifdatahasbeenadded();

does the trick.

I need to check these every second or so, but I'm not sure how to do this.

I can link this to a button,

public void onButtonClicked(View view) {
    checkifdatahasbeenadded();
};

but this isn't a good idea, because then only if the button is pressed the check is done.

I simply need to check the data every second.

The data is then used to update the listview in screen.

What's the best way to do this ?

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

Add a database trigger to the table you want to check whether the data has been changed. The trigger should be looking up INSERTS/UPDATES/ OR DELETIONS as your choice. If it get triggered, it should do an Insert to a table that can store the notification. Then when you load the list view, you may have to check the notifications table whether there are any notifications. You can do this in a runnable program that is running in the background. Then the list view should be updated and the particular notification should be deleted in that moment.

Keshan Fernando
  • 347
  • 1
  • 4
  • 16
  • What server? What database? Im using Parse.com, users can store data there, and my program needs to retreive that data when users store the data. Are you using Java? Yes A database trigger sounds sweet, any documentation about that ? – user3423455 Jan 14 '15 at 18:47
  • It's up to you to choose whatever you want. If you are developing C# or vb.net, most popular is MSSQL.. OR if you are developing web based apps, MySQL is the most popular dbms to use as i suggest – Keshan Fernando Jan 14 '15 at 18:56
  • Yes MySQL documentation is there . . http://dev.mysql.com/doc/refman/5.7/en/triggers.html – Keshan Fernando Jan 14 '15 at 18:59
  • You can use whatever database you have anywhere which is accessible. This is a tutorial on how to connect to MySQL using Java http://stackoverflow.com/questions/2839321/java-connectivity-with-mysql . In your database, basically you need to have the stuff I explained in my Answer and then connect it from your Java code and play with that. – Keshan Fernando Jan 14 '15 at 19:06
  • This will help you to build your own runnable program and check the database every 5 seconds. http://stackoverflow.com/questions/26042526/triggering-a-java-program-based-on-database-updates-and-time-interval – Keshan Fernando Jan 14 '15 at 19:10