user3515102
user3515102

Reputation: 43

How can I save a URL and load this URL in webview (android studio)

Android Studio

1: Open activity only once and save the URL link

2: Get this link in webview

myWebView.loadUrl("url link");

Thanks and regards

Upvotes: 0

Views: 972

Answers (1)

anomeric
anomeric

Reputation: 698

I'm not sure what clarification you need, as you already answered your own question (whether you realized it or not)

public class MyActivity extends Activity {

    WebView webView;

    // You can define as many of these as you like
    String urlString1 = "www.google.com";
    String urlString2 = "www.facebook.com";

    ...

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ...
        webView = (WebView) findViewById(R.id.my_web_view_id):
        ...
        webView.loadUrl(new Url(urlString));

    }

}

If you want to use shared preferences:

 // initialize prefs
 SharedPreferences sharedPreferences = getSharedPreferences("some_string_identifier" , Context.MODE_PRIVATE);
// get url
urlString1 = sharedPreferences.getString("url", null);

// save url
Editor editor = sharedPreferences.edit();     
editor.putString("url", urlString1); 
editor.commit();

Upvotes: 1

Related Questions