我在TicTacToe示例应用程序之后对我的代码进行了建模,所以我的设置是我有一个Application,它基本上是一个shell,它启动一个公共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中应该是什么样的?
谢谢你的时间,我希望我很清楚,这很令人困惑。答案 0 :(得分:1)
仔细阅读共享库清单中的注释:
<!-- 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>
我看到你实际上复制了这部分,但评论了它。所以只是取消注释。