-1

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

1 Answer 1

0

Actually, I'm not 100% sure what you're asking but:

If you register a PendingIntentto 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 BraodcastReceivers 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:

  1. An app is not running. It was never started, force closed by the user or crashed.
  2. 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
  • what "closed" states an app can be in Commented Mar 24, 2014 at 13:34
  • @user23621 see my edited answer. Commented Mar 24, 2014 at 13:55
  • BraodcastReceivers only have about 5 seconds to perform their work! - why is that? Commented Mar 24, 2014 at 15:56
  • If you registered the BroadcastReciever in your app's Manifest, the code in the Receiver will be executed - but then I saw force closing is stopping the whole process and thus the receiver as well Commented Mar 24, 2014 at 15:57
  • always consider doing the actual logic in an IntentService - but then it means I'll have to re-start a service every time? nowadays my reciever calls a regular java class (manager). no service Commented Mar 24, 2014 at 15:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.