【问题标题】:Android App Starts Imported Module and Not MainActivityAndroid 应用程序启动导入的模块而不是 MainActivity
【发布时间】:2015-05-24 19:39:04
【问题描述】:

安卓新手。我正在实现一个导航抽屉,并在选择一个特定的按钮(抽屉中的位置 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;
        }
    } 

【问题讨论】:

    标签: android android-intent navigation drawer


    【解决方案1】:

    一个肮脏的把戏是用".FileChooser"..在你的xml中替换".MainActivity"..

    如果您的 MainActivity 现在在启动时运行,它应该让您使用文件选择器。

    如果您认为自己做的事情正确,另一种选择是清理并重新打开项目..

    【讨论】:

    • 如果我尝试将其更改为“.FileChooser”,它会说它无法解析符号并变为红色。我尝试清洁并重新打开它。 :(
    • 您确定文件选择器活动存在吗?另外,你能告诉我错误吗?
    【解决方案2】:

    所以我发现它工作正常;我刚刚拥有它,以便默认情况下开始位置 0 活动。把它移到位置1,问题就解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-07
      • 1970-01-01
      • 1970-01-01
      • 2021-07-25
      相关资源
      最近更新 更多