how would you recommend for me to design an android app where i want it to
1) send location update every 10 minutes
2) to show push notification
I want both actions be available even when the app is closed.
Here i might ask for your explanation what “closed” states an app can be in?
a) removed from recent tasks stack – close the whole process including its services ?
b) forces closed – close the whole process including its services ?
c) other?
I was using
1) alarm manager that sends a pending intent to a broadcast receiver.
2) notification manager
I have tried to register all manager using ApplicationContext instead of Current-Activity context. Now both actions work even after user remove the app from the “recent tasks” stack.
but I’m not sure about the “closed” states so I might be missing something.
1
Actually, I’m not 100% sure what you’re asking but:
If you register a PendingIntent
to the AlarmManager
you can rely on the system to deliver your intent.
If you registered the BroadcastReciever
in your app’s Manifest, the code in the Receiver will be executed (Note: always consider doing the actual logic in an IntentService
, since BraodcastReceiver
s only have about 5 seconds to perform their work!).
Simply put your call to the NotificationManager
here.
If you registered the LocationListener
using the ApplicationContext
it will receive the location updates until the user “force closes” your app. But you could schedule another Alarm that registers the LocationListener again.
But keep in mind that you should keep the location updates on a moderate level – it drains battery.
As for your question about the “closed” states:
- An app is not running. It was never started, force closed by the user or crashed.
- The app is not visible. The UI is “closed” but the process is still running. This happens if someone hits the back button and the app closes. The system might close it completely if it needs the memory (point 1).
There are probably more cases, but these are the usual ones.
If the AlarmManager calls to your BroadcastReceiver and the Type is RTC_WAKEUP your App will be started if it was closed before.
8