开发者

Proper Android Intent Helper Class Usage?

I have two classes a MainActivity.class and a IntentsUtils.class.

Here is my IntentsUtils.class:

 public class IntentsUtils
    {
        public void invokeWebBrowser(Activity activity)
        {
            String url = "http://snipt.net/Martin/android-intent-usage/";
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            activity.startActivity(intent);
        }
   开发者_JAVA技巧 }

If I wanted to run invokeWebBrowser() from my MainActivity.class, what would be the best method?

Thanks.


Button button = (Button) findViewById(R.id.launch_br_btn);
button.setOnClickListener(new OnClickListener() {
  @Override
  public void onClick() {
     IntentUtils.invokeWebBrowser(MainActivity.this);
  }

})

put this to your onCreate() method of MainActivity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜