• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

How to quit an Android App - urgent!

Community Beginner ,
Oct 20, 2011 Oct 20, 2011

Copy link to clipboard

Copied

Hi guys,

I'm about to release an Android version of my app. It runs as fast on an Samsung Galaxy S2 - as good as the iPad 2!

When you press the home button, the Application stays open in the background and the music plays. It's annoying for the customer to have to manually

go and exit the app from memory.

I'm using Air 2.7

I found this code online, and put it in the first frame of my timeline, but it get 'syntax errors' on the first 2 lines. Anyone have some code that works?

Thanks,

Matt

if(Capabilities.cpuArchitecture==”ARM”){

NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true); NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true); NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);

}

function handleActivate(event:Event):void

{

NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

}

function handleDeactivate(event:Event):void

{

NativeApplication.nativeApplication.exit();

}

function handleKeys(event:KeyboardEvent):void

{

if(event.keyCode == Keyboard.BACK) {

NativeApplication.nativeApplication.exit();

}

}

TOPICS
Development

Views

8.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 20, 2011 Oct 20, 2011

Copy link to clipboard

Copied

Are there any cases where it does quit ok? Like, does pressing the back button work?

I read somewhere about people using and Event.EXITING listener, maybe that would do something.

In any case, throw in a SoundMixer.stopAll() on your deactivate function, and something on your activate function that will take the app back to the main menu, in case you do get stuck with it being open all the time.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 20, 2011 Oct 20, 2011

Copy link to clipboard

Copied

Actually, none of the code above would publish at all - it threw out errors on the first 2 lines, so I'm not sure what will work. Also, I tried it on my friend's Galaxy SII earlier,

so can't test it right now..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 20, 2011 Oct 20, 2011

Copy link to clipboard

Copied

You do have these import lines, don't you?:

import flash.desktop.NativeApplication;

import flash.desktop.SystemIdleMode;

import flash.system.Capabilities;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 20, 2011 Oct 20, 2011

Copy link to clipboard

Copied

That must be it - I didn't have any code for Android yet.  Thanks, I'll get my friend to test it with the above code

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 20, 2011 Oct 20, 2011

Copy link to clipboard

Copied

It's still getting 2 syntax errors on this line when I publish a swf:

if(Capabilities.cpuArchitecture==”ARM”){

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 20, 2011 Oct 20, 2011

Copy link to clipboard

Copied

Make sure the player type is set to either Android or iOS. You would get errors if you have it set to Flash Player.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 20, 2011 Oct 20, 2011

Copy link to clipboard

Copied

Yes, it's set to Android.

It's the 'Arm' line that's always having the prob. Any all the code I find uses this line..

I found another link:

http://cartoonsmartblog.wordpress.com/2011/04/04/what-to-do-when-your-air-to-android-app-closes/

He says this too:

"One thing to note too, posting your app to the Google Android Market store is like the wild west of app stores. Anything goes. The app will be live within minutes and there’s no review from Google prior to posting. So they don’t really care if you handle closing/pausing your app correctly. BUT I submitted one of my games to Amazon App Store and they were more particular about what the app did in the background. Basically they didn’t want it to just quit entirely if a phone call interrupted the game. And I submitted this game months before I knew any better so at the time, my code for handling the Home or Back buttons just quit out the app entirely. They didn’t like that. So Amazon rejected it for not pausing on deactivation."

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

Hi guys, my Android app was rejected by Amazon for the reasons below. (needs to pause on incoming call)

I've still not had any code that actually publishes my Android File, so if anyone has experience of what works, please post here, including the Android classes I'd need on my first frame.

If i'm using Flash CS5.5 with Air 2.7, so I need to install the Android SDK or not?

Thanks!

Matt

Amazon's message:

"Your app has failed a test case. Bug Description:An incoming voice call does not place the application in a pause state. When the interrupt is received, the audio generated by the application continues to play and is audible for the duration of the voice call. Steps to Reproduce: 1) Launch the application 2) Initiate a voice interrupt 3) Observe that, when the interrupt is initiated on the test device, the audio generated by the application continues to play 4) Accept the interrupt 5) Observe that the audio generated by the application continues to play for the duration of the interrupt OS/Device(s)/Form Factor: HTC Sensation 4G A 1.03.531.1 "

Please correct the issue(s) we found with your app submission so we may continue working to get it in the Appstore.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

In the Permissions tab of the Android publishing settings is READ_PHONE_STATE. Check that box. Then when a phone call comes in AIR will automatically mute any sound. That might be enough to keep Amazon happy.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

Thanks Colin, that's a handy toggle - I'll try resubmitting it!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

Right, just found the culprit for the above code - the syntax for the code I'd found had changed the punctuation.

I've ticked these boxes in the permissions. They seemed like the right thing to do, but let me know if I should

untick any of them!

- INTERNET

- WRITE EXTERNAL STORAGE

- READ PHONE STATE

- WAKE LOCK

This code has now been corrected, and does publish, but I haven't tested it yet:

import flash.desktop.NativeApplication;

import flash.desktop.SystemIdleMode;

import flash.system.Capabilities;

import flash.system.System;

    

     if(Capabilities.cpuArchitecture=="ARM")

    

         {

    NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);

    NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE , handleDeactivate, false, 0, true);

    NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);

    }

    function handleActivate(event:Event):void

    {

    NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

    }

    function handleDeactivate(event:Event):void

    {

    NativeApplication.nativeApplication.exit();

    }

    function handleKeys(event:KeyboardEvent):void

    {

    if(event.keyCode == Keyboard.BACK) {

    NativeApplication.nativeApplication.exit();

    }

    }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

Don't know about the other two boxes you've checked. The Internet one is needed, and the read phone state to get sound muted when a call comes in. Don't know what you're doing that needs the write external storage and wake lock.

Probably doesn't matter anyway, I doubt that Amazon will complain if you have asked for a permission that you end up not actually using. The only thing to note is tha thte user will see the list, and someone somewhere may decline to install the app if you are asking for too many permissions.

Thinking about wake lock, I'm going to check into that one, because maybe that is needed in order to keep the screen alive during long sections of no interactivity. I have an app that might need that permission.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

yes, we don't want to bamboozle the customer with too many - I'm surprised they even have to get asked. I doubt Apple would confuse their customers like that.

I thought the Write External Storage should be essential for Google market, if they're phones with a tiny memory. I expect that will run out if they download a lot..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

LATEST

monkey500 wrote:

yes, we don't want to bamboozle the customer with too many - I'm surprised they even have to get asked. I doubt Apple would confuse their customers like that.

Apple actually reviews apps though, Google doesn't.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines