soulkito
soulkito

Reputation: 236

Make Urban Airship restart after killed on Android

I'm working on Android and I know Urban Airship doesn't officially support this, but I want my app to keep getting notifications even if the app have been killed.

According to Urban Airship it should still work after the user "swipe" closes the app which would be fine by me but I think some phones handle it the same way, telling the OS not to receive any notifications anymore.

I've seen a lot of apps that have a service that restart itself after being quit so I know it's possible somehow. But not being able to modify the service that Urban Airship uses since I don't have the source code limits my options.

So what I wonder is if there's a simple way to keep the push notification Urban Airship uses Google Cloud Messaging stick after being quit without messing in UAirships source?

Edit: Okay after some further tinkering I found out that swiping and force stop is indeed not the same. It's okay for the notifications not to work after a manual force stop.

Upvotes: 1

Views: 1123

Answers (1)

ralepinski
ralepinski

Reputation: 1766

No action is required to continue to receive push notifications if takeOff is being called properly in Application.onCreate.

When an app is forced stopped, it will not receive any broadcasts until its manually started again. This includes the BOOT_COMPLETED broadcast and GCM intents (push notifications). If its forced closed, its probably for a reason and the intended behavior is to not start up for any reason other than a manual app launch.

Apps that are closed from a swipe will continue to receive intents. There is no reason to add a service or a receiver to auto start. If you are calling takeoff in the Application.onCreate() and push is enabled, everything should be working just fine. Having the service that starts up and never shuts down is wasting resources and is not needed.

Calling takeOff anywhere other then the Applicaiton.onCreate is dangerous, and in this case its redundant if you are also calling takeoff properly in the Application.onCreate. The Applicaiton.onCreate is triggered every time the application needs to start for any component (receivers, services, activities). So just by receiving an intent, we will call takeOff.

GCM works by sending an intent to the application when a new message has arrived. It will wake the app up exactly like the BOOT_COMPLETED wakes the app up, call takeoff, and the GCMIntentRecevier provided by Urban Airship will handle the message and post it to the notification center like normal.

In your example, you will probably notice that your service wont actually call takeOff, and if it does it will log an error saying its already taking off. If you are still having troubles with your application, please try to reproduce with one of the provided samples first. If you are able to produce it with a sample, you should write in to support. Here are the samples - https://github.com/urbanairship/android-samples.

I also noticed - "TODO: Move to a method so I can retry after a while if AU fail to take off" Urban Airship will only fail to takeoff if the config is invalid. Retrying takeoff with an invalid config will never succeed. Its best for this to be called once, and only once, on the main thread in Application.onCreate. Please read - http://docs.urbanairship.com/platform/android.html.

Upvotes: 1

Related Questions