Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hopefully this question is not too broad or too much to ask for...

I am building an Android app for my office. The app is used to send message alerts (as a custom "message" object class) to all users with the app (my office only). Once the message is received, all the names of the recipients are listed at the bottom with a status icon showing their reply to the message (thumbs up or down basically).

I have a Node/Express server that is used to track, store and distribute the messages and log their history. When a user sends an alert message, it will go to the Node server which will handle the distribution.

Requirements of the app

It is for emergency responders. The app must ALWAYS be able to receive an alert. If they have no service, that's ok, an SMS will be sent as backup. But all the Android phones must ALWAYS be listening to my Node server for updates.
The app MUST start on boot, or at least a service or something to listen to the server. This is based off the last requirement that it must always be listening to the server.
Once the message is received, the user will view it on a specific activity. This activity lists all the recipients and their status (thumbs up or down). This screen will need to be connected to the websocket at all times and update status real-time as the other users are submitting their status.
Here is my question

There are a few ways that I have seen recommended, but I don't know which to use.

Create a background service (service or intentservice... no clue?) that will start on boot and connect to the Node server.

This raises a few questions:

a. Is it ok to have a TCP socket connection like this on the phone 24/7?

b. It will only be exchanging data a few times a day. Will the open connection kill the battery?

c. Can I use this 'always running' service to start my application activity up in the event that the service receives a message from the server? Also, can I easily send the message from the background service to the application? (I don't know threading too well.... thats the hard part for me here).
Use GCM to "trigger" the phone to start the app, and once the app is started up, use the main UI thread to create the connection to the server and pull down the message that was sent.

a. I have never used GCM and only just learned about it yesterday. Is this the sort of thing it is used for?

b. If I use GCM, do I still need to create an 'always running' background service that starts on boot anyways?? Or does GCM have some built in way of just always listening?
I do not entirely understand how to use threads, my Java knowledge is below average (I wouldn't say beginner though), and this is my first Android application ever. The app is looking beautiful and really coming along great, but I just don't know how I should handle this network being always connected.

What I have tried:

I messed around with making a service but my phone crashed a lot and said my app was slowing everything down and android wanted to uninstall the app lol.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900