Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to block android back key?

Discussion in 'Android' started by egoquat, Apr 25, 2014.

  1. egoquat

    egoquat

    Joined:
    Jul 4, 2012
    Posts:
    93
    Hello. I want to know way to block android back-key fundamentally. How can it be?
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,663
    I think the back key only does what you want it to do within your code... like hitting back shouldn't quit your android app by default unless you use something like

    if(Input.GetKey(Keycode.Escape));

    within your app. Atleast I had never noticed that it could... ever...

    Is what your asking to block it within the android os in general? If so... good luck with that :p
     
  3. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    You should make sure to have the back key do what users expect it to (exit the game). If you don't, you will get several users posting mediocre reviews asking that you do that. I say this from experience. Do it right the first time.
     
    halley likes this.
  4. totsboy

    totsboy

    Joined:
    Jul 12, 2013
    Posts:
    253
    I've read somewhere that the recommendation was to make it exit the app only on the main menu screen or something like this. Do users expect it to close the app at any time?
    I'm iOS user, so I have no idea about this back button stuff >.<
     
  5. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    They expect it to either leave the app or pop up a dialog asking them to confirm leaving the app. Easier to do the first one. I don't mean "quit" the app, just stop playing and go back to home screen.
     
  6. totsboy

    totsboy

    Joined:
    Jul 12, 2013
    Posts:
    253
    Oh, ok! Thanks for the tip :)
     
  7. DalerHakimov

    DalerHakimov

    Joined:
    Mar 14, 2014
    Posts:
    302
    Last edited: Apr 29, 2014
  8. egoquat

    egoquat

    Joined:
    Jul 4, 2012
    Posts:
    93
    I solved it, block all of the back keys in my projects all. if(Input.GetKey(Keycode.Escape)); Thanks all.
     
  9. Wei Xiaofei

    Wei Xiaofei

    Joined:
    Jul 21, 2014
    Posts:
    2
    Hi guys, When I switch the scene, while it done, I press the back key, It doesn't work, and then quit,

    My u3d ver. is 4.3.4

    Someone help me please.
     
  10. egoquat

    egoquat

    Joined:
    Jul 4, 2012
    Posts:
    93
    Even I blocked all NGUIs internal call to back-key and it's work well.
     
  11. tanoshimi

    tanoshimi

    Joined:
    May 21, 2013
    Posts:
    297
    Along similar lines, can anyone suggest how to override the behaviour of the home and app switcher buttons? I don't care for the Google Play rules - this is for an installation not for general release - and the client wants to prevent pesky kids from exiting the application.

    I found http://stackoverflow.com/questions/3898876/how-to-disable-the-home-key but can't seem to implement it - not sure if that's because it's out of date, or because I'm an Android noob...
     
  12. imaleper

    imaleper

    Joined:
    Nov 14, 2012
    Posts:
    30
    Yo, tanoshimi!

    Did you ever figure out how to disable the app switcher button??

    It's really annoying my users in landscape mode.

    Any help would be greatly appreciated!

    Cheers
     
  13. domdev

    domdev

    Joined:
    Feb 2, 2015
    Posts:
    375
    I know its 2019.. but I was bit confuse how to use it.. I add it on the update if(Input.GetKey(Keycode.Escape));, but when I tap back or return button it exit..any?