Как указать действие .Preference в файле manifest.xml действия библиотеки - PullRequest
1 голос
/ 02 декабря 2010

Я смоделировал свой код после примера приложения TicTacToe, поэтому моя установка состоит в том, что у меня есть Приложение, которое в основном представляет собой оболочку, запускающую обычное действие, которое находится в отдельном проекте затмения, помеченном как общая библиотека (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;

когда я нажимаю на настройки, я получаю START_INTENT_NOT_RESOLVED в методе execStartActivity () в Instrumentation.java. Глядя на намерение, которое execStartActivity пытается запустить, я вижу, что

mPackage="com.barrett.calendar" 
mClass="com.ifundraizer.calendar.library.Preferences"

и все остальное - ноль, что неудивительно.

мой вопрос:

Принадлежит ли определение действия предпочтений манифесту вызывающего действия или манифесту общей библиотеки и как должно выглядеть определение класса в xml?

спасибо за потраченное время, надеюсь, я был ясен, это очень запутанно.

1 Ответ

1 голос
/ 03 декабря 2010

Внимательно читайте комментарии в вашем общем манифесте lib:

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

Я вижу, что вы на самом деле скопировали эту часть, но закомментировали ее. Так что просто раскомментируйте.

...