-4

i have two class, MainActivity and InputAddress, how to load url from class InputAddress

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

3 Answers3

1

send data from inputAddrss,

Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("url", YOUR_EDIT_TEXT.getText().toString());
startActivity(intent);

receive data in MainActivity,

String s = getIntent().getStringExtra("url");

then load into webview

view.loadUrl(s);
Exigente05
  • 2,068
  • 3
  • 16
  • 35
0

You can add a public static variable like this:

public class InputAddress {
  public static String address = "abc";
}

then you can access the address variable in MainActivity like this:

public class MainActivity {
  // ...
  public void onCreate(....) {
    Log.d("TAG", InputAddress.address);
  }
}
zijing07
  • 86
  • 4
0

Hi Deki Kurnia Hadi Permana,

There are lots of way to transfer data from one class to another class, But for the activity no need to do anything they provide functionality to transfer data one to another activity using "Intent" data,

Following is the code where you can send and access data in another activity.

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
        }
Dhaval Solanki
  • 4,093
  • 1
  • 21
  • 33