我收到错误“您的应用程序正在使用PreferenceActivity类的不安全实现,这使得它们容易受到碎片注入的影响。”来自Google Play。
我已阅读https://support.google.com/faqs/answer/7188427?hl=en和Your implementation of PreferenceActivity is vulnerable to fragment injection
是否意味着PreferenceActivity类已经过时了?我该如何解决这个问题?
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.dodata.unlock"
android:versionCode="8"
android:versionName="1.08" >
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.android.vending.BILLING" />
<application
android:allowBackup="true"
android:icon="@drawable/unlockwithwifi"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="ui.UnlockMain"
android:launchMode="singleTop"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ui.UnlockAddWiFi"
android:label="@string/app_name">
<intent-filter>
<action android:name="ui.UnlockAddWiFi" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="ui.LockPreference">
<intent-filter>
<action android:name="ui.LockPreference" />
<category android:name="android.intent.category.PREFERENCE" />
</intent-filter>
</activity>
...
</application>
</manifest>
LockPreference.java
public class LockPreference extends PreferenceActivity{
private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.unlockpreference);
setContentView(R.layout.unlock_custom_preference);
adView=(AdView) findViewById(R.id.adView);
PublicParFun.SetAD(adView);
SetDisplayIcon();
Button btnClose=(Button)findViewById(R.id.btnClosePreference);
btnClose.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
}
...
}
unlockpreference.xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="AppPreference"
android:summary="@string/PreferenceSummary"
android:title="@string/Preference" >
<ui.custom.DialogChangePassword
android:key="ChangePassword"
android:dialogIcon="@android:drawable/ic_dialog_alert"
android:title="@string/ChangePasswordTitle"
android:summary="@string/ChangePasswordSummary"
android:positiveButtonText="@string/BtnSave"
android:negativeButtonText="@string/BtnCancel"
android:layout="@layout/unlock_custom_preference_item"
/>
<CheckBoxPreference
android:defaultValue="true"
android:key="DisplayNotificationIcon"
android:title="@string/DisplayNotificationIconTitle"
android:summary="@string/DisplayNotificationIconSummary"
android:layout="@layout/unlock_custom_preference_item"
/>
</PreferenceScreen>
答案 0 :(得分:0)
首选添加首选项的方法是在正常活动中使用首选项片段。使用框架布局创建常规活动并创建首选项片段,该片段将使用首选项屏幕显示首选项。 见https://developer.android.com/guide/topics/ui/settings.html#Fragment