从我的库项目开始主项目的活动

har*_*ash 2 android android-intent android-library android-activity

我有2个项目。一个是我的 Main Project(A) ,另一个是 Library Project(B) 。我想从 B 中的活动开始 A 中存在的活动。我该怎么做?

我试过了startActivity(getApplicationContext(),B.class); ,但是

B级

没有解决。

如何让我的图书馆项目开始我的主要项目的活动?

zma*_*ies 5

您不应该需要使用意图过滤器。Activity A中的代码可以使用

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

startActivity(this, intent);
Run Code Online (Sandbox Code Playgroud)

指定应该启动的活动B。