Start a new topic

Back button issue

Back button issue


I have modified the back button function in the native already. It is okay when it is in AR view.

However, after closing the AR view and back to the phonegap view, the back button is not handled by natvice code, even I added back the event listen for back button, it still doesn't work.

Any ideas? Thanks.

Hi,
I don't know if i understand your problem correctly, but the swipe gesture from the left edge is impl. in the Wikitude PhoneGap plugin and will only work on the AR view and not on any other view.

If this is not the answer to your question, please rephrase it so that it is more clear what your question is.

Best regards

Andreas

Hi,

This question is not about the swipe problem. 

On Android, the back button is overrided by your native code (wikitude.java). When under the AR view, everything fine.
I have modified the back button action in the native code. Asking "confirm to exit" when press back button.

However, when I hide or close the AR view and back to phonegap view, and press the back button again, no action fired. The application closed without any confirmation. 

Any idea I have solve this problem?

So this is a Android specific problem? If so, I would have to forward the problem to our Android team.

 

Best regards

Andreas

Of course. There is a back button on Android only. There is no back button on iPhone.

^^

Hi,

if I understood correctly, this is not an issue with Wikitude SDK or with the plugin, but rather a general problem with back button handling in PhoneGap.

This seems to be a common problem, since PhoneGap is cross-platform, and not every platform has a back button.

A possible solution (for PhoneGap 3.3 or higher) is explained in this post: http://stackoverflow.com/a/22276292/113644.

If I added the listener document.addEventListener("backbutton"..... , the application will be crashed.

As the back button is handled in the WikitudePlugin.java (Around line 586).

I have modified this area, a confirmation window will be popup when under AR-view. However, after I close the AR view and back to Phonegap view. It seems the back button is not handled by WikitudePlugin.java anymore. 

Even I add back the listener document.addEventListener("backbutton"....., the event of back button is still not fired.

 

 

The problem is that the code in WikitudePlugin.java only works inside the AR view.

I'm trying to reproduce the problem but I need another piece of information: when you say you tried to add a listener in Javascript, do you mean in the PhoneGap HTML or in the HTML source of your AR-World?

Our plugin sample app already has a function "onBackButton", which disables the back button handler when the AR View is closed. You could try using that to add your handler after removing the default.

The code is in "index.js" of the sample application, line 106.

in the /www/js/index.js.

    onDeviceReady: function() {

document.addEventListener("backbutton", onBackKeyDown, false);

function onBackKeyDown() {

alert('back');

return false;

}

 

        app.receivedEvent('deviceready');

        app.wikitudePlugin = cordova.require("com.wikitude.phonegap.WikitudePlugin.WikitudePlugin");

        app.wikitudePlugin.isDeviceSupported(app.onDeviceSupportedCallback, app.onDeviceNotSupportedCallback);

    },

 

If I comment the 2 lines app.wikitudePlugin, there is no problem on the event listener for back button.

However, if not comment out the 2 lines, then the event listener does't work anymore.

Even I try to override the back button after calling "app.wikitudePlugin.hide();", the event listener also not fired.

 

If the application is closed with this situation, pressing back button when it is under Phonegap view, then the camera will not be released. Other application can't use the camera anymore.

 

Any ideas?

 

Hi Frederick,
Thank you very much for sharing your information with us. Hopefully some other forum guests can use your findings to get there app working.

 

Best regards

Andreas

Find out what happened. For other users reference.

Android 4.0.x, PhoneGap can't be overrided the Back button event. Therefore, the application will be closed.

Solution : Override the back button in the CordovaActivity

    @Override

    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK) {

            //do whatever you need for the hardware 'back' button

        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());

   builder

.setTitle("Title")

.setMessage("exit?")

.setCancelable(false)

.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

          public void onClick(DialogInterface dialog, int id) {

               //YourActivity.super.onBackPressed;

          System.exit(1);

          }

})

.setNegativeButton("No", new DialogInterface.OnClickListener() {

      public void onClick(DialogInterface dialog, int id) {

           dialog.cancel();

      }

})

      .show();

            return true;

        }

        return super.onKeyDown(keyCode, event);

 

    }

 

Other Android versions, PhoneGap can override the back button.
Login or Signup to post a comment