1.21 gigawatts
1.21 gigawatts

Reputation: 17760

How do you make your mobile AIR app run in the background all the time?

I have created an alarm clock type application in AIR for mobile. For it to work I would think it needs to be running all the time.

Basically, I need to check if it's a certain time (checking a stored value - the value could be in a local AIR SQLLite database, online, local storage (AIR cookie). When those conditions are met, for example timer complete, I need it to launch the application.

How would I keep my app running all the time or is there a better or alternative way to do what I want to do? Is there a headless mode? Pretend I am a beginner mobile developer and beginner AIR developer.

Note: When I say launches the application, I mean the application launches in full screen, not a notification badge or message. Although, if the first option isn't possible is it possible to show a native alert type message that when clicked OK or whatever the native way is, would then open the application?

UPDATE
It seems that in Android there is a way to run your application as a service. When notifications or messages come in from say, Google Cloud Messaging, then it runs the service class and any handlers listening handle the message. I think then you can launch the application if you need to. Note: I'm not sure if GCM is needed since it would be client side. An Intent might be what I'm trying to do. :P

It's still sketchy but I'm adding more detail as I understand it.

How this relates to an AIR app I'm not sure yet. I think possibly by native extension.

GCM Getting Started - http://developer.android.com/guide/google/gcm/gs.html
GCM Overview - https://support.google.com/googleplay/android-developer/support/bin/answer.py?hl=en&answer=2663268

Upvotes: 2

Views: 3969

Answers (1)

Pascal S.
Pascal S.

Reputation: 41

AFIK, on Android, applications run in the background when minimized by default (true multi-tasking). Adobe AIR just lowers the framerate automatically to 4fps by default when minimized. The lowered fps may have an impact on the delay of your timer events for your alarm clock so I would recommend using an enter_frame based Timer-surrogate, IF you rely on the client to trigger the alarm. Note: you can also query your server while the app is minimized, if you'd rather have the server trigger the alarm and/or maximize the app.

In iOS, it's a different story since apps do not run when minimized by default. The only exception is when your app uses one of the UIBackgroundModes (set in the app manifest). The App Store has become very stringent as far as allowing any app with a UI background mode, since the 4S came out ( bc of battery-gate ). For example, if you try to submit with UIBackgroundModes=audio, your alarm-clock app will be turned down, bc the audio is not continuous (it's only heard when the alarm goes off!). So, for iOS, you have to use either local or push notifications.

Local notifications are set by the client, with a particular delay, just prior to minimizing the app (on app deactivate is a good place to do this). Unfortunately, with the local notification ANE for AIR-iOS I have seen so far (http://juankpro.com/wordpress/2012/06/17/using-the-local-notification-ane-on-ios), you cannot set the alarm sound effect via the client, but you can repeat the default local notification sound every minute, from the time the alarm goes off.

Hope this helps a bit.

Upvotes: 4

Related Questions