Geckoview cangoback equivalent of android webview.canGoBack How can i use canGoBack on GeckoView? below is sample default android webview canGoBack implemention canGoBack public void onBackPressed if webView.canGoBack webView.goBack; else super.onBackPre
How can i use canGoBack() on GeckoView?
below is sample default android webview canGoBack()
implemention
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}
on geckoview
You need to set a navigation delegate on the gecko session and use a global boolean to keep track of whether it can go back or not.
Java
private boolean canGoBack = false;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
session.setNavigationDelegate(new GeckoSession.NavigationDelegate() {
@Override
public void onCanGoBack(@NonNull GeckoSession session, boolean canGoBack) {
MainActivity.this.canGoBack = canGoBack;
}
});
}
}
Kotlin
session.navigationDelegate = object : NavigationDelegate {
override fun onCanGoBack(session: GeckoSession, canGoBack: Boolean) {
// equivalent of webview.canGoBack
this@MainActivity.canGoBack = canGoBack
}
}