有多个活动Android应用 [英] Android app with multiple activities
问题描述
我有一个非常简单的游戏,只包含一个活动,我想添加标题画面。
如果标题画面是另一个活动,我需要什么样的变化,使我的清单文件,以使标题屏幕打开第一?
该游戏的活动就叫做Leeder先生和标题屏幕活动被称为LeederTitleScreen
下面是我当前的清单文件。
< XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=org.nifong.leeder
安卓版code =1
机器人:VERSIONNAME =1.0>
<应用机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME>
<活动机器人:名称=Leeder先生
机器人:标签=@字符串/ APP_NAME
机器人:configChanges =keyboardHidden |定位
机器人:screenOrientation =景观与GT;
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
< /用途>
<使用-SDK安卓的minSdkVersion =5/>
<使用-权限的Android:名称=android.permission.WAKE_LOCK/>
< /舱单>
所有你应该做的是改变:
<活动机器人:名称=Leeder先生
到
<活动机器人:名称=LeederTitleScreen
如果你希望你的标题画面开始通过 startActivity游戏()
,你还需要声明你的 Leeder先生
活动清单。
修改:是的,你需要的<意向滤光器>部分。它告诉系统,它隐含的意图你的活动会回应。因此,在你的清单中,意图过滤器通知系统,它会在 android.intent.category.LAUNCHER
的意图,这是当它启动一个应用程序的Android有什么回应分派(也就是说,它讲述的Android应用程序时开始启动活动)。
这里是意图和意图过滤器的一个很好的概述。
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>
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.
这篇关于有多个活动Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!