dtrodriguez
dtrodriguez

Reputation: 91

Trying to have main menu and submenu classes

So my original problem was that in my manifest my menu wasent loading ie

 <activity
        android:name=".MainMenu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.th3ramr0d.learnar670_1.MAINMENU" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
 </activity>

This was fixed by loading it at startup ie

 <activity
        android:name=".MainMenu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
 </activity>

So now my main menu works. However, the buttons inside MainMenu.xml will take you to another .xml file with more buttons. So now I have the same problem. I created another class called SubMenuChapter3 and put it in the manifest as such.

 <activity
        android:name=".SubMenuChapter3"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.th3ramr0d.learnar670_1.SUBMENUCHAPTER3" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
 </activity>

Now this doesnt work I am assuming for the same reason as before with mainmenu. Doesnt crash or give me errors. It just wont open the submenuchapter3 class. I forced the submenuchapter3 class to open by putting

 startActivity(new Intent("com.th3ramr0d.learnar670_1.SUBMENUCHAPTER3"));

directly into the MainMenu class outside of an onclick just to see if it was working. When I do that it opens the chapter_3.xml like it is supposed to and the button works. Thanks for the help.

Upvotes: 0

Views: 47

Answers (1)

Eugen Pechanec
Eugen Pechanec

Reputation: 38243

You misunderstood <intent-filter> tag and the way you start activities.

Also maintain proper terminology - Menu and Activity are completely different things.

Everything you need to know about Activities can be found here: Activities | Android Developers

Example:

This entry in AndroidManifest.xml says "show the MainMenu Activity as icon in the launcher":

<activity
    android:name=".MainMenu"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

EDIT: This allows Android to start MainActivity. It will also show in the installed app list.

The following Activity will not be displayed in launcher but can be opened from the app:

<activity android:name=".SubMenuChapter3"/>

EDIT: This allows Android to start SubMenuChapter3. It won't show in the installed app list.

These lines say "open the SubMenuChapter3 Activity":

Intent i = new Intent(this, SubMenuChapter3.class);
startActivity(i);

EDIT: You call this code from inside the onClick method inside MainMenu. It will launch SubMenuChapter3.

Upvotes: 1

Related Questions