DialogFragment in PreferenceActivity - android

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?

Related

How to use a PreferenceFragment in a FragmentPagerAdapter (android.support.v4)?

In my MainActivity, I am using a android.support.v4.view.ViewPager with a android.support.v4.app.FragmentPagerAdapter. I have seen many questions like this one, except the answers say to use android.support.v13.app.FragmentPagerAdapter, which is now deprecated. What is the current, proper, up-to-date answer of how to include a android.preference.PreferenceFragment inside a android.support.v4.app.FragmentPagerAdapter?
Note: My minimum sdk version is 16.
Note 2: I'd prefer to use only android/google provided libraries, if possible.
I have no idea if this is possible, but can the PreferenceFragment be shown inside an android.support.v4.app.Fragment to combat this issue?
You can use the android.support.v7.preference.PreferenceFragmentCompat as an alternative to PreferenceFragment that works with the android.support.v4.app.FragmentPagerAdapter as discussed in this Google+ post
It is part of the v7 Preference Support Library.

Android usage PreferenceFragment in old platforms

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

How do I use tabhost?

I tried to use almost all examples and source code from internet and all of them just doesn't work. I got this warning "The type TabActivity is deprecated", anyone have source code for Tabhost that is really working and doesn't crash?
You should not be using Tabs anymore. Look after Fragments instead. a good place to start is
http://developer.android.com/guide/components/fragments.html
From the documentation for TabActivity:
This class was deprecated in API level 13.
New applications should use Fragments instead of this class; to continue to run on older devices, you can use the v4 support library which provides a version of the Fragment API that is compatible down to DONUT.
You should learn how to use Fragments instead. TabHost/TabActivity isn't being actively supported any more, so if you're just learning how to do tabs, you should do it the new way. No point in learning something, only to have to replace it anyway.
From the link here:
This class was deprecated in API level 13.
New applications should use Fragments instead of this class; to continue to run on older devices, you can use the v4 support library which provides a version of the Fragment API that is compatible down to DONUT.
So the suggestion is obvious - use Fragments. But don't ask here how, create a new Question.
go through the link:http://developer.android.com/training/backward-compatible-ui/abstracting.html Download the Sample App: TabCompat.zip

Why is TabActivity deprecated (reason)?

This is not a duplicate of How can I use fragments, now that TabActivity is deprecated?
After some research the conclussion is that TabActivity is deprecated because we now have to use fragments. And the reason for that, as far I read, is that fragments work better with the action bar, and with the support compatibility library it's also possible to implement starting at Android 2.1
But I still don't really understand the reason why it's deprecated. Why not just make that the action bar also works with activities? Why are fragments prefered?
I also read fragments have better performance... is that the reason?
Activities at least are cleary separated entities which is something positive. I don't have enough insight in fragments now to understand why they are better.
Thanks in advance...
TabActivity has been deprecated, cause it is subclass of ActivityGroup, which also has been deprecated.
ActityGroup has been deprecated, and instead Fragment has been introduced and suggested. As using Fragments is easier and more flexible than ActivityGroup. It also enable android components to have a homogeneous pattern.
The main reason for which Google deprecate some methods / objects is to enforce best-practices and get the most homogeneous patterns accross applications.
Marking TabActivities as deprecated will make developpers use the ActionBar system for new applications, but you still can use TabActivities, although it's not encouraged.
Sometimes, They will mark something as deprecated for performance or because the behavior is not up to date with the latest API (for example the Clipboard system, changing from a "text only clipboard" to a "copy and paste anything".

On Android's Support Package, use it or not?

I've been thinking about the pros and cons of using Android's Support Package when targeting the latest API and setting the min SDK to 7, for example.
The Android documentation states "The goal is to simplify your development by offering more APIs that you can bundle with your application so you can worry less about platform versions"; however, I'm having some doubt on whether it will make it simpler.
Consider the TabActivity, which has been deprecated. The alternative to using TabActivity is through Fragments and by looking at the example to get a tabular view working, it doesn't look simpler. Besides, I have to use reflection anyways when deciding on to use the Fragments class versus the FragmentActivity class, so why not just use TabActivity. I was hoping to get your opinion on this. I'm leaning towards not using it, but I would like to know if I'm missing out on any benefits.
The alternative to using TabActivity is through Fragments
An alternative to using TabActivity is through Fragments, using the icky stuff in the example you cite. The better alternative to using TabActivity is to put your tabs in the action bar, perhaps using ActionBarSherlock's fork of the Android support library that offers a backwards-compatible action bar.
by looking at the example to get a tabular view working, it doesn't look simpler
It's not.
Besides, I have to use reflection anyways when deciding on to use the Fragments class versus the FragmentActivity class
If you are using the Android support library, you should not need this, as you always extend FragmentActivity.
I'm leaning towards not using it, but I would like to know if I'm missing out on any benefits.
If you plan on supporting tablets and/or TVs, you want to be using fragments. Fragments are useful even in phone-only apps, but not quite as visibly.

Categories

Resources