Android – specifies the targetpackage for the intent in the XML file of the library project

I have a library project. I use it to build two applications, one public and one private, for personal use. Almost no settings are useless to most people. In this library project, I define a preferenceactivity (for API < honeycomb) and some preferencefragments (for API > = honeycomb), Use the preferences title of this guide: http://developer.android.com/guide/topics/ui/settings.html#BackCompatHeaders

In order to support old devices, I defined this XML file, as shown in the guide:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
    <Preference 
        android:title="@string/base_de_donnees"
        android:summary="@string/summary_pref_restaurer_bdd_sd">
        <intent
            android:targetPackage="com.me.app_lib"
            android:targetClass="com.me.app_lib.activities.preferences.SettingsActivity"
            android:action="com.me.app_lib.activities.preferences.SettingsActivity.ACTION_PREF_BDD" />
    </Preference>

   <Preference 
       android:title="@string/saisie"
       android:summary="@string/summary_pref_saisie">
       <intent
           android:targetPackage="com.me.app_lib"
           android:targetClass="com.me.app_lib.activities.preferences.SettingsActivity"
           android:action="com.me.app_lib.activities.preferences.SettingsActivity.ACTION_PREF_SASISIE" />

   </Preference>
</PreferenceScreen>

Including com.me.app_ Lib is the package of the library project, in which settingsactivity is defined. However, when intent is called from one of the subprojects, I encounter a crash because the targetpackage does not match the target of the subproject. If I call com.me.app_ Change lib to com.me.app_ Public (package of one subproject), which can work, but since I have two subprojects, this is not an option

Do I have to copy this file to each subproject and change only the targetpackage line, or do I have a better choice?

resolvent:

The last thing I did was put com.me.app_ Lib is defined as the resource string. The Android: targetpackage attribute changes to:

android:targetPackage="@string/package_activity_preferences"

Then I can define a different value in the two subprojects of this string. This is not as clean as I want, but at least I don't need to copy and paste the same file in the two subprojects. Targetclass is a part of my library project, so I don't need to change any of its contents; Only the targetpackage attribute has a problem

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>