Alternative to addPreferencesFromResource as its deprecated

前端 未结 1 761
清歌不尽
清歌不尽 2020-12-09 10:59

I create Preference activity on my app to allow user to start/stop background splash screen music as follow :

public class Prefs extends PreferenceActivity{
         


        
相关标签:
1条回答
  • 2020-12-09 11:54

    PreferenceActivity is not deprecated.

    addPreferencesFromResource() on PreferenceActivity is deprecated. However, if you are supporting API Level 10 or lower, you have no choice but to use it, at least on those devices.

    The non-deprecated approach is to use PreferenceFragment in conjunction with PreferenceActivity, as is described in the PrefereceActivity documentation. If your app is only supporting API Level 11 and higher, just use that. If your app is supporting older devices, either:

    • Use addPreferencesFromResource() all the time, as it still works, until you drop support for the older versions, or

    • Use addPreferencesFromResource() only on the older devices (by checking Build.VERSION.SDK_INT), and rely on the new fragment-based system on newer devices

    0 讨论(0)
提交回复
热议问题