Android app with multiple activities

心不动则不痛 提交于 2020-01-12 03:27:11

问题


I have a very simple game that consists of only one activity, and I want to add a title screen.

If the title screen is another activity, what changes do I need to make to my manifest file to make the title screen open first?

The gameplay activity is called Leeder, and the title screen activity is called LeederTitleScreen

here is my current manifest file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="org.nifong.leeder"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name="Leeder"
                  android:label="@string/app_name"
                  android:configChanges="keyboardHidden|orientation"
                  android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="5" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>

回答1:


All you should have to do is change:

<activity android:name="Leeder"

to:

<activity android:name="LeederTitleScreen"

If you want your title screen to start the game via startActivity(), you'll also need to declare your Leeder activity in the manifest.

Edit: Yes, you need the <intent-filter> section. It tells the system which implicit intents your activity will respond to. So in your manifest, the intent filter tells the system that it will respond to the android.intent.category.LAUNCHER intent, which is what Android dispatches when it starts an app (i.e. it tells Android to start the Activity when the application is started).

Here is a good overview of intents and intent filters.



来源:https://stackoverflow.com/questions/2225738/android-app-with-multiple-activities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!