[android]Back = Exit game problem

I am referring to this post here:

http://forums.rpgmakerweb.com/index.php?/topic/47780-androidios-tldr-converting-your-project-using-the-manual-method/page-2#entry503435

I have searched around this forum and I still couldn't find the answer (might have been oversight but well....)

So yeah,

If you (accidentally) press the back button during your RMMV gaming session, OR if a program force you to tend to it during your gaming session, you will exit the game.

That will be shocking to some players and I wonder if there is any work around to that.

Thanks for at least reading.
This is really a problem, because android user are used to use the back button as a way to navigate backwards in the menu.

This is only a temporary fix.

If you build your apk file with crosswalks: Navigate to your crosswalks folder there should be a folder inside called "template".

Open it and navigate to: "template\src\org\xwalk\app\template" and open the file "AppTemplateActivity.java" with a text editor.

at the end just before the very last "}" add:

@Overridepublic void onBackPressed() { // Do nothing}Save and done!

Now when you build your apk, the back button does nothing.

This is not a good solution, maybe I work on it some other time.
This is really a problem, because android user are used to use the back button as a way to navigate backwards in the menu.

This is only a temporary fix.

If you build your apk file with crosswalks: Navigate to your crosswalks folder there should be a folder inside called "template".

Open it and navigate to: "template\src\org\xwalk\app\template" and open the file "AppTemplateActivity.java" with a text editor.

at the end just before the very last "}" add:

@Overridepublic void onBackPressed() { // Do nothing}Save and done!Now when you build your apk, the back button does nothing.

This is not a good solution, maybe I work on it some other time.
Hi,

I just read your answer and well...not the best ssolution but at least it ia better than restarting the game....

Now what about those apps forcing themselves onto you when you are in gaming session, will this work on them too?
Now what about those apps forcing themselves onto you when you are in gaming session, will this work on them too?
I'm not sure what you mean by that, do apps open on their own? Push the game (while) you play into the background?
I'm not sure what you mean by that, do apps open on their own? Push the game (while) you play into the background?
It sometimes happens.

Example.

You run an app, and then you open another app without closing that previous app. After sometime you may forget and run RMMV APK, and then suddenly that apk that you forget to close needs something urgent from you, and it forcefully pushes whatever you are on into background. Once you are back to your RMMV APK, the game restarts.

I don't know if my explanation good enough. Hope you understand me.
Now I know what you mean. But I never experienced it before, but I take a look at it.

Adding some function to back button:

This will show a window that asks: ""

You can click "yes" or "no", this is better then doing nothing.

This is the modified "AppTemplateActivity.java" file from "crosswalk-15.44.384.12" (I'm not sure if I'm allowed to post it, so I post what I add only, should work with other versions of course).

1. Add these two lines to the other imports at the top:

import android.app.AlertDialog;import android.content.DialogInterface;2. add this at the end (before the very last "}"):

Code:
// create a function that creates an alert window and displays it    public void openDialog(View view)    {        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);        alertDialogBuilder.setMessage("Are you sure, you want to close the game.");        alertDialogBuilder.setTitle("Warning");        alertDialogBuilder.setPositiveButton("yes", new DialogInterface.OnClickListener()        {            @Override            public void onClick(DialogInterface arg0, int arg1)            {                // close the app                finish();            }        });        alertDialogBuilder.setNegativeButton("no",new DialogInterface.OnClickListener()        {            @Override            public void onClick(DialogInterface dialog, int which)            {                // do nothing            }        });        AlertDialog alertDialog = alertDialogBuilder.create();        alertDialog.show();    }    // Override back button to prevent closing the app    // this is the same as before, but with a function call	@Override	public void onBackPressed() {		 //super.onBackPressed();         // Call openDialog         openDialog(this.findViewById(0));	}
Now I know what you mean. But I never experienced it before, but I take a look at it.

Adding some function to back button:

This will show a window that asks: ""

You can click "yes" or "no", this is better then doing nothing.

This is the modified "AppTemplateActivity.java" file from "crosswalk-15.44.384.12" (I'm not sure if I'm allowed to post it, so I post what I add only, should work with other versions of course).

1. Add these two lines to the other imports at the top:

import android.app.AlertDialog;import android.content.DialogInterface;2. add this at the end (before the very last "}"):

// create a function that creates an alert window and displays it public void openDialog(View view) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setMessage("Are you sure, you want to close the game."); alertDialogBuilder.setTitle("Warning"); alertDialogBuilder.setPositiveButton("yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // close the app finish(); } }); alertDialogBuilder.setNegativeButton("no",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // do nothing } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } // Override back button to prevent closing the app // this is the same as before, but with a function call @Override public void onBackPressed() { //super.onBackPressed(); // Call openDialog openDialog(this.findViewById(0)); }
thnx so much for the very great tip! you saved me. 🙂

only.. the second tip didn't work for me.

the first tip doing nothing solution works fine when I tested it in mobile thnk god.

 but in the second tip about alerting yes or no script,

I  added the written lines  before the last" { "   just like the first one and command prompt says "BUILD FAILED" about reading this file.

how can I do this? could you show me a little more specific info?   entired fixed AppTemplateActivity.java file will be very helpful. or explanation is great too.

I'd really love to put the yes or no button!
Since the BSD-style license allows me to post the complete code of the "AppTemplateActivity.java" file, I will post it here.

So here is how the complete code should look like:

Spoiler
Code:
// Copyright (c) 2013 Intel Corporation. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.package org.xwalk.app.template;import android.app.AlertDialog;import android.content.DialogInterface;import android.graphics.Color;import android.os.Build;import android.os.Bundle;import android.util.Log;import android.view.Window;import android.view.WindowManager;import android.view.View;import android.widget.TextView;import org.xwalk.app.XWalkRuntimeActivityBase;public class AppTemplateActivity extends XWalkRuntimeActivityBase {    private final int SYSTEM_UI_OPTIONS = View.SYSTEM_UI_FLAG_LAYOUT_STABLE |            View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |            View.SYSTEM_UI_FLAG_FULLSCREEN |            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;    private final String TAG = this.getClass().getName();    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);    }    @Override    public void onResume() {        super.onResume();        enterFullscreen();    }    @Override    protected void didTryLoadRuntimeView(View runtimeView) {        if (runtimeView != null) {            getRuntimeView().loadAppFromUrl("file:///android_asset/www/index.html");        } else {            TextView msgText = new TextView(this);            msgText.setText("Crosswalk failed to initialize.");            msgText.setTextSize(36);            msgText.setTextColor(Color.BLACK);            setContentView(msgText);        }    }    private void enterFullscreen() {        if (isNewerThanKitkat() && ((getWindow().getAttributes().flags &                WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0)) {            View decorView = getWindow().getDecorView();            decorView.setSystemUiVisibility(SYSTEM_UI_OPTIONS);        }    }    public void setIsFullscreen(boolean isFullscreen) {        if (!isFullscreen) return;        if (!isNewerThanKitkat()) {            Log.w(TAG, "setIsFullscreen() should not be called if " +                    "android version is older than Kitkat.");            return;        }        setSystemUiVisibilityChangeListener();    }    private void setSystemUiVisibilityChangeListener() {        final View decorView = getWindow().getDecorView();        decorView.setOnSystemUiVisibilityChangeListener(            new View.OnSystemUiVisibilityChangeListener() {                @Override                public void onSystemUiVisibilityChange(int visibility) {                    if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {                        decorView.setSystemUiVisibility(SYSTEM_UI_OPTIONS);                    }                }            }        );    }    private boolean isNewerThanKitkat() {        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;    }	    // create a function that creates an alert window and displays it    public void openDialog(View view)    {        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);        alertDialogBuilder.setMessage("Are you sure, you want to close the game.");        alertDialogBuilder.setTitle("Warning");        alertDialogBuilder.setPositiveButton("yes", new DialogInterface.OnClickListener()        {            @Override            public void onClick(DialogInterface arg0, int arg1)            {                // close the app                finish();            }        });        alertDialogBuilder.setNegativeButton("no",new DialogInterface.OnClickListener()        {            @Override            public void onClick(DialogInterface dialog, int which)            {                // do nothing            }        });        AlertDialog alertDialog = alertDialogBuilder.create();        alertDialog.show();    }    // Override back button to prevent closing the app	@Override	public void onBackPressed() {		 //super.onBackPressed();         // Call openDialog         openDialog(this.findViewById(0));	}}
Hello,

I'm working for a mobile game with RpgMakerMv, and I searching, in google, line of command for BackButton, in Mobile (Android), but i have don't find this.

I need your help please.

I need the line of command for open the menu and cancel input for Android:

Scene_Map.prototype.isMenuCalled = function() {
return Input.isTriggered('menu') || TouchInput.isCancelled() || TouchInput.onBackPressed();
};


Window_Selectable.prototype.processTouch = function() {
if (this.isOpenAndActive()) {
if (TouchInput.isTriggered() && this.isTouchedInsideFrame()) {
this._touching = true;
this.onTouch(true);
} else if (TouchInput.isCancelled() || TouchInput.onBackPressed()) {
if (this.isCancelEnabled()) {
this.processCancel();
}
}
if (this._touching) {
if (TouchInput.isPressed()) {
this.onTouch(false);
} else {
this._touching = false;
}
}
} else {
this._touching = false;
}
};


Thanks and sorry for my english.

Rastos, please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.



Start your own thread instead, as this post is unrelated to what is discussed in that thread.

Original thread: https://forums.rpgmakerweb.com/threads/android-back-exit-game-problem.51460/