Event key "back" and Composer

Double and triple check your usage.  

Not exiting app while in simulator or on phone?

If in simulator, no prob.  It is calling:

native.requestExit()

That should exit the app while on Android though

Not exiting when on the phone, I do not know how to test this on the simulator.

I tested your example (15-android-back-nav) and realized that on the last screen it also does not exit the application.

On windows simulator you can use Hardware > Back menu option (or Alt + Left arrow shortcut)

Thank you for your help, Benzeliden.

@Daniel,

0. Please re-download the example.   I updated it further and fully tested it on a device.

1.  You must have missed it, but I stated that debugEn = true in the new() call will allow you to use the ‘escape’ key to test back.  Still you can use the suggestion Benzeliden gave too.  I just like simple single keystrokes when testing.

  1. I found and fixed an issue/bug in the module.   This caused the ‘exit’ call to fail on deviecs.  I had the code out of order:

Was like this:

 local alert alert = native.showAlert( params.title, params.msg, { "NO", "YES" }, onComplete ) local function onComplete( event ) if "clicked" == event.action then local i = event.index if 1 == i then native.cancelAlert( alert ) alert = nil elseif 2 == i then if( params.onExit ) then params.onExit() end native.requestExit() end end end -- ISSUE? onComplete wasn't defined before creation of alert

Fix:

 local alert local function onComplete( event ) if "clicked" == event.action then local i = event.index if 1 == i then native.cancelAlert( alert ) alert = nil elseif 2 == i then if( params.onExit ) then params.onExit() end native.requestExit() end end end alert = native.showAlert( params.title, params.msg, { "NO", "YES" }, onComplete )
  1. No matter what you do (short of calling os.exit()), you cannot test exiting the app in the simulator.

  2. This update includes the following changes:

  • scenes changed to: 1,2,3,4,5, options
  • scene 1 leads to 2 and 3
  • scene 2 leads to 4 or back to 1
  • scene 3 leads to 5 or back to 1
  • scene 4 leads back to 2
  • scene 5 leads back to 3

This will let you fully test the idea of back button to go back to last scene.

Thank you, roaminggamer!
 

I’m going to need some time to assimilate your code and see how I can make it work inside the code I’ve made.

I’m a beginner and some things are a bit difficult for me, but I need to learn all this and overcome all the challenges, as I have several ideas to put into practice.

As soon as I have news, I’ll be posting here. :slight_smile:

Daniel

Recently I have worked on my App again and I can say that all advice was very helpful (mainly the roaminggamer tips ).

My App works now, but when I’m navigating for the scenes I receive a runtime error.

"Runtime Error

/Users/jenkins/slaveroot/workspace/template…composer.lua1583: attempt to call local “lruScene”  (a string value)"

I tried to fix it, but I don’t know where the failure is occurring.

Screenshot_2017-10-09-18-54-00.png?dl=0

Are you removing scenes or destroying them?  That may be the source of the issue.

Also, please list the composer.* functions you’re using.  i.e composer.gotoScene(), composer.???

Finally, are you using overlays?  

If I coded composer.* lruScene would literally mean ’ least recently used scene’. 

This would then be used in automatic scene caching and cleaning code.

Following this ‘logic’, there may be an issue occuring when composer tries to remove a scene, which may in turn be caused by the way you’re maintaining them.

I think you may need to pay someone to look into this for you if you can’t resolve it.

PS - I updated this post because I brain-farted my last response.  LRU is a well established caching algorithm term and concept in case you were curious.

Oh, one more note.  That kind of an error should be reproduce-able on the simulator.

To get a little more info, do this at the top of main.lua.

local composer = require "composer" composer.isDebug = true

To try to force an error do this when running in the simulator:

local composer = require "composer" composer.recycleOnSceneChange = true -- Not exercising same algorithm, but let's see what happens.

Hi, roaminggamer!

I was able to solve the problem, this was occurring (I think :)) because of an unfixed “Timer” and a function that was previously outside the Composer. But I found the error strange because it does not point to anything concrete inside the code.

I added “CancelTimer ()” in your function and that’s it.

onGotoScene3 = function ( self, event ) composer.gotoScene( "scene3") cancelTimer() return true end

Now I think I’ve got it all figured out.

Thank you very much for your help and for all the other forum collaborators.

I intend to study more to have this immense reasoning that you all have, and for the ease of solving all these problems.

Thank you so much!

Great tip!

Thank you again!

Here is a link for my app.

https://play.google.com/store/apps/developer?id=Studio%20Domingos&hl=pt_BR