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
Related
from some of the answer such as
Using getFragmentManager() vs getSupportFragmentManager()?
I find that getFragmentManager() is used for API>=14,
and getSupportFragmentManager() will be used in support lib such as v4 which also support older API.
So my question is should I just use getSupportFragmentManager (import the support.v4 for each classes) so that my application can be used in any API version?
And are there any different I should know between these 2 FragmentManager?
If you are interested in supporting API versions that do not have Fragments, then by all means use the FragmentActivity and getSupportFragmentManager() patterns.
Even if you are not targeting an API below 14, it may be a good idea to use the support library. Classes in the support library can be updated by you, the developer, whenever Google releases a bugfix/feature in the library that you are interested in. If you use a framework class, you only get the updates when your users get a firmware update, which we all know can take a while. Using the support library means all users are using the same "latest-and-greatest" classes.
Yes, for Fragment, just use getSupportFragmentManager, then your app for Fragment can be compatible backward to old API levels, normally minSDKversion = 7 is enough. However if you really want your app to get compitability with most API levels, then there still many other components your app concerning need use support library, such as ActionBar, etc..
For more info, please go through Android Docs: Support Library Features
I am new to Android development and I am following the training at http://developer.android.com to get into it. I am confused whether I do use the support library or not.
To make it clear: I do not need to support APIs older than 11.
Situation: Adding Items to the ActionBar I had to use my own Namespace to make it work (app:showAsAction="ifRoom" instead of android:showAsAction="ifRoom"), which is a normal behaviour using the support-lib, am I right?
First Question: Why am I using it? I did never activate it on purpose!
Second Question:
Is it normal that I can use both getActionBar().setDisplayHomeAsUpEnabled(true); and getSupportActionBar().setDisplayHomeAsUpEnabled(true); to make the "up"-functionality work? I thought the first one wouldn't work if I used the support-lib?
I'd be glad if one of you could help me. I don't want to mess around with these basics so I'd like to know what I understood or configured wrong.
EDIT: My "uses-sdk" in the AndroidManifest actually looks like this:
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="19" />
To answer your first question, depending on how you created your project in the first place, it was probably enabled for you automatically. There are lots of other things in the support library besides ActionBar, so even if your minSdkVersion=11, it's probably still a good idea to use it.
To answer your second question, yes, it's normal that both methods work. Framework methods are not disabled or removed when you enable the support library. They will still work as long as they are supported by the Android OS you're eventually running on. For example, if your minSdkVersion was 10 instead of 11 and you tried to run the app on a device running Gingerbread, it would crash on the getActionBar() call.
In your case, you should use the framework method (getActionBar()). The documentation for ActionBar says:
This class is included in the support library for compatibility with
API level 7 and higher. If you're developing your app for API level 11
and higher only, you should instead use the framework ActionBar
class.
The best way to know whether you need to use the support library for a given method or class is to refer to the documentation for that class and pay attention to the "Added in API Level ?" notation. Here is the documentation non-support-library version of ActionBar, where you can see that some methods were added after API 11. If you need any of those methods, you should use the support library.
Also, as I said before, there other things besides ActionBar to consider in your app. GridLayout is an example. It was added in API 14, but it also exists in the support library for backwards compatibility. If you want to use GridLayout, you should use the support library version of it.
"The type TabActivity is deprecated"?
I am making the Tabs of app following tutorial book.
I've checked from the android developer.com website, but i have no ideas on the significance of the following message : This class is deprecated.
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."* (http://developer.android.com/reference/android/app/TabActivity.html)
What is v4 support library?
How to finish the tab functions?
You can still use a deprecated package. It is however recommended to use Fragments, and thus the support package. You can read more about it here. However, if you are a beginner at java and android development, I would recommend ignoring the deprecation for now and come back to this when you have completed the tutorial you are currently using if you find it educating.
If you want to watch a nice example of tabbed navigation using Fragments, then create a new project in Eclipse using android 4.0 or later. Make sure your android-plugin is updated. You will get the option to create a project with basic navigation already implemented.
"Deprecated" means that the api developers don't recommend using it anymore, probably because its not a good model, or inefficient, etc. Fragments were introduced in Honeycomb and can be used to provide a similar functionality as tabs and is more in-line with android's current design philosophy.
Since Fragment was introduced in Android 3.0 Honeycomb, you might think you cannot use that for pre-Honeycomb devices. Enter Support Libraries. They are libraries which you can include in your application which needs to run on pre-Honeycomb and still use this class.
So if you want to, you can finish the TabActivity as described in whatever tutorial you are following, it'll probably work on a few more upcoming android versions. But it is recommended that you start using Fragments.
I'm trying to offer tab support for all Android versions 2.2 and above. Is there a way of achieving this without using any deprecated classes/methods?
The Problem is as following:
TabActivity is deprecated because it derives from ActivityGroup which is deprecated, too. Problems are, to start Activitys inside Tabs and don't break callbacks like onActivityResume. There are some 'Hacks' around which solve this but they are ALL relying on the deprecated LocalActivityManager. So I see no solution of using Tabs without ANY deprecated calls. Since Android 3.X google invented Fragments for this kind of things which are supported on lower Versions with the SupportPackage. You should definetly try them in Combination with the new ActionBar if you want to avoid deprecated classes/methods
EDIT:
Link to FragmentTabs for further reference
I recon with with the answer Rafael gave.
Instead of resorting to the TabActivity you can sill use the regular TabHost to show tabs in all versions of android.
Am I missing something important in this, or do you have to maintain a seperate version of all your fragments for the backported classes, and for the native honeycomb fragments?
-- Attempting to use the backported fragments on honeycomb was expected to do a fall-through and use the native, not crash because of a ClassCastException
Any help would be greatly appreciated.
You should only need to extend the Fragment classes provided for you in the JAR file that comes with the Compatibility plug-in. No need to maintain two classes for both platforms.
Take a look at the API Demos example that comes with the compatibility download, specifically the FragmentLayoutSupport demo.
Incidentally, what is the ClassCastException you are seeing?
for me in this situation helped a simply replacing rows:
setContentView(R.layout.buttons_fragments);
super.onCreate(bundle);
on
super.onCreate(bundle);
setContentView(R.layout.buttons_fragments);
Oh my, well don't I feel silly.
Found the problem -- I was running a preview version of the emulator, I never remembered to delete it and replace it with a level 11 instance -- works fine in the final Honeycomb emulator.