简体   繁体   中英

How to navigate to a HTML page from an ACTIVITY in android

I'm working in a webview and I'm successfully redirecting from home.html to MainActivity but I want to back go to home.html.

@Override
public void onBackPressed() {

}

public void logout(View view)
{
    SharedPreferences preferences = getSharedPreferences("myprefs", 0);
    if (preferences.contains("userphoto")) {
        SharedPreferences.Editor editor = preferences.edit();
        editor.remove("userphoto");
        editor.remove("userbg");
        editor.commit();

        finish();
    }
}

public void back(View view)
{
finish();
}

If you're looking to navigate through a webpage within the app, you can use a WebView . It makes it easier to navigate through the webpage and app seamlessly.

Here's an example solution: I would check if the user can go back using webView.canGoBack() and if so go back using webView.goBack() . Otherwise exit the activity with finish() .

@Override public void onBackPressed() {
    if (webView.canGoBack()) {
        webView.goBack();
        return;
    }
    finish();
}

Source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM