68

<intent>タグを使用して、デフォルトのpreferences.xmlからアクティビティを開始したいと思います。アクティビティは十分にテストされていますが、問題はそれではありません。(アプリでPreferenceActivityを拡張しているので、preferences.xmlはそれに「付属」しています)コードを見てください。何が問題になっていますか?

Preferences.xml:

.... 
<PreferenceCategory 
    android:title="@string/titleEtcSetup">
    <PreferenceScreen
        android:key="renameCourses"
        android:title="@string/titleRenameCourses"
        android:summary="@string/textRenameDisplayedCoursesNames">
        <intent
             android:action="android.intent.action.VIEW"
             android:targetPackage="my.notifier.ui"
             android:targetClass="my.notifier.ui.EditCoursesNamesActivity" />         
    </PreferenceScreen>
.....
</PreferenceCategory>
..... 

マニフェスト.xml:

....
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.notifier.ui"....
....
<activity android:name=".EditCoursesNamesActivity" android:label="@string/titleRenameCourses">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
 .....

「renameCoursesアイテム」を押してもアクティビティが呼び出されません。何も起こりません。LogCatは「クリア」であり、エラーや警告はありません。たくさん検索していましたが、解決策が見つかりませんでした。何かを逃しただけかもしれません...助けてください!

4

12 に答える 12

66

私は同じ問題を抱えていました。AndroidManifest.xml でアクションを宣言するだけで、次のように機能するようになりました。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.myapp" android:versionName="1.3" android:versionCode="4">

...

    <activity android:name=".activities.MyActivity" 
              android:label="@string/my_activity_title"
              android:theme="@android:style/Theme.Black.NoTitleBar">
        <intent-filter>
           <action android:name="com.example.myapp.activities.MyActivity" />
           <category android:name="android.intent.category.DEFAULT" />
       </intent-filter>
    </activity>

次に、設定xmlファイルで:

<PreferenceCategory
        android:title="@string/my_activity_title">
    <PreferenceScreen
        android:title="@string/my_activity_title" 
        android:summary="@string/my_activity_title">
        <intent android:action="com.example.myapp.activities.MyActivity"/>
    </PreferenceScreen>
</PreferenceCategory>
于 2012-05-04T01:58:36.070 に答える
52

タグはではなく<intent>内にある必要があると思います。<Preference><PreferenceScreen>

<PreferenceCategory 
    android:title="@string/titleEtcSetup">
    <Preference
        android:key="renameCourses"
        android:title="@string/titleRenameCourses"
        android:summary="@string/textRenameDisplayedCoursesNames">
        <intent
             android:action="android.intent.action.VIEW"
             android:targetPackage="my.notifier.ui"
             android:targetClass="my.notifier.ui.EditCoursesNamesActivity" />         
    </Preference>
.....
</PreferenceCategory>
于 2011-09-01T20:09:45.183 に答える
35

注意!の値は、ファイルのルート要素 (Gradle ビルド ファイルで定義) でtargetPackage宣言されているように、アプリのパッケージ ID にする必要があります。AndroidManifest.xmlActivity クラスの Java パッケージと同じである必要はありません (通常は のサブパッケージに入れます"ui")。

したがって、あなたの特定のケースでは、そうではないtargetPackageはずです(確実にマニフェストを確認する必要があります)。"my.notifier""my.notifier.ui"

于 2013-05-18T00:07:36.577 に答える
22

IntentFilter を追加する必要はありません。アクティビティは完全修飾名で参照できます。

<intent android:targetPackage="my.notifier.ui"
    android:targetClass="my.notifier.ui.EditCoursesNamesActivity"/>
于 2014-02-13T06:52:26.653 に答える
4

この問題が発生したのは、アクティビティのサブパッケージを作成したためです。ルートパッケージに移動すると、設定画面で起動できました。

于 2011-10-06T08:07:07.453 に答える
3

このソリューションは、アクティビティを設定ヘッダーに接続する方法を示しています。

まず、ターゲット アクティビティを次のようにマニフェストで宣言する必要があります。

<activity android:name=".ui.activities.MyActivity">
    <intent-filter>
        <action android:name=".ui.activities.MyActivity" />
        <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

ここで、アクティビティとアクションの android:name が同じであることに注意してください。

これで、preferences.xml ファイルで、次のようなヘッダーを宣言するだけで済みます。

<header
    android:title="@string/my_activity_title"
    android:summary="@string/my_activity_summary">
    <intent android:action=".ui.activities.MyActivity"/>
</header>

それだけです。

于 2013-01-19T19:18:42.330 に答える
2
<Preference>
    <intent
        android:targetPackage="applicationIdFromBuildGradle"
        android:targetClass="targetClassFromJavaFile.YourClassName"/>
</Preference>
于 2019-08-29T10:18:02.560 に答える
1

インテントフィルターのカテゴリーをから変更することでこれを修正することができました

android.intent.category.DEFAULT

android.intent.category.PREFERENCE

http://developer.android.com/reference/android/content/Intent.html#CATEGORY_PREFERENCE

<activity
  android:name=".ui.DatapackSelectionActivity"
  android:label="@string/app_name"
  android:screenOrientation="portrait"
  android:theme="@android:style/Theme.NoTitleBar" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.PREFERENCE" />
    </intent-filter>
</activity>

アクションをさらに具体的にしたい場合は、カテゴリノード全体を削除するだけだと思います

<activity
  android:name=".ui.DatapackSelectionActivity"
  android:label="@string/app_name"
  android:screenOrientation="portrait"
  android:theme="@android:style/Theme.NoTitleBar" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
    </intent-filter>
</activity>
于 2012-05-25T15:02:23.407 に答える
1

パッケージ名のリファクタリングにより、targetPackage と targetClass(prefix) が異なる場合があります。簡単に確認するには、マニフェストでアクティビティを削除して呼び出すとstartActivity()、logCat に「明示的なアクティビティ クラス {'targetPackage'/'targetClass'} が見つかりません」というエラーが表示されます。これらは、Preference>intent に書き込むべき正しい名前です。インテントフィルターは必要ありません。

于 2015-12-02T10:33:31.357 に答える