# Catching Back button on BluetoothMidiDevicePairingDialogue

**URL:** <https://forum.juce.com/t/catching-back-button-on-bluetoothmididevicepairingdialogue/67166>\
**Category:** Android\
**Created:** [September 17, 2025, 10:58am UTC](https://forum.juce.com/t/catching-back-button-on-bluetoothmididevicepairingdialogue/67166 "2025-09-17T10:58:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![swar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/swar/32/12935_2.png) [@swar](https://forum.juce.com/u/swar)\
**Post date:** [September 17, 2025, 10:58am UTC](https://forum.juce.com/t/catching-back-button-on-bluetoothmididevicepairingdialogue/67166/1 "2025-09-17T10:58:44Z")

</div>

I’m able to successfully connect Bluetooth MIDI controllers using BluetoothMidiDevicePairingDialogue::open(), but I’m so far unable to close the dialog elegantly, because Back button just closes the app, without passing through the back handles of my activity (works for everything else).

Clicking outside the table works just fine (table disappears), but Back button closes the app.

I have checked the DemoRunner app, and there it looks like the Back button disappears when the bluetooth dialog is displayed (that would also work).

Any help on this would be gladly appreciated.

---

<div class="post-metadata">

**Author:** ![ibisum](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ibisum/32/21288_2.png) [@ibisum](https://forum.juce.com/u/ibisum)\
**Post date:** [September 17, 2025, 11:01am UTC](https://forum.juce.com/t/catching-back-button-on-bluetoothmididevicepairingdialogue/67166/2 "2025-09-17T11:01:22Z")

</div>

Which platform? Android? iOS?

---

<div class="post-metadata">

**Author:** ![swar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/swar/32/12935_2.png) [@swar](https://forum.juce.com/u/swar)\
**Post date:** [September 17, 2025, 11:02am UTC](https://forum.juce.com/t/catching-back-button-on-bluetoothmididevicepairingdialogue/67166/3 "2025-09-17T11:02:00Z")

</div>

Android

---

<div class="post-metadata">

**Author:** ![ibisum](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ibisum/32/21288_2.png) [@ibisum](https://forum.juce.com/u/ibisum)\
**Post date:** [September 17, 2025, 11:43am UTC](https://forum.juce.com/t/catching-back-button-on-bluetoothmididevicepairingdialogue/67166/4 "2025-09-17T11:43:14Z")

</div>

Typically on Android whenever the Back button doesn’t behave as expected its related to the interaction between your Activity and whatever Fragments you may have implemented. Check that you have “ **app:defaultNavHost=“true”** “ set for your Fragments - otherwise the default activity behaviour will be wired up, which is to quit your app when the Back button is pressed.

EDIT: see if any of the solutions proposed here make an impact:

> <https://stackoverflow.com/questions/59078423/back-button-closes-app-instead-of-going-to-previous-fragment-android-navigation>

---

<div class="post-metadata">

**Author:** ![swar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/swar/32/12935_2.png) [@swar](https://forum.juce.com/u/swar)\
**Post date:** [September 17, 2025, 1:18pm UTC](https://forum.juce.com/t/catching-back-button-on-bluetoothmididevicepairingdialogue/67166/5 "2025-09-17T13:18:43Z")

</div>

I’m not using any Fragments in my app, apart from the ones used in JUCE code in the background.

If it can help, I’m getting the following call-stack when placing a breakpoint on my app’s activity finish() method:

finish(), (com.swarsystems.myapp)  
handleBackButton:-1, ComponentPeerView (com.rmsl.juce)  
backButtonPressed:405, ComponentPeerView (com.rmsl.juce)  
onKeyDown:426, ComponentPeerView (com.rmsl.juce)

Also I’m on JUCE 7.0.9

---

<div class="post-metadata">

**Author:** ![swar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/swar/32/12935_2.png) [@swar](https://forum.juce.com/u/swar)\
**Post date:** [September 17, 2025, 3:14pm UTC](https://forum.juce.com/t/catching-back-button-on-bluetoothmididevicepairingdialogue/67166/6 "2025-09-17T15:14:48Z")

</div>

It seems the issue is in juce\_Windowing\_android.cpp, in the handleBackButtonCallback() we try to branch to the JUCEApplicationBase backButtonPressed() method. In my case, JUCEApplicationBase::getInstance() returns NULL (I don’t think I declared that in my code).

Should an Android app have a JUCEApplicationBase instance, and if so, how to declare it?

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [September 17, 2025, 5:36pm UTC](https://forum.juce.com/t/catching-back-button-on-bluetoothmididevicepairingdialogue/67166/7 "2025-09-17T17:36:57Z")

</div>

If you have a C++/JUCE app from the ground up - where you inherit `JUCEApplication` and fill out the functions to suit your needs, then call `START_JUCE_APPLICATION` - your app instance should not be null.

Otherwise, if you’re simply calling `ScopedJuceInitialiser_GUI` somewhere, this is probably a weird grey area…

You’ll have to provide more context about your project so we can help you.

---

<div class="post-metadata">

**Author:** ![swar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/swar/32/12935_2.png) [@swar](https://forum.juce.com/u/swar)\
**Post date:** [September 18, 2025, 8:47am UTC](https://forum.juce.com/t/catching-back-button-on-bluetoothmididevicepairingdialogue/67166/8 "2025-09-18T08:47:39Z")

</div>

The app was buit over 15 years back, I think, so I don’t think it follows any of the 2 options you mentioned. I starts as a normal Android app in the Java activity, then calls a native method constructNativeClass to build the native activity that gives access to all JUCE cpp code.

---

<div class="post-metadata">

**Author:** ![ibisum](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ibisum/32/21288_2.png) [@ibisum](https://forum.juce.com/u/ibisum)\
**Post date:** [September 18, 2025, 8:49am UTC](https://forum.juce.com/t/catching-back-button-on-bluetoothmididevicepairingdialogue/67166/9 "2025-09-18T08:49:13Z")

</div>

Your issue is that the JUCEApplication instance is null. Work back from that.

---

<div class="post-metadata">

**Author:** ![swar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/swar/32/12935_2.png) [@swar](https://forum.juce.com/u/swar)\
**Post date:** [September 19, 2025, 8:06am UTC](https://forum.juce.com/t/catching-back-button-on-bluetoothmididevicepairingdialogue/67166/10 "2025-09-19T08:06:50Z")

</div>

Yeah, it looks like this could be solved by instantiating a JUCEApplication. However, since the app is quite complex and works perfectly the way I described above, I’ll have to find out how to do that, so it doesn’t disturb the current flow.
