2012-12-19 57 views
20

如何在我的Android清單中註冊我的應用程序類?我在網上查了很多教程,但仍然無法正確理解。我的應用程序類叫做Monitor.java。我如何在下面的清單文件代碼中註冊它?如何在清單文件中註冊應用程序類?

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

<application 
    android:allowBackup="true" 
    android:debuggable="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="xyz" 
    android:screenOrientation="landscape" 
    android:theme="@style/AppTheme" > 

    <service 
     android:name=".AudioService" 
     android:icon="@drawable/ic_launcher" 
     android:label="audioservice" > 
    </service> 

    <activity 
     android:name=".MainActivity" 
     android:screenOrientation="landscape" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

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

    <activity 
     android:name=".Editor" 
     android:screenOrientation="landscape" 
     android:windowSoftInputMode="stateHidden" > 
     <intent-filter> 
      <action android:name="com.example.project.EDITOR" /> 

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

</application> 

+0

你忘了加上「名「應用程序標籤中的屬性.. – SilentKiller

回答

47
<application 
     android:name="package.YourApplicationClass" <-------- 
     android:allowBackup="true" 
     android:debuggable="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="xyz" 
     android:screenOrientation="landscape" 
     android:theme="@style/AppTheme"> 
+0

是的,它的作品! – Kevik

+1

@Kevik:如果您得到解決方案,您可以將此答案標記爲正確 – MAC

+1

@frayab +1正確答案 – MAC

1

好了,你已經有了內部的應用程序類 - 開始<application。如果你有一個自定義類(即擴展Application)在你的代碼,並希望它啓動 - 把

android:name=".Monitor" (or full path like com.something.app.Monitor) 

<application標籤(同一進程中都將添加一個活動)。

2

簡單,把android:name屬性與您的應用程序類名<application />標籤應用的的Manifest.xml的

<application 
android:name=".Monitor" 
    .... > 

更新:

應用類別:

個基類,用於需要維護全局應用程序狀態的人員。 你可以通過在你的AndroidManifest.xml標籤中指定它的名字來提供你自己的 實現,當你的應用程序/包的進程被創建時, 將會爲你實例化這個類。

更多信息看http://developer.android.com/reference/android/app/Application.html

7

試試這個:

<application android:icon="@drawable/icon" 
     android:label="@string/app_name" 
     android:name="Monitor"> 

請參見下面的很好的參考鏈接:

How to use the Application object of Android

感謝。

+0

我將檢查出鏈接 – Kevik

+0

@Kevik你將會得到'Application class'的很好的例子以及給定鏈接的所有必需的細節。謝謝。 –

+0

分享鏈接+1 – Patrick

1

只需將android:name=".Monitor"屬性添加到application標記(我假定Monitor.java類位於應用程序包的根目錄中)。希望這可以幫助。

0

使用這一個

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.testing" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="16" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name=".Monitor" 
     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> 

</manifest> 
1

什麼困惑我的是「機器人:名稱」清單文件中多次出現。在創建應用程序類文件之前,我有'活動'標記後的

android:name=".MainActivity" 

創建應用程序文件後,一切都在清單文件保持不變,除了「應用程序」標籤後,我加入

android:name=".myApplicationClass" 

我的完整清單文件:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="pixtas.com.nightout" > 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
    <uses-permission android:name="android.permission.VIBRATE" /> 
    <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 

    <!-- 
     IMPORTANT: Change "com.parse.tutorials.pushnotifications.permission.C2D_MESSAGE" in the lines below 
     to match your app's package name + ".permission.C2D_MESSAGE". 
    --> 
    <permission android:protectionLevel="signature" 
     android:name="pixtas.com.nightout.permission.C2D_MESSAGE" /> 
    <uses-permission android:name="pixtas.com.nightout.permission.C2D_MESSAGE" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" 
     android:name=".myApplicationClass" > 


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

     <service android:name="com.parse.PushService" /> 
     <receiver android:name="com.parse.ParseBroadcastReceiver"> 
      <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED" /> 
       <action android:name="android.intent.action.USER_PRESENT" /> 
      </intent-filter> 
     </receiver> 
     <receiver android:name="com.parse.GcmBroadcastReceiver" 
      android:permission="com.google.android.c2dm.permission.SEND"> 
      <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
       <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 

       <!-- 
        IMPORTANT: Change "com.parse.tutorials.pushnotifications" to match your app's package name. 
       --> 
       <category android:name="pixtas.com.nightout" /> 
      </intent-filter> 
     </receiver> 
     <receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported="false"> 
      <intent-filter> 
       <action android:name="com.parse.push.intent.RECEIVE" /> 
       <action android:name="com.parse.push.intent.DELETE" /> 
       <action android:name="com.parse.push.intent.OPEN" /> 
      </intent-filter> 
     </receiver> 

     <!-- replace @drawable/push_icon with your push icon identifier --> 
     <meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/ic_launcher"/> 

    </application> 

</manifest> 
相關問題