Anas Bin Numan
Anas Bin Numan

Reputation: 77

Flex Android Background Service, Air SDK 4.0

I'm new at flex android. But experienced with web and AIR. i'm developing an android application with flex and i need to start a timer when the app is in background. And doing some research online what i did is: 1. on application complete :

if(Capabilities.cpuArchitecture=="ARM")
            {
                NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
                NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE,onDeactivate);

            }

2. on onDeactivateFunction:

protected function onDeactivate(event:Event):void
        {

            deactivateTimer = new Timer(1000*5,0);
            deactivateTimer.addEventListener(TimerEvent.TIMER,vibrateDevice);
            deactivateTimer.start();

        }

and on vibrateDevice function:

protected function vibrateDevice(event:TimerEvent):void
        {
            if(Vibration.isSupported)
            {
                var vibration:Vibration = new Vibration();
                vibration.vibrate(200);
            }
        }

i'm using an ANE for iOS and Android for vibration. I've confirmed that the ANE works fine. But as the application should vibrate the device when deactivated in evary 5 seconds, it does nothing !!!. I've also checked the permissions to vibrate the device

<uses-permission android:name="android.permission.VIBRATE"/>

i'm using Air SDK 4.0 as they said from Air SDK 3.9 , they added support for Android background service.

Can anyone please help me on this ?? It'll be really appreciable

Thanks in advance

Upvotes: 0

Views: 269

Answers (1)

tomergott
tomergott

Reputation: 74

as far as i know when air app is deactivate all the timers are being stoped, therefore the timer wont trigger anything, try to use ENTER_FRAME instead of timer but be aware that also the ENTER_FRAME is being lowered to 4 FPS so you must calculate the counter. However, I have another problem is even when the app is running on the background after a while (around 30 minutes) its being automatically shuts down.

Upvotes: 1

Related Questions