Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java webview从另一个类中的输入文本加载url_Java_Android_Android Studio_Webview - Fatal编程技术网

Java webview从另一个类中的输入文本加载url

Java webview从另一个类中的输入文本加载url,java,android,android-studio,webview,Java,Android,Android Studio,Webview,我有两个类,MainActivity和InputAddress,如何从类InputAddress加载url view.loadUrl("here, im confused"); 从InputAddress发送数据 Intent intent = new Intent(getBaseContext(), SignoutActivity.class); intent.putExtra("url", YOUR_EDIT_TEXT.getText().toString()); startActivit

我有两个类,MainActivity和InputAddress,如何从类InputAddress加载url

view.loadUrl("here, im confused");

从InputAddress发送数据

Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("url", YOUR_EDIT_TEXT.getText().toString());
startActivity(intent);
在MainActivity中接收数据

String s = getIntent().getStringExtra("url");
然后加载到webview

view.loadUrl(s);

您可以像这样添加公共静态变量:

public class InputAddress {
  public static String address = "abc";
}
public class MainActivity {
  // ...
  public void onCreate(....) {
    Log.d("TAG", InputAddress.address);
  }
}
然后您可以访问MainActivity中的address变量,如下所示:

public class InputAddress {
  public static String address = "abc";
}
public class MainActivity {
  // ...
  public void onCreate(....) {
    Log.d("TAG", InputAddress.address);
  }
}

嗨Deki Kurnia Hadi Permana

有很多方法可以将数据从一个类传输到另一个类,但是对于活动来说,不需要做任何事情,它们提供了使用意图数据将数据从一个活动传输到另一个活动的功能

以下是您可以在其他活动中发送和访问数据的代码

FirstActivity.class

Intent callIntent=new Intent(FirstActivity.this,SecondActivity.class);
        callIntent.putExtra("urlToLaunch","post url here");
        startActivity(callIntent);

SecondActivity.class
Bundle bundle=getIntent().getExtras();
        if(bundle!=null){
            String urlToLaunch=bundle.getString("urlToLaunch");
//            set In webbrowser
        }

使用putExtra传递url。