当前位置:操作系统 > 安卓/Android >>

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

现在有个需求,需要在现有的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 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,