如何从android studio中的库模块调用活动
我试图从我的应用程序中的库模块调用一个活动。 我一直在收到错误
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.nextgis.mobile/com.nextgis.mobile.activity.MainActivity}; have you declared this activity in your AndroidManifest.xml?
我把活动称为
Intent intentGIS = new Intent(android.content.Intent.ACTION_VIEW); intentGIS.setComponent(new ComponentName("com.nextgis.mobile", "com.nextgis.mobile.activity.MainActivity")); startActivity(intentGIS);
应用清单:
<!-- --> <!-- -->
图书馆清单:
<!-- ~ Project: NextGIS Mobile ~ Purpose: Mobile GIS for Android. ~ Author: Dmitry Baryshnikov (aka Bishop), bishop.dev@gmail.com ~ Author: NikitaFeodonit, nfeodonit@yandex.com ~ Author: Stanislav Petriakov, becomeglory@gmail.com ~ ****************************************************************************** ~ Copyright (c) 2012-2016 NextGIS, info@nextgis.com ~ ~ This program is free software: you can redistribute it and/or modify ~ it under the terms of the GNU General Public License as published by ~ the Free Software Foundation, either version 3 of the License, or ~ (at your option) any later version. ~ ~ This program is distributed in the hope that it will be useful, ~ but WITHOUT ANY WARRANTY; without even the implied warranty of ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ~ GNU General Public License for more details. ~ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see . -->
我在模块app
的gradle文件中添加了compile project(':gisapp')
。 我知道gradle会自动显示合并,但我可能错了。
我在这做错了什么?
注意: 这是我用作库的项目。
我们可以使用reflection来获取类对象。
的Class.forName( “com.mypackage.myMainActivity”)
在Library项目中添加此代码以进行调用,
try { Intent myIntent = new Intent(this,Class.forName("com.mypackage.myMainActivity")); startActivity(myIntent ); } catch (ClassNotFoundException e) { e.printStackTrace(); }
“com.mypackage.myMainActivity”是Main项目中的Activity,我们需要从它的Library项目中调用它。