Android应用启动导入模块而不是MainActivity



android新手。我正在实现一个导航抽屉,并在选择一个特定的按钮(位置0在抽屉),我要开始一个活动。这些活动是在我导入的模块中定义的。

首先,我创建了导航栏。我使用位置来确定点击了哪个按钮。对于测试,我只使用一个按钮和一个活动。我导入这个项目作为一个模块:https://github.com/spacecowboy/NoNonsense-FilePicker

我希望能够从我的菜单开始他的第一个活动。我删除了他的清单的意图过滤器,这样我的应用程序就会首先启动,如下面的代码所示。问题是,我的应用程序仍然会首先启动导入的模块,而不是我的导航抽屉。如果我按后退键它就会转到导航栏。因为我是新手,所以不能发布截图。

<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>

这是我如何从抽屉代码启动活动。

private void selectItem(int position) {
        Intent selectedIntent = null;
        switch(position){
            case 0:
            {
                selectedIntent = new Intent(this.getActivity(), FileexplorerActivity.class);
                startActivity(selectedIntent);
                break;
            }
            default:
                break;
        }
    } 

".FileChooser"代替".MainActivity

如果你的MainActivity在启动时正在运行,它应该让你选择文件选择器。

另一个选择是清理并重新打开项目,如果你相信你做的事情是正确的。

所以我发现它工作正常;我只是有它,所以位置0活动将默认启动。把它移到位置1,问题就解决了

最新更新