Android 如何在库活动的manifest.xml中指定.Preference活动

Android 如何在库活动的manifest.xml中指定.Preference活动,android,android-manifest,Android,Android Manifest,我按照Tictaoe示例应用程序对代码进行建模,因此我的设置是,我有一个应用程序,它基本上是一个shell,启动一个公共活动,该活动位于一个单独的eclipse项目中,标记为共享库(properties->IsALibrary)。我已将库添加到调用活动的属性中。我调用共享库代码如下: private void startGame() { Intent i = new Intent( this, calendar.class ); startActivityForResult(

我按照Tictaoe示例应用程序对代码进行建模,因此我的设置是,我有一个应用程序,它基本上是一个shell,启动一个公共活动,该活动位于一个单独的eclipse项目中,标记为共享库(properties->IsALibrary)。我已将库添加到调用活动的属性中。我调用共享库代码如下:

    private void startGame()
    {
 Intent i = new Intent( this, calendar.class );
 startActivityForResult( i, START_APPLICATION );
    }
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.calendar" android:screenOrientation="portrait"
 android:versionCode="1" android:versionName="1.0">
 <application android:label="@string/app_name"
  android:debuggable="true" android:icon="@drawable/icon">

  <activity android:name=".MainActivity"
   android:screenOrientation="portrait" android:label="@string/app_name"
   android:configChanges="keyboardHidden|orientation">
   <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
  </activity>

        <!-- This is defined in CalendarLib. Right now we need to manually copy 
            it here. Eventually it should get merged automatically. -->
        <activity 
            android:name="com.library.calendar" >
        </activity>

<!--  <activity android:name=".Preferences" android:label="@string/prefTitle"-->
<!--   android:screenOrientation="nosensor">-->
<!--   <intent-filer>-->
<!--    <action android:name="com.calendar.library.Preferences" />-->
<!--    <catagory android:name="android.intent.catagory.PREFERENCE" />-->
<!--   </intent-filer>-->
<!--  </activity>-->

 </application>

 <uses-sdk android:minSdkVersion="4" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


 <supports-screens android:anyDensity="false"
  android:resizeable="true" android:largeScreens="true"
  android:normalScreens="true" android:smallScreens="false" />

</manifest> 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.calendar.library" android:versionCode="1"
 android:versionName="1.0">
 <application android:icon="@drawable/icon" android:label="@string/app_name">
  <!-- The activity tag here is currently not used. The main project must 
   currently redefine the activities to be used from the libraries. However 
   later the tools will pick up the activities from here and merge them automatically, 
   so it's best to define your activities here like for any regular Android 
   project. -->
  <activity android:name="calendar" />

        <activity android:name=".Preferences" android:label="@string/prefTitle"
            android:screenOrientation="nosensor">
            <intent-filer>
                <action android:name=".Preferences" />
                <catagory android:name="android.intent.catagory.PREFERENCE" />
            </intent-filer>
        </activity>

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

</manifest>
case MENU_SETTINGS:
     Intent intent = new Intent().setClass( this, Preferences.class );
     this.startActivityForResult( intent, 0 );
     return true;
调用活动的AndroidManifest如下所示:

    private void startGame()
    {
 Intent i = new Intent( this, calendar.class );
 startActivityForResult( i, START_APPLICATION );
    }
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.calendar" android:screenOrientation="portrait"
 android:versionCode="1" android:versionName="1.0">
 <application android:label="@string/app_name"
  android:debuggable="true" android:icon="@drawable/icon">

  <activity android:name=".MainActivity"
   android:screenOrientation="portrait" android:label="@string/app_name"
   android:configChanges="keyboardHidden|orientation">
   <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
  </activity>

        <!-- This is defined in CalendarLib. Right now we need to manually copy 
            it here. Eventually it should get merged automatically. -->
        <activity 
            android:name="com.library.calendar" >
        </activity>

<!--  <activity android:name=".Preferences" android:label="@string/prefTitle"-->
<!--   android:screenOrientation="nosensor">-->
<!--   <intent-filer>-->
<!--    <action android:name="com.calendar.library.Preferences" />-->
<!--    <catagory android:name="android.intent.catagory.PREFERENCE" />-->
<!--   </intent-filer>-->
<!--  </activity>-->

 </application>

 <uses-sdk android:minSdkVersion="4" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


 <supports-screens android:anyDensity="false"
  android:resizeable="true" android:largeScreens="true"
  android:normalScreens="true" android:smallScreens="false" />

</manifest> 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.calendar.library" android:versionCode="1"
 android:versionName="1.0">
 <application android:icon="@drawable/icon" android:label="@string/app_name">
  <!-- The activity tag here is currently not used. The main project must 
   currently redefine the activities to be used from the libraries. However 
   later the tools will pick up the activities from here and merge them automatically, 
   so it's best to define your activities here like for any regular Android 
   project. -->
  <activity android:name="calendar" />

        <activity android:name=".Preferences" android:label="@string/prefTitle"
            android:screenOrientation="nosensor">
            <intent-filer>
                <action android:name=".Preferences" />
                <catagory android:name="android.intent.catagory.PREFERENCE" />
            </intent-filer>
        </activity>

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

</manifest>
case MENU_SETTINGS:
     Intent intent = new Intent().setClass( this, Preferences.class );
     this.startActivityForResult( intent, 0 );
     return true;
当我点击设置时,我在Instrumentation.java中的execStartActivity()方法中得到START\u INTENT\u NOT\u解析。看看execStartActivity试图启动的意图,我明白了

mPackage="com.barrett.calendar" 
mClass="com.ifundraizer.calendar.library.Preferences"
其他一切都是空的,这并不奇怪

我的问题是:

preferences活动的定义是属于调用活动的清单还是属于共享库的清单?类的定义在xml中应该是什么样子


感谢您抽出时间,我希望我说得很清楚,这很让人困惑。

仔细阅读共享库清单中的评论:

<!-- The activity tag here is currently not used. The main project TicTacToeMain
         must currently redefine the activities to be used from the libraries.
         However later the tools will pick up the activities from here and merge them
         automatically, so it's best to define your activities here like for any
         regular Android project.
    -->

基本上,您需要将共享库清单中的所有活动复制到使用这些活动的应用程序中。基本上,将其添加到您的应用程序AndroidManifest.xml:

<activity android:name=".Preferences" android:label="@string/prefTitle"
        android:screenOrientation="nosensor">
        <intent-filter>
            <action android:name=".Preferences" />
            <category android:name="android.intent.category.PREFERENCE" />
        </intent-filter>
</activity>


我看到你实际上复制了这部分,但把它注释掉了。所以只需取消注释即可。

谢谢,对我有效的是该解决方案的一个变体,我需要定义完全限定的活动(向前引用的XML等价物)并取消对代码的注释。或者在
project.properties
中使用
manifestmerge.enabled=true
是的,这太棒了!剩下的一个错误是,如果在库项目中有活动
主启动器
,它将无法工作。。。