Start Activity of Main project from my library project

可紊 提交于 2019-12-06 23:42:26

You can add custom Action in intent-filter of you activity and start that activity by specifying action

<activity android:name="my.package.MyActivity">
    <intent-filter>
        <action android:name="my.package.action.MY_ACTION"/>
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="my.package"/>
    </intent-filter>
</activity>

start activity with this code:

final Intent intent = new Intent("my.package.action.MY_ACTION");
intent.addCategory(getActivity().getPackageName());
startActivity(getActivity(), intent);

You shouldn't need to use an intent filter. The code in Activity A can use

ComponentName cn = new ComponentName(this, "my.package.MyActivity.B");
Intent intent = new Intent().setComponent(cn);

startActivity(this, intent);

to specify the activity B should be started.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!