Skip to main content
Participant
July 10, 2014
Answered

Partial wakelock in Adobe Air for Android

  • July 10, 2014
  • 1 reply
  • 1384 views

I'm developing Adobe Air (for Android) application which is intended to be constantly on. App has event based operations. However, when phone enters to sleep mode app is able to perform only one or few events in a second which is not good enough. AIR's SystemIdleMode.KEEP_AWAKE -mode is not an alternative since it is too battery consuming.

I'm looking for a solution where phone is allowed to go into sleep mode (screen is off) but still CPU performance is not drastically dropped. Not sure if Android's partial wakelock -mode does the job and is available via ANE?

This topic has been closed for replies.
Correct answer

What kind of events are you wanting to be able to handle during sleep? According to Adobe's documentation, AIR drops the frame rate to 4FPS when the gets moved to the background or becomes inactive. Im guessing that the screen turning off counts in that regard and that is probably a reason as to why you are only getting a few events a second, but I can't say for certain without knowing what kind of events you are using. As far as using Android's PowerManager WAKE_LOCK feature, Google's documentation says that you shouldn't use that API unless you absolutely have to and if you have to use it, you should use it and be done with it as soon as possible as that API hurts battery life (they even bold the part about battery life). What are you trying to do that requires the app always be on? More details may help myself or others provide other options to accomplish what you are trying to do. If you have to use the PowerManager, you should be able to create an ANE to activate and deactivate the WAKE_LOCK mode, but that might only help the Android/Java side of things and you would probably need to move your event handling over to the Java side of things because the AIR app will still be dropped to 4FPS once the screen turns off.

Adobe AIR * Mobile application design considerations

PowerManager | Android Developers

1 reply

Correct answer
July 14, 2014

What kind of events are you wanting to be able to handle during sleep? According to Adobe's documentation, AIR drops the frame rate to 4FPS when the gets moved to the background or becomes inactive. Im guessing that the screen turning off counts in that regard and that is probably a reason as to why you are only getting a few events a second, but I can't say for certain without knowing what kind of events you are using. As far as using Android's PowerManager WAKE_LOCK feature, Google's documentation says that you shouldn't use that API unless you absolutely have to and if you have to use it, you should use it and be done with it as soon as possible as that API hurts battery life (they even bold the part about battery life). What are you trying to do that requires the app always be on? More details may help myself or others provide other options to accomplish what you are trying to do. If you have to use the PowerManager, you should be able to create an ANE to activate and deactivate the WAKE_LOCK mode, but that might only help the Android/Java side of things and you would probably need to move your event handling over to the Java side of things because the AIR app will still be dropped to 4FPS once the screen turns off.

Adobe AIR * Mobile application design considerations

PowerManager | Android Developers

Jake81Author
Participant
July 14, 2014

Thx wadedwalker for your response. I was looking for a simple timer based events. I realize that partial wake mode would be battery consuming, so I'm planning to keep events as simple as possible.

I guess there is no way to put AIR app into partial wake mode? Then, as you said, maybe the correct way to implement this would be creating a handler (service) on Android side, which communicates with AIR when the app wakes?

July 14, 2014

Well Im a bit puzzled now. I just created a quick AIR app using AIR13 for Android and did a DEACTIVATE test on the NativeApplication.nativeApplication property and used a TextField to "trace" out the frame rate when the app deactivated. The frame rate stayed at 24FPS the entire time. I turned the screen off, let it turn off, went to the home screen, and switched to other apps while the test app was still running. In all cases, the frame rate never dropped to 4FPS as indicated in Adobe's documentation. So it is either something a bug or feature of AIR13+ or it is how Android KitKat handles applications in the background. Im using an unlocked/stock Moto X running Android 4.4.3. The app also appends the getTimer() call to the end so you can see that it does change. Here is a link to the quick app I created: Dropbox - deactivate.apk

I guess if you want to download that and test it out to see how it behaves on your device and let me know the results. What device and OS are you running?

Below is the original message I started to type before I decided to create a quick app to test with. It may or may not still be relevant based on your results from my app test.

If you are looking at just recording information, you could probably setup something on the Android/Java side that gets started when the app "sleeps" using the DEACTIVE event as a trigger to start the ANE side of things. Then when your app "wakes", you could use the ACTIVATE event to trigger a call to the ANE to pull all the data collected in the Java side back to AIR and stop the ANE data capture since the data capture would be back to being handled by AIR.