user3482023
user3482023

Reputation: 25

Android service working with mySQL data

So I have a desktop app working with an MySQL DB. I need to include a notification system inside that desktop app, allowing the desktop users to send notifications to a set of 10 tablets. So it's like sending SMS, but not really. So the tablets users must receive the notifications sent by desktop users and the other way around, tablet users must be able to send notifications to desktop users. Since the common ground between the two is the MySQL DB, I thought of the following schema:I would need to build a notification service, that will run all the time on the tablet after I run it once. It should check a remote MySQL table to see if new records are inside, and if so, then display a notification on the tablet. I am sure many of you experts have done this at least once.

So the path I thought of is:

  1. I have a MySQL db on a server, and I have an application (desktop) that allows users to input a notification (a new record) inside a mysql table.

  2. Build a PHP backend that will serve my Android service with "yes" or "no" answers and a second PHP that will return the data of the notification upon request

  3. Build a service that will make a call to that PHP every minute

  4. In case "yes" is received by service then make another call to the second PHP asking for notification data

  5. With the response, create a notification on the device and show it to the user.

Now, First of all,: is my logic ok?

Second: How do I create a service that "installs itself" and remains installed and running all the time on the tablet? I've been trying the tutorial from here but the service does not do what is should. Perhaps it's because of RECEIVE_BOOT_COMPLETED ?

Third:Should I make async calls to the PHP, or is it enough to make simple calls, since there is no Activity/Intent that would freeze until receiving response

Fourth: Is it possible as I imagined to have all this as an independent service, so not an Android App that the tablet users must run and keep open?

Is there any good example out there of a service like this?

I found an example of something very similar to what I want (I think) but I have a few questions about it. So the tutorial is here My questions are:

1. Will this service start on Android startUp ? Or do I have to do something extra? What would that be?

2. Where do I place my call towards PHP?

Please help me,

Thank you

Upvotes: 0

Views: 429

Answers (1)

keithrel
keithrel

Reputation: 321

I would suggest that you make your database on the tablet a ContentProvider. Then you can implement syncing using the sync mechanism.

http://developer.android.com/training/sync-adapters/index.html

To trigger the update on the devices look at Google Cloud Messaging.

http://developer.android.com/training/cloudsync/gcm.html

I haven't done this, but I have been researching it :-)

Upvotes: 1

Related Questions