I am writing an app for android (2.1 > 3.1) and I would like to use the familiar practice of using the app Icon in Honeycomb apps to go up to the home activity, however, when I run the activity on earlier, non Honeycomb devices where the Activity.getActionBar(); method does not exist yet, the app force closes, how can I only run this specified code if the device is running honeycomb?
@Override
protected void onStart() {
super.onStart();
ActionBar actionBar = this.getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
Thanks for any help and have a great day.
I have written a library for Android which will automatically wrap your pre-3.0 activities with a custom implementation of the action bar design pattern. You can then call getSupportActionBar()
which will provide a common interface for both the native and custom implementations, depending on which version of Android your application is running on.
The library also allows you to apply custom styles to both of these action bars through a single theme.
You can find out more information as well as screenshots of sample applications at actionbarsherlock.com.
The library is 100% open source and available at github.com/JakeWharton/ActionBarSherlock.