In my app I need provide this screen for tablets.
So when I choose Setings from ListFragment I need add appropriative fragment to activity e.g. PreferenceFragment, but there is no PreferenceFragment in support library.
Is there any "legal" way to use PreferenceFragment in platforms olter than 11 API level? Of cause there are projects on GitHub, which adding PreferenceFragment to android.support.v4.app.. For example that.
But usage of project like this is a good idea or not? Is there a better way to accomplish this?
EDIT
However I use sw to provide differend screens and it starts from the 3.2 version e.g. API level 13 and PreferenceFragment starts from API level 11.
So as far as I see I think that will be enought provide PreferenceFragment for tablets and PreferenceActivity for handsets.
I guess these are what you might be looking for:
PreferenceFragment-Compat
Android-support-v4-preferencefragment
Related
I'm a newbie to Android Development. Even though I referred the android developer website, I didn't figure out.
On the customize Activity dialog box, when I unchecked the Backwards Compatiblity(Appcompat) in Android Studio 2.3.1 It gave me a hint as:
If false, this activity base class will be Activity instead of AppCompatActivity
Generally, what do android developers prefer? enabling backwards compatibility or without it? Can anyone explain me which one is better.
Android apps can be backward-compatible without checking this checkbox.
If false, this activity base class will be Activity instead of AppCompatActivity
Android studio is letting you know that if you uncheck the "Backwards Compatability(Appcompat)" box, then you'll be including & using the library Activity instead of AppCompatActivity.
For a more detailed comparison between the two, check this: Activity, AppCompatActivity, FragmentActivity, and ActionBarActivity: When to Use Which?
Generally, what do android developers prefer? enabling backwards compatibility or without it?
A comment written by "CommonsWare" explains this best:
An activity created with that checkbox checked is no more backwards compatible than is one without that checkbox checked. Checking the checkbox gives your app a particular look and feel that will retain that look and feel on some older devices; leaving the checkbox unchecked means that some aspects of your look and feel will be different on pre-Android 5.0 devices. This does not impact the core functionality of the activity, though. – CommonsWare
Backwards compatibility allows you to use certain backwards compatible features in your app. They will be able to work on previous versions of Android.
The Android Support Library offers backward-compatible versions of a number of features that are not built into the framework. (Android Support Library website)
For example, instead of Activity, AppCompatActivity will be used and is something that is "backwards" compatible. It can be used all the way back to API level 15.
You should generally use AppCompatActivity to support older Android versions. If your app has no need for older android versions, then just use Activity.
Using AppCompatActivity is generally more recommended.
i'm implementing viewpager in my app, it has 4 tabs. In the last tab i want to implement settings. If i look at the preferencefragment its not supported for devices below API 11. Even in android compat lib v7 also, this feature is not included. Looked at few alternatives like 3rd party libs which are not official. What is the best, efficient way to use this?
PreferenceFragment is supported for implementing application preferences beginning with API 11 (http://developer.android.com/guide/topics/ui/settings.html#Fragment). Prior to API 11, PreferenceActivity was used.
I have seen people struggle to implement PreferenceActivity for devices running older APIs while using PreferenceFragment for devices using newer APIs, in the same application.
Can anybody help me understand why we would bother to implement PreferenceFragment. Why not just continue to use PreferenceActivity? That is what I am doing in my application as of now.
I was doing what you were doing until I had an app that had so many preferences that I knew I needed to provide a two-pane layout, at least for tablet users. It looks way cleaner now, and on phones the left pane is full screen and behaves like a list of PreferenceScreens.
So I would say that it is worth using PreferenceFragments if you want to support two panes on tablets. But for most apps, there are not enough settings to justify using two panes at all, so it wouldn't be worth the effort to use PreferenceFragments. It definitely was a pain to get it working correctly and still support pre-v11. It's too bad PreferenceActivity and PreferenceFragment are not in the compatibility library...
I have a BaseFragmentActivity that all my activities extend. I would like to createa PreferencesActivity and take advantage of Androids preferences.xml capabilities, but obviously I cannot extend both classes.
I know newer APIs provide the use of PreferenceFragments but I want to offer support to legacy Android versions (from 2.3 and above).
How can I make use of the Preferences structure and extend my own base class (which has a few functionalities I need for all activities).
Seems it's not possible to use PreferenceFragment now on older versions (here some discussion about it). However, here some link to xda-developers for creating Your own for older versions (but it's pretty hacky).
I have defined dialogfragments (because Android documentation says that it is better and indeed it is) but now I want to use it in PreferenceActivity.
The problem is that I cannot use getSupportFragmentManager() there and I cannot use PreferenceFragment since it doesn't work with compatibility library. Looks like a road block scenario.
Can anyone advise on this?
As you noted, PreferenceFragment is not in the android compatibility package and unfortunately there is no clean way around this. For my own personal project, I had to adapt an implementation off of Android's source code:
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.4_r1.2/android/preference/PreferenceFragment.java
The answers to this question have some great suggestions:
Was PreferenceFragment intentionally excluded from the compatibility package?