java如何从安卓 studio中的库模块调用活动
我试图从应用程序中的库模块调用活动。我一直在犯错误
安卓.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(安卓.content.Intent.ACTION_VIEW);
intentGIS.setComponent(new ComponentName("com.nextgis.mobile",
"com.nextgis.mobile.activity.MainActivity"));
startActivity(intentGIS);
应用程序清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
package="com.disarm.sanna.pdm">
<uses-permission 安卓:name="安卓.permission.READ_PHONE_STATE" />
<uses-permission 安卓:name="安卓.permission.CHANGE_WIFI_STATE" />
<uses-permission 安卓:name="安卓.permission.CHANGE_NETWORK_STATE" />
<uses-permission 安卓:name="安卓.permission.RECORD_AUDIO" />
<uses-permission 安卓:name="安卓.permission.CLEAR_APP_CACHE" />
<uses-permission 安卓:name="安卓.permission.READ_EXTERNAL_STORAGE" />
<uses-permission-sdk-23 安卓:name="安卓.permission.WRITE_SETTINGS" />
<uses-permission 安卓:name="安卓.permission.READ_CONTACTS" />
<uses-permission 安卓:name="安卓.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission 安卓:name="安卓.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission 安卓:name="安卓.permission.ACCESS_FINE_LOCATION"/>
<uses-permission 安卓:name="安卓.permission.ACCESS_NETWORK_STATE"/>
<uses-permission 安卓:name="安卓.permission.ACCESS_WIFI_STATE"/>
<uses-permission 安卓:name="安卓.permission.AUTHENTICATE_ACCOUNTS"/>
<uses-permission 安卓:name="安卓.permission.INTERNET"/>
<uses-permission 安卓:name="安卓.permission.GET_ACCOUNTS"/>
<uses-permission 安卓:name="安卓.permission.MANAGE_ACCOUNTS"/>
<uses-permission 安卓:name="安卓.permission.READ_SYNC_SETTINGS"/>
<uses-permission 安卓:name="安卓.permission.READ_SYNC_STATS"/>
<uses-permission 安卓:name="安卓.permission.USE_CREDENTIALS"/>
<uses-permission 安卓:name="安卓.permission.WAKE_LOCK"/>
<uses-permission 安卓:name="安卓.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission 安卓:name="安卓.permission.WRITE_SYNC_SETTINGS"/>
<uses-permission 安卓:name="安卓.permission.VIBRATE"/>
<!--
<uses-permission 安卓:name="安卓.permission.CAMERA"/>
-->
<uses-feature
安卓:name="安卓.hardware.location"
安卓:required="true"
/>
<uses-feature
安卓:name="安卓.hardware.telephony"
安卓:required="false"
/>
<uses-feature
安卓:name="安卓.hardware.wifi"
安卓:required="false"
/>
<!--
<uses-feature
安卓:name="安卓.hardware.camera"
安卓:required="false"
/>
<uses-feature
安卓:name="安卓.hardware.compass"
安卓:required="false"
/>
-->
<supports-screens
安卓:largeScreens="true"
安卓:smallScreens="true"
安卓:anyDensity="true"
安卓:normalScreens="true"
安卓:xlargeScreens="true"
安卓:resizeable="true"
/>
<application
安卓:allowBackup="true"
安卓:icon="@drawable/logo"
安卓:label="@string/app_name"
安卓:supportsRtl="true"
安卓:theme="@style/AppTheme"
tools:node="replace">
<activity
安卓:name=".SplashActivity"
安卓:windowSoftInputMode="stateHidden|adjustUnspecified"
安卓:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<category 安卓:name="安卓.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
安卓:name="com.disarm.sanna.pdm.ShareActivity"
安卓:label="@string/app_name">
</activity>
<activity 安卓:name=".SelectCategoryActivity"
安卓:label="@string/app_name">
</activity>
<activity 安卓:name=".SocialShareActivity"
安卓:label="@string/app_name">
</activity>
<activity
安卓:name=".MainActivity"
安卓:label="@string/app_name"
安卓:theme="@style/AppTheme.NoActionBar">
</activity>
<activity
安卓:name=".ActivityList"
安卓:windowSoftInputMode="stateHidden|adjustPan"
安卓:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
</activity>
<activity
安卓:name=".Capture.Photo"
安卓:theme="@style/AppCompatAlertDialogStyle"
>
</activity>
<activity
安卓:name=".Capture.Video"
安卓:theme="@style/AppCompatAlertDialogStyle"
>
</activity>
<activity
安卓:label="Record Audio"
安卓:name=".Capture.AudioCapture"
安卓:theme="@style/Theme.AppCompat.Light.Dialog"
>
</activity>
<activity
安卓:label="@string/allow_setting"
安卓:name=".WriteSettingActivity"
安卓:theme="@style/AppTheme"
>
</activity>
<service
安卓:name=".Service.SyncService"
安卓:enabled="true"
安卓:exported="true" />
<service 安卓:name=".DisarmConnect.MyService" />
</application>
</manifest>
库清单:
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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 <http://www.gnu.org/licenses/>.
-->
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
package="com.nextgis.mobile"
>
<application
安卓:allowBackup="true"
安卓:label="@string/app_name"
>
<activity
安卓:name=".activity.MainActivity"
安卓:label="@string/app_name"
>
</activity>
<activity
安卓:name=".activity.SettingsActivity"
安卓:label="@string/action_settings"
/>
<activity
安卓:name=".activity.NGWSettingsActivityProxy"
安卓:label="@string/ngw_settings"
/>
<activity
安卓:name=".activity.AboutActivity"
安卓:label="@string/action_help"
/>
<activity
安卓:name=".activity.CreateVectorLayerActivity"
安卓:label="@string/create_layer"
安卓:screenOrientation="portrait"
/>
<service
安卓:name="com.nextgis.mobile.datasource.SyncService"
>
<intent-filter>
<action
安卓:name="安卓.content.SyncAdapter"
/>
</intent-filter>
<meta-data
安卓:name="安卓.content.SyncAdapter"
安卓:resource="@xml/syncadapter"
/>
</service>
<provider
安卓:name="com.nextgis.maplib.datasource.LayerContentProvider"
安卓:authorities="com.nextgis.mobile.provider"
安卓:exported="false"
安卓:syncable="true"
/>
</application>
</manifest>
我在gradle文件中为模块app
添加了compile project(':gisapp')
。我知道gradle是自动合并的,但我可能错了
我做错了什么
注:This是我用作库的项目
# 1 楼答案
我们可以使用反射来获取类对象
上课。forName(“com.mypackage.mymain活动”)
在库项目中添加此代码以调用
“com.mypackage.myMainActivity”是主项目中存在的活动,我们需要从其库项目中调用它