简体   繁体   English

如何从活动返回上一个Webview页面

[英]How to return to previous webview page from an activity

I have a WebView and it will open another activity code in my Webview client 我有一个WebView ,它将在Webview客户端中打开另一个活动代码

if (Uri.parse(url).toString().contains(".mp3")) {

    Intent intent = new Intent(MainActivity.this,Download.class);
    intent.putExtra("Link",Uri.parse(url).toString());
    intent.putExtra("Link2",myWebview.getOriginalUrl().toString());

    startActivity(intent);
    finish();
}

Now As this intent extra will pass the value of the url from where the next Download.class is started 现在,由于此意图,额外的东西将从下一个Download.class开始的地方传递url的值。

what I need is on onBackPressed() it will open the url from where Download .class was opened 我需要的是onBackPressed() ,它将从Download .class位置打开URL。

This is my onBackPressed() code in Download.class 这是我在Download.class onBackPressed()代码

Intent i = new Intent(Download.this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();

Please refer bellow code code snippet. 请参阅下面的代码段。

    @Override
    public void onBackPressed() {
        if(webView.canGoBack()){
            webView.goBack();
        } else {
            super.onBackPressed();
        }
    }   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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