dimanche 24 mai 2015

Android App Starts Imported Module and Not MainActivity

New to android. I'm implementing a navigation drawer and upon selecting a specific button (position 0 in the drawer) I'm going to start an activity. These activities are defined in modules that I've imported.

To start with I created the navigation drawer. I'm using the position to determine which button was clicked. For testing I'm just using one button and one activity. I imported this project as a module: http://ift.tt/1BbBnkc

I want to be able to start his first activity from my menu. I removed the intent filter for his manifest so that my application would start first shown in the code below. The problem is that my application will still start the imported module first and not my navigation drawer. If I hit the back button then it goes to the navigation drawer. Can't post screenshots since I'm a noob.

<manifest xmlns:android="http://ift.tt/nIICcg"
    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>

My MainActivity manifest file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
    xmlns:tools="http://ift.tt/LrGmb4"
    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>

This is how I start the activity from the drawer code.

private void selectItem(int position) {

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

Aucun commentaire:

Enregistrer un commentaire