Question

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" />
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top