在应用A中,点击按钮时
Intent intent = getPackageManager().getLaunchIntentForPackage("com.example.db_demo");
if (intent != null) {
intent.putExtra("name", "Liu xiang");
intent.putExtra("birthday", "1983-7-13");
startActivity(intent);
} else {
ToastUtils.success("哟,赶紧下载安装这个APP吧");
备注:这里是默认启动应用B的启动页面
二、应用A中点击按钮,跳转到应用B中的指定Activity
注意:通过scheme来启动Activity
1.应用A中,点击按钮
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("scheme_db://123123123")));
2.应用B中,AndroidManifest.xml的配置如下
假设要启动的是
<activity android:name=".ui.WCDBActivity"
android:launchMode="singleInstance"> //多窗口,可添加android:launchMode="singleInstance"
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="scheme_db"/> //通过scheme名称,可启动WCDBActivity
</intent-filter>
</activity>
3.在应用B中,WCDBActivity中可获取应用A中传递过来的数据
getIntent().getScheme();
String data = getIntent().getDataString();
Toast.makeText(this, data+"",Toast.LENGTH_LONG).show();
三、应用A点击按钮,跳转到应用B的指定Activity
另外一种跳转指定Activity模式如下:
1.应用A中,点击
ComponentName componentName =
new ComponentName("com.example.db_demo", "com.example.db_demo.ui.SQLiteActivity");
Intent intent = new Intent();
intent.putExtra("id", 1001);
intent.setComponent(componentName);startActivity(intent);
2.应用B中,AndroidManifest.xml需要修改
<activity
android:name=".ui.LiteOrmActivity"
android:exported="true" //必须配置,否则不能被其他应用开启
//如果想要在相邻窗口打开,则修改启动模式singleTask或者singleInstance
android:launchMode="singleTask"/>
复制代码