2

I know there are already quite a lot of blog entries, how to's, questions out there that cover backward compatibility of Android 3.0 apps.

However, after reading them all I'm just more confused than before. :(

What I have is a Smartphone app that supports min. SDK version 8 (2.2).

I now want this one to stay the same on Smartphones, but also provide a fancy version on Honeycomb Tablets with Action Bar and Fragments and so on.

I know there is the compatibility pack, but all I read about it was about Fragments. What's with the Action Bar and the holographic Theme? I did get this pretty nice and easy just by changing the targetSdkVersion to "11" on my Tablet. How could I reach this with the compatibility pack?

Or would you say it's better to develop two different versions of the program? (And maybe merge them together later?)

Kind regards, jellyfish

Community
  • 1
  • 1
jellyfish
  • 7,868
  • 11
  • 37
  • 49
  • Try this link: http://www.android-dev-faq.com/2011/12/how-to-create-action-bar-for-smartphone.html –  Dec 29 '11 at 22:23

2 Answers2

5

Keep one apk and just use alternative resources for your Tablet.

Take a look at:

http://code.google.com/p/iosched/source/browse/#hg%2Fandroid%2Fres

This show's you the directory structure of how to target SmartPhones and Tablets (with honeycomb) in the same APK.

EDIT

fancy version on Honeycomb

using Fragments won't change your UI in honeycomb it's just a way to re-use code. So you don't need Fragments to make your UI 'fancy'

EDIT 2

To find the current running Android version you can do something like

int b = Integer.parseInt(Build.VERSION.SDK);              
if(b >= Build.VERSION_CODES.HONEYCOMB){
      Log.i(TAG, "Found A Tablet Running Honeycomb or newer");                  
 }

EDIT 3

in your Activity call getActionBar(); you then have access to all action bar methods stated here: http://developer.android.com/reference/android/app/ActionBar.html

Blundell
  • 75,855
  • 30
  • 208
  • 233
  • /layout-xlarge-v11/ is saying layout file - X Large screens (7inch+) - version 11 which is HoneyComb. So i.e. use the layout in this folder when loading on a tablet – Blundell May 27 '11 at 11:52
  • But together with the compatibility pack, right? http://code.google.com/p/iosched/source/browse/android/res/layout-xlarge-land-v11/activity_home.xml -> otherwise, there couldn't be a "fragment", could it? – jellyfish May 27 '11 at 11:53
  • You could use fragments within the layout files if you want, and yes you would need the fragment library. – Blundell May 27 '11 at 11:54
  • Thank you! You don't by a chance know how a main activity should look like then? I guess I'd have to check first which android version is supported and then provide two different "ways" of following activities. Is that right? Is there an example somewhere? – jellyfish May 27 '11 at 11:58
  • @Edit: I know, but I want to re-design my app for tablet. E.g. I have a main menu from which I start other activities. On 3.0 I want it to stay on the left all the time and provide the selected activity on the right. I thought that's something I could only achieve with fragments? – jellyfish May 27 '11 at 12:00
  • 1
    It is recommended with fragments. As you say the other way to do it, is when the class loads (with an Intent etc) check the SDK version and if(Tablet) run HomeActivityTablet.java else HomeActivity.java – Blundell May 27 '11 at 12:03
  • Thanks Blundell, for your effort! Only question left is how to access the ActionBar/Holo Theme. In the docu it says "...more specifically, all activities that use the new "holographic" theme include the Action Bar, and any application that targets Android 3.0 automatically receives this theme. ... However, if you want to use Action Bar APIs, such as to add tabs or modify Action Bar styles, you need to set the android:minSdkVersion to "11", so you can access the ActionBar class." – jellyfish May 27 '11 at 12:07
  • 1
    Erm in your Activity call getActionBar(); you then have access to all action bar methods stated here: http://developer.android.com/reference/android/app/ActionBar.html – Blundell May 27 '11 at 12:11
  • And don't forget to mark the question as answered :-D (green tick) – Blundell May 27 '11 at 12:14
2

There was a talk on this very subject at Google IO this year. Now available on YouTube http://www.youtube.com/watch?v=WGIU2JX1U5Y&feature=youtube_gdata_player

Damian
  • 8,062
  • 4
  • 42
  • 43
  • 1
    And available on your phone: https://market.android.com/details?id=com.blundell.googleio.free :-) – Blundell May 28 '11 at 12:22