How do I specify a .Preference activity in the manifest.xml of a library activity
I modeled my code after the TicTacToe sample application, so my setup is that I have an Application which is basically a shell that starts a common Activity which is in a separate eclipse project flagged as a shared library ( properties->IsALibrary ). I have add the the library to the calling activity's properties. I invoke the shared library code as follows:
private void startGame()
{
Intent i = new Intent( this, calendar.class );
startActivityForResult( i, START_APPLICATION );
}
my AndroidManifest for the calling activity is as follows:
<?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>
the AndroidManifest for the shared library is as follows:
<?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>
I define my menu in the shared library code's Activity class and invoke it as follows:
case MENU_SETTINGS:
Intent intent = new Intent().setClass( this, Preferences.class );
this.startActivityForResult( intent, 0 );
return true;
when I click on settings I get START_INTENT_NOT_RESOLVED in the method execStartActivity() in Instrumentation.java. Looking at the intent that execStartActivity is trying to start I see that
mPackage="com.barrett.calendar"
mClass="com.ifundraizer.calendar.library.Preferences"
and everything else is null, not surprisingly.
my question is:
Does the definition of the preferences activity belong in the开发者_如何学Python calling activity's manifest or in the shared library's manifest and what should the definition of the class look like in xml?
thank you for your time, I hope I was clear, this is very confusing.
Read carefully comments in your shared lib manifest:
<!-- 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.
-->
Basically you need to copy all activities from you shared library manifest to the application that uses those activities. Basically add this to your application 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>
I see that you actually copied this part, but commented it out. So just uncomment it.
精彩评论