Android 应用程序启动导入的模块而不是 MainActivity
Android App Starts Imported Module and Not MainActivity
android 的新手。我正在实现一个导航抽屉,在选择一个特定按钮(抽屉中的位置 0)后,我将启动一个 activity。这些活动是在我导入的模块中定义的。
首先,我创建了导航抽屉。我正在使用位置来确定单击了哪个按钮。为了测试,我只使用了一个按钮和一个 activity。我将这个项目导入为一个模块:
https://github.com/spacecowboy/NoNonsense-FilePicker
我希望能够从我的菜单中启动他的第一个 activity。我删除了他的清单的意图过滤器,以便我的应用程序首先启动,如下面的代码所示。问题是我的应用程序仍然会首先启动导入的模块,而不是我的导航抽屉。如果我点击后退按钮,它就会转到导航抽屉。不能post截图,因为我是菜鸟。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fileexplorer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".FileexplorerActivity"
android:label="@string/title_activity_fileexplorer">
<!--android:theme="@android:style/Theme.Holo"--> >
<!-- <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>-->
</activity>
<activity
android:name=".FileChooser"
android:label="Choose File" >
//android:theme="@android:style/Theme.Holo">
<action android:name="com.example.fileexplorer.FileChooser" />
<category android:name="android.intent.category.DEFAULT" />
</activity>
</application>
</manifest>
我的 MainActivity 清单文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.jonny.nav" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
tools:replace="android:icon">
<activity
android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.Light"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这就是我从抽屉代码开始 activity 的方式。
private void selectItem(int position) {
Intent selectedIntent = null;
switch(position){
case 0:
{
selectedIntent = new Intent(this.getActivity(), FileexplorerActivity.class);
startActivity(selectedIntent);
break;
}
default:
break;
}
}
一个肮脏的把戏是在你的 xml..
中用 ".FileChooser"
.. 替换 ".MainActivity
"
如果您的 MainActivity 现在启动时 运行,它应该让您使用文件选择器..
另一种选择是清理并重新打开项目,如果您认为自己做的是正确的..
所以我发现它工作正常;我刚刚有了它,所以位置 0 activity 会默认开始。移到位置1,问题解决
android 的新手。我正在实现一个导航抽屉,在选择一个特定按钮(抽屉中的位置 0)后,我将启动一个 activity。这些活动是在我导入的模块中定义的。
首先,我创建了导航抽屉。我正在使用位置来确定单击了哪个按钮。为了测试,我只使用了一个按钮和一个 activity。我将这个项目导入为一个模块: https://github.com/spacecowboy/NoNonsense-FilePicker
我希望能够从我的菜单中启动他的第一个 activity。我删除了他的清单的意图过滤器,以便我的应用程序首先启动,如下面的代码所示。问题是我的应用程序仍然会首先启动导入的模块,而不是我的导航抽屉。如果我点击后退按钮,它就会转到导航抽屉。不能post截图,因为我是菜鸟。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fileexplorer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".FileexplorerActivity"
android:label="@string/title_activity_fileexplorer">
<!--android:theme="@android:style/Theme.Holo"--> >
<!-- <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>-->
</activity>
<activity
android:name=".FileChooser"
android:label="Choose File" >
//android:theme="@android:style/Theme.Holo">
<action android:name="com.example.fileexplorer.FileChooser" />
<category android:name="android.intent.category.DEFAULT" />
</activity>
</application>
</manifest>
我的 MainActivity 清单文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.jonny.nav" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
tools:replace="android:icon">
<activity
android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.Light"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这就是我从抽屉代码开始 activity 的方式。
private void selectItem(int position) {
Intent selectedIntent = null;
switch(position){
case 0:
{
selectedIntent = new Intent(this.getActivity(), FileexplorerActivity.class);
startActivity(selectedIntent);
break;
}
default:
break;
}
}
一个肮脏的把戏是在你的 xml..
中用".FileChooser"
.. 替换 ".MainActivity
"
如果您的 MainActivity 现在启动时 运行,它应该让您使用文件选择器..
另一种选择是清理并重新打开项目,如果您认为自己做的是正确的..
所以我发现它工作正常;我刚刚有了它,所以位置 0 activity 会默认开始。移到位置1,问题解决