Android从一个App界面跳转到另一个App界面

Android从一个App界面跳转到另一个App界面
首先,将需要的要跳转的App的activity暴露出来

 <activity
        android:name=".MainPage"
        android:exported="true">
    </activity>

需要注意的是,如果不暴露,就会报错

然后在需要进行跳转的地方写如下代码
显示启动
1 常见

  Intent intent =new Intent(FirstActivity.this,SecondActivity.class);
        startActivity(intent);

2 通过Intent的ComponentName:

//前提:知道要跳转应用的包名、类名
Intent intent =new Intent(Intent.ACTION_MAIN);
//ComponentName的第一处是package的包名,第二个是锁需要进行跳转的类名
ComponentName componentName = new 
ComponentName("com.example.selftest","com.example.selftest.MainPage");
intent.setComponent(componentName);
startActivity(intent);

3 初始化Intent时指定包名:

Intent intent = new Intent("android.intent.action.MAIN");
intent.setClassName("当前Act的全限定类名","启动Act的全限定类名");
startActivity(intent);

隐式启动
通过Intent-filter的Action,Category或data来实现

Intent intent1 =new Intent("com.example.helloandroid.core.action.SecondActivity");
                startActivity(intent1);

猜你喜欢

转载自blog.csdn.net/qq_52843958/article/details/129345579