java - Android - 使用 webView 将 url 从 Activity 1 发送到 Activity 2

标签 java android mobile webview

我有我的项目here如果有人想看。

所以我想单击 activity1 上的图像(它将保留链接),然后使用将打开该链接的 webview 转到第二个 Activity 。我怎么做? 这是我当前的代码,但是当我点击图片时应用程序崩溃了:

//Activity1.java

 public void onClick(View view)
    {       
        Bundle bundle = new Bundle();
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        Intent act2 = new Intent(view.getContext(), Activity2.class);

        String url = "http://www.google.com";
        bundle.putString("urlString", url);
        intent.putExtras(bundle);
        startActivity(act2);
    }

activity2.java:

//Activity2.java

   //OnCreate
    String url = super.getIntent().getExtras().getString("urlString");
    mWebView = (WebView) findViewById(R.id.webView1);
    mWebView.loadUrl(url);

  private void load(String url)
  {
      mWebView = (WebView) findViewById(R.id.webView1);
      mWebView.setWebViewClient(new WebViewClient());
      mWebView.loadUrl(url);
  } 

随时查看整个代码 here 提前谢谢你。

最佳答案

  ImageView img = (ImageView)findViewById(R.id.imageView1);
    img.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View view)
        {       

            Intent intent = new Intent(Activity1.this,Activity2.class);
            intent.putExtra("urlString", "http://www.google.com");
            startActivity(intent);
        }
    });

    String url = getIntent().getExtras().getString("urlString");
    mWebView = (WebView) findViewById(R.id.webView1);
    mWebView.loadUrl(url);

关于java - Android - 使用 webView 将 url 从 Activity 1 发送到 Activity 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25661381/

相关文章:

java - LWJGL 和 Slick2D 64 位

java - 使用 rjb 将 ruby​​ hash 转为 java hashmap

java - 关闭查询后获取耶拿结果集 - 用于模块化

windows - 2D 跨平台游戏开发引擎

java - 如何将 pom.xml 添加到现有的 Eclipse 项目?

android - React Native 自定义字体适用于 IOS 但不适用于 Android

java - Room 如何验证数据完整性?数据库版本/哈希存储在哪里?

SomeClass.class 的 Java 语法

html - 媒体查询在第二个文件中无法在移动设备上运行

css - 我可以在没有设备像素比的情况下使用最大设备宽度和设备宽度吗?