现在有个需求,需要在现有的app中调用另一个app,并且传入相应的参数
查了一下,还是蛮方便的
假设现有的app::com.sqlhelp.app2
需用启动的app为:com.sqlhelp.app1
具体步骤如下:
1.修改app2的
AndroidManifest.xml的配置,在原来启动的activity中增加一个<intent-filter>,如下图标识的
[html]
<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
[html]
<activity
Android:name="com.sqlhelp.app2.appMain"
Android:label="@string/app_name">
</activity>
3.在app2中调用app1的启动intent,通过Bundle传递参数
[
java]
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中接受参数,做相应的操作
[
java]
Bundle m_Bundle = this.getIntent().getExtras();
boolean m_Show = m_Bundle.getBoolean("Show");
....