展会信息港展会大全

在当前activity中启动自己另一个程序的activity
来源:互联网   发布日期:2016-01-14 10:55:42   浏览:2411次  

导读:现在有个需求,需要在现有的app中调用另一个app,并且传入相应的参数查了一下,还是蛮方便的假设现有的app::com.sqlhelp.app2需用启动的app为:com.sqlhelp...

现在有个需求,需要在现有的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");

....

摘自 sql_help的专栏

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港