首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

在Service中起步Activity

2012-08-31 
在Service中启动Activity在Service中启动Activity,我碰到的情况是要在壁纸的点击事件中启动一个浏览器访问

在Service中启动Activity
在Service中启动Activity,我碰到的情况是要在壁纸的点击事件中启动一个浏览器访问web。实现代码如下:

Uri url = Uri.parse("http://www.google.com/");  Intent intent = new Intent(Intent.ACTION_VIEW,url);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);


一定要加上intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);否则可能会抛出NullPointException。还有一点就是如果你的需求和我碰到情况一样的话,别忘了在onTouchEvent(MotionEvent event)执行之前的回调函数中(如OnCreate()中)加上setTouchEventsEnabled(true)激活壁纸背景的点击事件。

热点排行