您的位置:首页 > 其它

一个程序A通过intent调用程序B的Activity

2012-12-25 16:11 459 查看
好久没有写代码了,今天要测试一个全屏的Activity,都不知道怎么写了,Intent的用法也忘的差不多了。

可以通过显示和隐式方法来实现。

隐式方法:通过在程序B的manifest.xml文件中对相应的Activity进行配置,如:

<activity android:name="com.routon.brow.WebViewActivity"
android:label="FullScreen"
android:theme="@style/NoTitle">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>

<catagory android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="javascript" />
</intent-filter>
<intent-filter >
<action android:name="com.routon.brow.FULLSCREEN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
在程序A中,我可以使用

Intent t = new Intent();
t.setAction("com.routon.brow.FULLSCREEN");
startActivity(t);
来启动B程序的Activity。当然,大多数情况,我们还要传数据,可以通过Intent的setData()方法,put系列的方法来设置。

显示方法:

调用Intent.setComponent()\ Intent.setClassName()或Intent.setClass()方法 或者在new Intent(A.this,B.class)指明需要转向到的Activity 这种明确指定了组件名的Intent为显式意图,显式意图明确指定了要激活的组件是哪个组件。

如使用Component:
Intent intent = new Intent();
ComponentName comp = new ComponentName("com.routon.brow","com.routon.brow.WebViewActivity");
intent.setComponent(comp);
startActivity(intent);
很多东西很容易忘,希望自己能够坚持记录,记录自己的成长。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐