How Can I?... Create A Custom Exit Button? (android)

Discussion in 'How Can I...?' started by Vlad-NY, Jul 7, 2020.

  1. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    Hey boxers,

    I've seen a lot of threads around about how to create a exit button that works more or less on Android, so I've made a quick setup / a way to do this and I'm gonna share a step by step tutorial below.

    Please note that this is not the correct way of doing it but at least is something.

    Let's begin:

    Buildbox Setup 3.x.x
    • On your UI screen drag and drop a Navigation button
    • Set the Name to be Exit Button (name is important!
    • Set Function to Custom
    • Add your images save and export your game to Android.

    Check the red marks below:
    [​IMG]

    Android Studio Setup:
    • Open PTServicesBridge class
    • [​IMG]
    • Scroll down until you see buttonActivated method
    • [​IMG]
    • Now here you must add the following lines of code just after the last if statement
    • Code:
      if(name.contains("Exit Button")) {
          activity.finish();
          System.exit(0);
      }
    • [​IMG]
    • Save the project, deploy it to a telephone and enjoy your custom button.
    Congratulations you've just created your first custom exit button behavior.

    IMPORTANT NOTES:
    1. The naming of the Navigation button has to match the name that is checked in the if condition. Otherwise this won't work and you can't exit your app.
    2. On most of the cases for android when the activity is closed/finished the app will exit but it will still be available on quickview list (or the place where you can see all your opened app and you swipe up or down to close them)
    As I said before this is not something that is intended to be working based on Java standards but it is something that I wanted to share with the community. Any suggestion/improvement would be greatly appreciated and I will happily edit this thread with the proper way of doing things based on your feedback.

    That's it for now,
    stay safe, have fun creating games and I will see you in my next thread!
     
    Last edited: Jul 7, 2020
    Josh (Nology Games) likes this.
  2. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    Buildbox Setup 2.x.x
    • On your UI screen drag and drop a Navigation button
    • Set the Name to be Exit Button (name is important!
    • Set Function to Custom
    • Add your images save and export your game to Android.

    Check the red marks below:
    [​IMG]

    Android Studio Setup:
    • Open AdIntegrator class
    • [​IMG]
    • Scroll down until you see buttonActivated method
    • [​IMG]
    • Now here you must add the following lines of code just after the last if statement
    • If you got name defined in between brackets use this with the if statement
    • Code:
      if(name.contains("Exit Button")) {
          activity.finish();
          System.exit(0);
      }
    • [​IMG]
    • otherwise use this code
    • Code:
          activity.finish();
          System.exit(0);
      

    • [​IMG]
    • Save the project, deploy it to a telephone and enjoy your custom button.
    Congratulations you've just created your first custom exit button behavior on Buildbox 2


    Please let me know if you have any issues with the above tutorial.
    Also a video on how it works is greatly appreciated :)
     
    Last edited: Jul 8, 2020
  3. michel15

    michel15 Boxer

    Joined:
    Oct 8, 2015
    Messages:
    29
    Likes Received:
    5
    Hi @Vlad-NY
    Thanks for sharing this tutorial
    Could you please tell us which buildbox version are you using ?
    I have tried version 2.3.9 but I couldn't find the code in PTServicesBridge class
     
  4. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    The tutorial was made for BB3 I was using 3.2.3 version
     
  5. michel15

    michel15 Boxer

    Joined:
    Oct 8, 2015
    Messages:
    29
    Likes Received:
    5
    Have you tried to implement it on buildbox v2.3.9 ?
     
  6. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    I've updated my 2nd post with the setup for buildbox 2. For some reason on my export I have the name missing from
    buttonActivated meaning that you can't have multiple custom buttons that does multiple stuff since this method would be called every time you click on your custom button.

    If you guys have the name there please use it to create multiple behaviors based on your needs. As far as I know the iOS export might have the name there so you should be fine there.

    Stay safe, have fun, and see you soon!
     

Share This Page