[android]Back = Exit game problem

Status
Not open for further replies.

metronome

Veteran
Veteran
Joined
Aug 21, 2014
Messages
338
Reaction score
144
First Language
English (Sure!)
Primarily Uses
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.
 

Tagflag

Villager
Member
Joined
Nov 29, 2015
Messages
16
Reaction score
6
First Language
German
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.
 

metronome

Veteran
Veteran
Joined
Aug 21, 2014
Messages
338
Reaction score
144
First Language
English (Sure!)
Primarily Uses
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?
 

Tagflag

Villager
Member
Joined
Nov 29, 2015
Messages
16
Reaction score
6
First Language
German
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?
 

metronome

Veteran
Veteran
Joined
Aug 21, 2014
Messages
338
Reaction score
144
First Language
English (Sure!)
Primarily Uses
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.
 

Tagflag

Villager
Member
Joined
Nov 29, 2015
Messages
16
Reaction score
6
First Language
German
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));	}
 

yongilcool

Veteran
Veteran
Joined
Nov 7, 2014
Messages
60
Reaction score
10
First Language
English
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!
 

Tagflag

Villager
Member
Joined
Nov 29, 2015
Messages
16
Reaction score
6
First Language
German
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:

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));	}}
 
Last edited by a moderator:

PesadeloDoEspantalho

Blood Cloud Studio
Veteran
Joined
May 5, 2016
Messages
32
Reaction score
40
First Language
French
Primarily Uses
RMMV
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.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA

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.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,981
Members
137,563
Latest member
cexojow
Top