I want to implement Notifications based on changing in MySQL. i have an app thats send tasks to device on runtime. I want that i get notification on my android device when i insert a task in Task table in MySQL. I can get every task from MySQL using php. and i have also make login in which i get username and password and verify it from MySQL. and same like that i have did for task. to get tasks. like this and now i am following this tutorial for implement notification. but how can i get notification when inserting task in MySQL. i have to make an service that will run in background but how will i get if there is anychange in task table. ?
3 Answers
You can create a trigger in your MySQL database and run an external application everytime a row is inserted in that table. More info: http://dev.mysql.com/doc/refman/5.1/en/faqs-triggers.html#qandaitem-B-5-1-10
1 Comment
m4t1t0
Ok, may the force be with you.
You should take a look at Firebase Cloud Messaging, it provides functionality to send messages to the device without polling.
1 Comment
1615903
It is not recommended to send large amount of data via Cloud Messaging, but instead use it to notify the android device that there are changes in the database that it should fetch.
You can use MySQL triggers to catch changes. In the trigger code you'll do INSERT INTO changes_log … and you can watch the changes_log table for new records.
2 Comments
m4t1t0
yeah, but you need another trigger to watch the changes_log table, or if you write an observer, why that extra step?
Volodymyr Smotesko
@m4t1t0 your solution is definitely better. I didn't know before that triggers can execute external programs. I proposed to create a changes_log because one can make this new table simpler or better suited to be handled by observer.