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

    private void startGame()
    {
 Intent i = new Intent( this, calendar.class );
 startActivityForResult( i, START_APPLICATION );
    }


我用于呼叫活动的AndroidManifest如下:

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


共享库的AndroidManifest如下:

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


我在共享库代码的Activity类中定义菜单,并按以下方式调用它:

case MENU_SETTINGS:
     Intent intent = new Intent().setClass( this, Preferences.class );
     this.startActivityForResult( intent, 0 );
     return true;


当我单击设置时,在Instrumentation.java中的execStartActivity()方法中得到START_INTENT_NOT_RESOLVED。查看execStartActivity试图启动的意图,我看到了

mPackage="com.barrett.calendar"
mClass="com.ifundraizer.calendar.library.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-filer>
            <action android:name=".Preferences" />
            <category android:name="android.intent.category.PREFERENCE" />
        </intent-filer>
</activity>


我看到您实际上复制了此部分,但是将其注释掉。因此,只需取消注释即可。

关于android - 如何在库 Activity 的manifest.xml中指定.Preference Activity ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4339785/

10-09 07:30