4

I am asked to build an Android app, that receives an input from a "central station", and gets alerted, like "please respond immediately ."

I'm new to Android programming, so I have no idea how to get such a "live" input, so any help will be appreciated.

This question has two parts. The first part is up to me, I guess. But still important in finding the right path.

1) how will the "central", alert the user? I have two solutions in mind for now :

1.a.) The central can insert a database entry to the server, and the app constantly (1 per minute) sends requests to a php file, and asks if there is an entry with id=my_id , and status="unread".

1.b.) The central sends an SMS to the device, and my app listens to the incoming SMS messages from that number.

and the important part :

2) How can I make sure that the device gets "alerted", even if the user has closed the application ?

Thanks for any help!

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
mobilGelistirici
  • 449
  • 4
  • 7
  • 19

4 Answers4

2

For the second part of your question, or even for the first for that matter, you could make a service which runs in the background.

Anudeep Bulla
  • 8,318
  • 4
  • 22
  • 29
2

From your requirements , it seems implementing push notification will solve your purpose, details here

you want to poll server each minute, that will be waste of battery and bandwidth as well, why not receive event from server using push notification

you can receive push notification even if app is killed, so that will solve your other purpose too

cheers!!

this is good tutorial for implementing push notification to your app

Sourabh Saldi
  • 3,567
  • 6
  • 34
  • 57
1

Actually Anudeep answer is correct i just want to make to easier to implement You can make a class that extends Service Something like this:

public class YourCustomService extends Service {
...
}

and set it's onStartCommand to:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("LocalService", "Received start id " + startId + ": " + intent);
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
}

Now you have a service that starts it self when it can allocate resource regardless of the application is running or not so you can write some code that will be running as soon as the service is started

Here it is a helpful link

Community
  • 1
  • 1
Arash khangaldi
  • 110
  • 2
  • 15
1

I think you are looking for Google Cloud Messaging API

jeff
  • 13,055
  • 29
  • 78
  • 136