0

在此之后:http: //developer.android.com/training/basics/firstapp/starting-activity.html在编辑 Android Manifest.xml 文件时我很困惑。它说该文件应包含以下内容:

<application ... >
    <activity android:name="com.example.myapp.DisplayMessageActivity" />
     ...
    </application>

我的 android manifest.xml 看起来像这样:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.nick.myfirstapp"
        android:versionCode="1"
        android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="4"
        android:targetSdkVersion="15" />

    <application android:label="@string/app_name">
       <activity android:name="com.nick.myfirstapp.DisplayMessageActivity" />
        ...
    </application>



</manifest>

当我运行应用程序时,一切都很好,除了它说:“没有找到启动器活动!启动只会同步设备上的应用程序包!” 这是 android manifest.xml 文件中缺少的东西吗?

4

4 回答 4

2

在 AndroidManifest.xml 中声明您的活动,如在启动器中显示为:

<application android:label="@string/app_name">
       <activity android:name="com.nick.myfirstapp.DisplayMessageActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

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

有关更多信息,请参阅我们如何在 Launcher 中设置活动:

http://developer.android.com/reference/android/content/Intent.html

http://developer.android.com/reference/android/app/Activity.html

于 2012-07-01T14:50:07.360 回答
0

您需要将清单更改为以下内容。这样做会告诉 Android 您希望使用您的图标在启动器中显示此 Activity。

<application android:label="@string/app_name" android:icon="drawable icon resource here">
       <activity android:name="com.nick.myfirstapp.DisplayMessageActivity" android:label="Your Label">
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

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

在文档中,用于...显示您的正常代码位于此处。您正在做的事情对于非启动器活动很好。

于 2012-07-01T14:52:28.587 回答
0

您缺少启动器意图,因此应用程序在开始时找不到要启动的活动。

您需要像这样布置活动:

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
于 2012-07-01T14:52:50.563 回答
0

package="com.example.myfirstapp"

android:versionCode="1"

android:versionName="1.0" >


<uses-sdk

    android:minSdkVersion="8"

    android:targetSdkVersion="17" />


<application

    android:allowBackup="true"

    android:icon="@drawable/ic_launcher"

    android:label="@string/app_name"

    android:theme="@style/AppTheme" >

    <activity

        android:name="com.example.myfirstapp.DisplayMessageActivity"

        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>

于 2013-04-20T13:46:58.923 回答