How do I specify a .Preference activity in the manifest.xml of a library activity

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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



This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




1 Answer
1



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-filer>
<action android:name=".Preferences" />
<category android:name="android.intent.category.PREFERENCE" />
</intent-filer>
</activity>



I see that you actually copied this part, but commented it out. So just uncomment it.





thank you, what worked for me was a variant of that solution, I needed to both define the fully qualified activity ( the XML equiv of a forward reference ) and uncomment the code.
– user330844
Dec 3 '10 at 9:45





Or using manifestmerger.enabled=true in project.properties
– ChristopheCVB
Nov 28 '12 at 4:54


manifestmerger.enabled=true


project.properties





@ChristopheCVB, yes, now we can use manifest merger feature.
– inazaruk
Nov 28 '12 at 19:26





Yep, it's so great ! One bug left is if you have the Activity Main Launcher in Library project, it won't works...
– ChristopheCVB
Nov 30 '12 at 5:35


Main Launcher






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results