简体   繁体   English

Android manifest.xml问题

[英]Android manifest.xml problems

Following this: http://developer.android.com/training/basics/firstapp/starting-activity.html I am confused when editing the Android Manifest.xml file. 接下来: http//developer.android.com/training/basics/firstapp/starting-activity.html编辑Android Manifest.xml文件时我很困惑。 It says that the file should contain this: 它说文件应该包含这个:

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

My android manifest.xml looks like this: 我的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>

and when I run the app everything goes fine except it says : "No Launcher activity found! The launch will only sync the application package on the device!" 当我运行应用程序时,一切都很顺利,除了它说:“没有找到Launcher活动!启动只会同步设备上的应用程序包!” Is this something missing from the android manifest.xml file? 这是android manifest.xml文件中缺少的东西吗?

declare Your Activity in AndroidManifest.xml as for Showing In Launcher as: 在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>

see for more info how we set an activity which so in Launcher : 有关我们如何在Launcher中设置活动的更多信息,请参阅:

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

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

You need to change you manifest to the following. 您需要将清单更改为以下内容。 Doing this will tell Android that you want this Activity to be displayed in the Launcher using your icon. 执行此操作将告诉Android您希望使用您的图标在Launcher中显示此活动。

<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>

In the docs the used ... to show that your normal code goes here. 在文档中使用...来表明你的正常代码在这里。 What you're doing is fine for non-launcher Activities. 你正在做的事情对于非发射器活动是好的。

You are missing the launcher intent and therefore the app finds no activity to launch at the start. 您缺少启动器意图,因此应用程序在开始时找不到要启动的活动。

You need to lay out the activity like so: 你需要像这样布置活动:

    <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>

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM