1

please help me..

how to prevent users back to the local page page.?

coz file://android_asset/index.html I am setting to the main page in app with a script meta refresh, script auto load to my main web (using wordpress). I do this so that when the application is opened not too heavy or too long

the problem now. when I press the Back button, even back to the page localpage, well how to avoid user can press the back button?

I’ve tried using javascript but it did not work (though javascript on)

Help me, I’ve run out of ideas confused does not know how

creat15
  • 165
  • 1
  • 2
  • 12

3 Answers3

0

You can override the back button so it will do nothing

  @Override
public void onBackPressed() {
}

This works for API level 5 or higher so it must work fine

Slye
  • 198
  • 2
  • 13
  • Sorry, the script was put where? if a script it could to block users from accessing back localpage? What in place the assets in the folder? – creat15 Feb 23 '17 at 14:53
0

Try overriding onBackPressed() and writing nothin inside it as follows: @Override public void onBackPressed() { }

Let me know if it works!!

Saarang Tiwari
  • 291
  • 2
  • 12
  • sorry the code is placed where? in the asset folder? I ask simply can not go back to the page localpage only not in all app, because I localpage first opening in the app settings – creat15 Feb 23 '17 at 14:59
  • `onBackPressed()` is placed in the activity that extends Activity. Which has `onCreate()`. Refer this [link](https://developer.android.com/reference/android/app/Activity.html#onBackPressed()) – Saarang Tiwari Feb 23 '17 at 15:01
  • sorry i mean like this, when the application is opened. local pages first appeared, please how to prevent the user back to the local page when they hit the back button – creat15 Feb 23 '17 at 15:17
  • Ohh alright. So the application is loading local pages first, that means these pages are offline. Well in this case I don't think we can do anything from android. But we can change that using java script on website. Refer following [link] (https://www.irt.org/script/311.htm) or try writing `window.onbeforeunload = function() { return "You work will be lost."; };` in the webpage from where you would like your users to not go back. – Saarang Tiwari Feb 23 '17 at 15:26
  • thanks for reply. I've tried using javascript but can not function in the application. whereas javascript on / enable / active in his studio script android – creat15 Feb 23 '17 at 15:32
  • There is a way of using javascript in Android application, refer this [Solution on Stackoverflow](http://stackoverflow.com/a/9432330/7026592) – Saarang Tiwari Feb 23 '17 at 15:47
  • I think you must be using webview to load the HTML page . Then there is a way to disable the navigation in webview as well. For the refer [link](https://www.google.co.in/amp/s/mytechead.wordpress.com/2014/02/24/android-webview-enable-disable-navigation-buttons/amp/) – Saarang Tiwari Feb 23 '17 at 16:08
0

Just remove super.onBackPressed();

@Override
public void onBackPressed() {
  //  super.onBackPressed();
// dont call **super**, if u want disable back button in current screen.
}
mihir raj
  • 156
  • 5
  • sorry, if I remove super.onBackPressed (); or it will not completely go back to the previous page. I ask simply can not go back to the page localpage only not in all app, because I localpage first opening in the app settings – creat15 Feb 23 '17 at 14:58
  • So when your application starts local page will be the first one to be displayed ? – mihir raj Feb 23 '17 at 15:04
  • yeah right, when the application is opened. local pages first appeared, please how to prevent the user back to the local page when they hit the back button – creat15 Feb 23 '17 at 15:11
  • you dont want user to get back on local page right ? but from which page ? – mihir raj Feb 23 '17 at 15:31
  • thanks for reply, yeah right, I want to prevent the user to not re-access the page localpage. coz localpage i setting like a splash screen – creat15 Feb 23 '17 at 15:37