CodeMonkeyAlx
CodeMonkeyAlx

Reputation: 853

is there a good way to open a webpage automatically after an app starts?

I guess the question is the description. Plain, simple... How can I do this in a simple and easy way? I have done this before in regular Java, but android being so similar and yet soooo different seems to have a different way of doing so.

-Thanks!

Upvotes: 0

Views: 152

Answers (1)

Ahmad
Ahmad

Reputation: 72613

You can do it with this in your OnCreate() method:

Intent openLink = new Intent(Intent.ACTION_VIEW, Uri.parse("yourLink"));
startActivity(openLink);

Or if you don't want to open it in a web browser you can load it in a WebView like this:

WebView myWebView  = (WebView) findViewById(R.id.yourWebView);
myWebView.loadUrl("yourLink");
myWebView.setWebViewClient(new MyWebViewClient());

but then don't forget to create a WebViewClient:

public class MyWebViewClient extends WebViewClient {

     @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
}

Upvotes: 3

Related Questions