0

i was thinking if there is anyway to sync android app with a web/website account. Basically, if the user logs in through the web, i want the android app to log in/start up/show notification. Should i use a background service in android to monitor the account or something else Please help Thanks

Samsquanch
  • 8,866
  • 12
  • 50
  • 89
j4rey
  • 2,582
  • 20
  • 34

2 Answers2

0

As far as I can see, you have a couple of options:

  1. Use a background service (as you suggested) which is constantly running and checking. This will be battery consuming.
  2. Use the AlarmManager to schedule a repeating alarm to check on a scheduled interval. This will be less battery consuming but also less immediate (unless you set a low interval which will consume a lot of battery).
  3. Use a push message. This will be the most accurate and least battery consuming for your phone, but it's also the most advanced (difficult) to set up.
Toon Borgers
  • 3,638
  • 1
  • 14
  • 22
  • I also want an option to start up my app when the user gets the message or notification. is it possible with a push message? – j4rey Oct 08 '14 at 09:28
  • If you look [here](https://developer.android.com/google/gcm/client.html#sample-receive) it gives some code to implement a broadcast receiver. You can use this code to display a notification which will start an activity when clicked. If you want to start the activity directly, take a look at the answer to [this](http://stackoverflow.com/questions/3606596/android-start-activity-from-service) question. – Toon Borgers Oct 08 '14 at 09:43
0

Based on your requirement, optimized solution is to use GCM - Push Notification. Based on the whatever action occurs at web, you just need to send a push notification to clients. Based on the push notification IDs, client needs to perform appropriate action.

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • Thanks, i was looking for something more than just notifying the user, i am looking for something like if the user logs in the webpage, the android app will automatically logs in plus send some data to the webpage/web server. hence, kinda like syncing up android and the web – j4rey Oct 08 '14 at 09:38
  • Yes that you can do with push messages. Read my answer again and try to understand the mechanism I mentioned. – Paresh Mayani Oct 08 '14 at 09:50
  • thanks....i guess i need to do more studying and research, as i am fairly new to android. – j4rey Oct 08 '14 at 10:17
  • No issue! Just to provide more information, you can send more information/details/commands in push messages, you just need to check which command has been sent by server. Based on the received command, client will perform task like do login, etc. – Paresh Mayani Oct 08 '14 at 10:26