MV Is there any way to remove the game refresh for android?

Is there any way to remove the game refresh for android?

I am currently doing tests of my game on android and noticed that sometimes it restarts randomly.

I did a test with a controller and when I turn off the controller the game restarts...😅

I saw that someone made a plugin that disables the F5, but on android obviously, this does not work...
It may be a problem with some Plugin:
  1. What version of your Android?
  2. What version of WebView (Android -> Apps)?
  3. What Plugins are you using in your game?
  4. Tried to create a simple game with nothing and compile to APK?
Spoiler: It is worth mentioning:
The way that most RpgMV / MZ users create the project (Android Studio) to compile (APK) is based on the manual, but it is not necessarily the only way to do this.

Good Luck
It may be a problem with some Plugin:
  1. What version of your Android?
  2. What version of WebView (Android -> Apps)?
  3. What Plugins are you using in your game?
  4. Tried to create a simple game with nothing and compile to APK?
Spoiler: It is worth mentioning:
The way that most RpgMV / MZ users create the project (Android Studio) to compile (APK) is based on the manual, but it is not necessarily the only way to do this.

Good Luck
Thanks.

1. Android 10
2. 83.0.4103.101
3. A lot of plugins.(Yanfly,Moghunter,HIME...)
4. I have not done this yet, but I downloaded an RPG maker game from playstore, and the same thing happened so it must be something from my android or it must have something to do with the controller I use to play.

I just wanted to find a way to disable the refresh.
If it is a key called "Page refresh", it is native to the application's mini-browser. Therefore, predicting the F5 key will not work, as it is not the same key, it should be something like this:
JavaScript:
location.reload(); //reload page

Try to put this right in the index.html
I'm away from my computer and Rpg Maker now.
JavaScript:
window.onbeforeunload = function(){
   return "You cannot refresh the page";
}
Thanks for helping me.
JavaScript:
window.onbeforeunload = function(){
return "You cannot refresh the page";
}

I added this code to index.html

A confirmation window appears on the computer to restart the game.

On android it simply ignores it.
So, only if we find out what is the key event in your controller that reloads the page.

So we can use:
event.preventDefault();

You can find out what the event is if you can install the controller on your computer.
So, only if we find out what is the key event in your controller that reloads the page.

So we can use:
event.preventDefault();

You can find out what the event is if you can install the controller on your computer.
From my tests, always when I disconnect and connect the controller from the smartphone the game restarts.
Please tell the make and model of the device.
Please tell the make and model of the device.
I am using a Xiaomi Poco x3
CPU- Qualcomm SM7150-AC Snapdragon 732G,GPU- Adreno 618, 6 GB Ram.
I did a test with Xiaomi note 7 with the controller happened the same thing.
Sorry, I was referring to the control model, why events happen because of it.

Try modifying the APK:

Feedback please:
You can find out what the event is if you can install the controller on your computer.
Sorry, I was referring to the control model, why events happen because of it.

Try modifying the APK:

Feedback please:
Ah sorry...

Ipega 9076.

I will try to modify the apk.

On the computer, nothing happened.
I am thinking of a theory of the cause of the problem.
I think Android (WebView) automatically restarts the page when connecting / disconnecting, to ensure that the command system has been changed.
Perhaps the same can happen when you connect a mouse via USB with "USB-OTG".

Test other games made in RpgMV:
https://play.google.com/store/search?q=rpg maker mv&c=apps
I am thinking of a theory of the cause of the problem.
I think Android (WebView) automatically restarts the page when connecting / disconnecting, to ensure that the command system has been changed.
Perhaps the same can happen when you connect a mouse via USB with "USB-OTG".

Test other games made in RpgMV:
https://play.google.com/store/search?q=rpg maker mv&c=apps
Yes, it happens in all the other games I tested.😅

So there's not much to do...

Since it happens to everyone.
Have you ever done the test by running the game on a browser on your smartphone?
(Via HTTP)
Have you ever done the test by running the game on a browser on your smartphone?
(Via HTTP)
Yes.

Interesting, even in the browser it resets.LZYskeptic
That's what I thought, the problem must not be in control, it must be in the "plug & play" system.
The fact is that I searched the internet and found nothing about it.
There is no way to be absolutely sure, you have to test all the possibilities, which is not so easy:
  • Place a USB mouse to see if the same happens
  • Place a controller from another brand
  • Test on an older android, preferably 5.0 (Loolip)
Anyway, I wish you the best of luck.
That's what I thought, the problem must not be in control, it must be in the "plug & play" system.
The fact is that I searched the internet and found nothing about it.
There is no way to be absolutely sure, you have to test all the possibilities, which is not so easy:
  • Place a USB mouse to see if the same happens
  • Place a control from another brand
  • Test on an older android, preferably 5.0 (Loolip)
Anyway, I wish you the best of luck.
Thanks for helping me. I will do more tests soon.
I ended up getting some time to create a test code with Javascript. It blocks any key, except the ones used in games made with Rpg MV.

If it does not work then it is sure that it is something in WebView.

Spoiler: Source code:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Only - RpgMV Keys</title>
<script>
var know, nowkey, MVkey, mytimer, counter;

window.onload=function(){
   nowkey=document.getElementById("nowkey");
   MVkey=document.getElementById("MVkey");
   mytimer=document.getElementById("mytimer");
   counter=0;
   setInterval(function(){counter++;mytimer.innerHTML="Timer: "+counter}, 1000);
}
document.onkeydown=function(e){
   nowkey.innerHTML="Key: ["+e.key+"]";
   if(
      e.key != "ArrowLeft" && e.key.code != "ArrowLeft" &&
      e.key != "ArrowUp" && e.key.code != "ArrowUp" &&
      e.key != "ArrowRight" && e.key.code != "ArrowRight" &&
      e.key != "ArrowDown" && e.key.code != "ArrowDown" &&

      e.key != "Left" &&
      e.key != "Up" &&
      e.key != "Right" &&
      e.key != "Down" &&

      e.key != "Enter" && e.key.code != "Enter" &&
      e.key != "Z" && e.key.code != "KeyZ" &&
      e.key != " " && e.key.code != "Space" &&
      e.key != "Enter" &&
      e.key != "Spacebar" &&

      e.key != "Escape" && e.key.code != "Escape" &&
      e.key != "X" && e.key.code != "KeyX" &&
      e.key != "0" && e.key.code != "Numpad0" &&
      e.key != "Esc" &&

      e.key != "8" && e.key.code != "Numpad8" &&
      e.key != "6" && e.key.code != "Numpad6" &&
      e.key != "2" && e.key.code != "Numpad2" &&
      e.key != "4" && e.key.code != "Numpad4" &&

      e.key != "PageUp" && e.key.code != "PageUp" &&
      e.key != "PageDown" && e.key.code != "PageDown"
   ){
      e.preventDefault();
      return false;
   }else{
      MVkey.innerHTML="MV-Key: ["+e.key+"]";
   }
}
</script>
</head>
<body>
<pre id="nowkey">Key: [false]</pre>
<pre id="MVkey">MV-Key: [false]</pre>
<pre id="mytimer">Timer: 0</pre>
</body>
</html>
I ended up getting some time to create a test code with Javascript. It blocks any key, except the ones used in games made with Rpg MV.

If it does not work then it is sure that it is something in WebView.

Spoiler: Source code:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Only - RpgMV Keys</title>
<script>
var know, nowkey, MVkey, mytimer, counter;

window.onload=function(){
   nowkey=document.getElementById("nowkey");
   MVkey=document.getElementById("MVkey");
   mytimer=document.getElementById("mytimer");
   counter=0;
   setInterval(function(){counter++;mytimer.innerHTML="Timer: "+counter}, 1000);
}
document.onkeydown=function(e){
   nowkey.innerHTML="Key: ["+e.key+"]";
   if(
      e.key != "ArrowLeft" && e.key.code != "ArrowLeft" &&
      e.key != "ArrowUp" && e.key.code != "ArrowUp" &&
      e.key != "ArrowRight" && e.key.code != "ArrowRight" &&
      e.key != "ArrowDown" && e.key.code != "ArrowDown" &&

      e.key != "Left" &&
      e.key != "Up" &&
      e.key != "Right" &&
      e.key != "Down" &&

      e.key != "Enter" && e.key.code != "Enter" &&
      e.key != "Z" && e.key.code != "KeyZ" &&
      e.key != " " && e.key.code != "Space" &&
      e.key != "Enter" &&
      e.key != "Spacebar" &&

      e.key != "Escape" && e.key.code != "Escape" &&
      e.key != "X" && e.key.code != "KeyX" &&
      e.key != "0" && e.key.code != "Numpad0" &&
      e.key != "Esc" &&

      e.key != "8" && e.key.code != "Numpad8" &&
      e.key != "6" && e.key.code != "Numpad6" &&
      e.key != "2" && e.key.code != "Numpad2" &&
      e.key != "4" && e.key.code != "Numpad4" &&

      e.key != "PageUp" && e.key.code != "PageUp" &&
      e.key != "PageDown" && e.key.code != "PageDown"
   ){
      e.preventDefault();
      return false;
   }else{
      MVkey.innerHTML="MV-Key: ["+e.key+"]";
   }
}
</script>
</head>
<body>
<pre id="nowkey">Key: [false]</pre>
<pre id="MVkey">MV-Key: [false]</pre>
<pre id="mytimer">Timer: 0</pre>
</body>
</html>
Thanks, I will test it.
I ended up getting some time to create a test code with Javascript. It blocks any key, except the ones used in games made with Rpg MV.

If it does not work then it is sure that it is something in WebView.

Spoiler: Source code:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Only - RpgMV Keys</title>
<script>
var know, nowkey, MVkey, mytimer, counter;

window.onload=function(){
   nowkey=document.getElementById("nowkey");
   MVkey=document.getElementById("MVkey");
   mytimer=document.getElementById("mytimer");
   counter=0;
   setInterval(function(){counter++;mytimer.innerHTML="Timer: "+counter}, 1000);
}
document.onkeydown=function(e){
   nowkey.innerHTML="Key: ["+e.key+"]";
   if(
      e.key != "ArrowLeft" && e.key.code != "ArrowLeft" &&
      e.key != "ArrowUp" && e.key.code != "ArrowUp" &&
      e.key != "ArrowRight" && e.key.code != "ArrowRight" &&
      e.key != "ArrowDown" && e.key.code != "ArrowDown" &&

      e.key != "Left" &&
      e.key != "Up" &&
      e.key != "Right" &&
      e.key != "Down" &&

      e.key != "Enter" && e.key.code != "Enter" &&
      e.key != "Z" && e.key.code != "KeyZ" &&
      e.key != " " && e.key.code != "Space" &&
      e.key != "Enter" &&
      e.key != "Spacebar" &&

      e.key != "Escape" && e.key.code != "Escape" &&
      e.key != "X" && e.key.code != "KeyX" &&
      e.key != "0" && e.key.code != "Numpad0" &&
      e.key != "Esc" &&

      e.key != "8" && e.key.code != "Numpad8" &&
      e.key != "6" && e.key.code != "Numpad6" &&
      e.key != "2" && e.key.code != "Numpad2" &&
      e.key != "4" && e.key.code != "Numpad4" &&

      e.key != "PageUp" && e.key.code != "PageUp" &&
      e.key != "PageDown" && e.key.code != "PageDown"
   ){
      e.preventDefault();
      return false;
   }else{
      MVkey.innerHTML="MV-Key: ["+e.key+"]";
   }
}
</script>
</head>
<body>
<pre id="nowkey">Key: [false]</pre>
<pre id="MVkey">MV-Key: [false]</pre>
<pre id="mytimer">Timer: 0</pre>
</body>
</html>
I don't know if I did it right.

Was I supposed to add it to the index.html?

I tested it and it didn't work.;_;

I noticed that if I disconnect and connect the controller while I use a browser, the browser restarts too.

Original thread: https://forums.rpgmakerweb.com/threads/is-there-any-way-to-remove-the-game-refresh-for-android.135206/