您的位置:首页 > 移动开发

在当前activity中启动自己另一个程序的activity

2012-02-27 10:32 429 查看
现在有个需求,需要在现有的app中调用另一个app,并且传入相应的参数

查了一下,还是蛮方便的

假设现有的app::com.sqlhelp.app2

需用启动的app为:com.sqlhelp.app1

具体步骤如下:

1.修改app2的AndroidManifest.xml的配置,在原来启动的activity中增加一个<intent-filter>,如下图标识的

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".appMain"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.sqlhelp.app2.appMain" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>


2.修改app1的AndroidManifest.xml的配置,增加一个新的activity

<activity android:name="com.sqlhelp.app2.appMain"
android:label="@string/app_name">
</activity>


3.在app2中调用app1的启动intent,通过Bundle传递参数

Intent testIntent = new Intent("com.sqlhelp.app2.appMain");
Bundle m_bundle = new Bundle();
m_bundle.putBoolean("Show",true);
testIntent.putExtras(m_bundle);
startActivity(testIntent);


4.在app1中接受参数,做相应的操作

Bundle m_Bundle = this.getIntent().getExtras();
boolean m_Show = m_Bundle.getBoolean("Show");
....
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android action application