开发者

cant start browser from service in android

Hello I am trying to start the android browser from a service using this code:

protected void showBrowser(){

    String url = "http://www.google.com";
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    this.startActivit开发者_开发百科y(i);
}

but this doesn't seem to work! the browser is never started and using log the execution stops when the startActivity is called.


You might also need:

i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);


This works for me. I think this comes from an official android tutorial, so probably you've seen it. So just use this snippet and it should work.

 public void openBrowser(View view){
      Intent i = new Intent("android.intent.action.VIEW", Uri.parse("http://google.com"));
       startActivity();
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜