Organize Imports (Listing 6.2)


#1

After typing:

ActionBar actionBar = getActionBar();

I pressed Ctrl=Shift-O. I then see the Organize Imports dialog. In it I have a choice between the following:

android.app.ActionBar
android.support.v7.app.ActionBar

Would someone be able to explain why I have this choice and what I may want to choose?


#2

Generally you should use the first one.

From what I understand, the second version of ActionBar is from the Android “support” library, which backports features from the newest SDK to older Android versions. It is not part of the core SDK that the phone comes with, but you can bundle it with your app. This lets you “cheat” and use newer API features on older phones that otherwise wouldn’t support it. It’s an alternative to doing what the book suggests, i.e. doing an SDK version check and not including the new features if the runtime API version doesn’t support it.

See https://developer.android.com/tools/support-library/index.html