Android "Back" button if possible?

Below is how I currently go back using Director. Can someone with a good heart please just translate the below code using the hardware “Back” button on an Android device and going from “Screen2” to “Screen1” using storyboard? The documentation on this is slacking very badly.

 

local backBtn local onBack = function( event )    if event.phase == "ended" then        director:changeScene("Screen1")    end end backBtn:addEventListener("touch", onBack)  

 

Have you seen this blog post? 

http://www.coronalabs.com/blog/2013/03/26/androidizing-your-mobile-app/

It uses Storyboard, but it’s easily adaptable to Director.

Hi,

I’ve tried to implement this (linked) solution whilst playing a video using media.playVideo(). The video is bundled in the apk, it plays fine no worries and returns to the initiating scene after playing using the complete callback.

With the back button sample code linked above, when the back button is pressed during the video playback the video stops, disappears and the screen seems to freeze…a second back button press is required to return to the scene.

The current setup has an event handler on an image press to a local function that has one statement, media.playVideo(“video_name.mp4”,true);

In the main.lua there is a function and event handler for the key event:

local function onKeyEvent( event ) local phase = event.phase; local keyName = event.keyName; if ( "back" == keyName and phase == "up" ) then storyboard.reloadScene(); end return true end

I am looking to find out why and resolve the issue of the second back button press to “unload” or remove the video playing from the screen and to return to the scene gracefully on just one press of the back button.

Any help would be greatly appreciated.

Thanks

Chris.

I’ve not tried this with every combination.  I think media.playVideo() backgrounds your app while it plays in a separate process (that is your app is suspended then resumed.    Perhaps you need to make sure your app handles recovering from being suspended.  I don’t know that one back button will work here.

Have you seen this blog post? 

http://www.coronalabs.com/blog/2013/03/26/androidizing-your-mobile-app/

It uses Storyboard, but it’s easily adaptable to Director.

Hi,

I’ve tried to implement this (linked) solution whilst playing a video using media.playVideo(). The video is bundled in the apk, it plays fine no worries and returns to the initiating scene after playing using the complete callback.

With the back button sample code linked above, when the back button is pressed during the video playback the video stops, disappears and the screen seems to freeze…a second back button press is required to return to the scene.

The current setup has an event handler on an image press to a local function that has one statement, media.playVideo(“video_name.mp4”,true);

In the main.lua there is a function and event handler for the key event:

local function onKeyEvent( event ) local phase = event.phase; local keyName = event.keyName; if ( "back" == keyName and phase == "up" ) then storyboard.reloadScene(); end return true end

I am looking to find out why and resolve the issue of the second back button press to “unload” or remove the video playing from the screen and to return to the scene gracefully on just one press of the back button.

Any help would be greatly appreciated.

Thanks

Chris.

I’ve not tried this with every combination.  I think media.playVideo() backgrounds your app while it plays in a separate process (that is your app is suspended then resumed.    Perhaps you need to make sure your app handles recovering from being suspended.  I don’t know that one back button will work here.

Hey Milner99 – did you ever figure out a good solution for this? I’m having the same problem – one back press from a video seems to freeze, and a second press returns.

I don’t actually use an Android, but people who do tell me that the standard behaviour when hitting the back button from a video will return you to the app. 

Hi @sjerrett,

I’m a little confused… you are developing for Android, but don’t have an Android device to test on? The back button can definitely be handled, and you can “override” the OS’s default behavior if you want, to perform a task that you desire.

Take care,

Brent

Hey Milner99 – did you ever figure out a good solution for this? I’m having the same problem – one back press from a video seems to freeze, and a second press returns.

I don’t actually use an Android, but people who do tell me that the standard behaviour when hitting the back button from a video will return you to the app. 

Hi @sjerrett,

I’m a little confused… you are developing for Android, but don’t have an Android device to test on? The back button can definitely be handled, and you can “override” the OS’s default behavior if you want, to perform a task that you desire.

Take care,

Brent