Wednesday, November 21, 2012

getActionBar and targetSdkVersion in Android development

Hi All,

Recently I was trying to reiterate Android docs training just to fill in anything I missed previously. There I came across this piece of code:

     // Initialize member TextView so we can manipulate it later  
     mTextView = (TextView) findViewById(;  
     // Make sure we're running on Honeycomb or higher to use ActionBar APIs  
       // For the main activity, make sure the app icon in the action bar  
       // does not behave as a button  
       ActionBar actionBar = getActionBar();  

I tried to put that in a simple hello world example and it worked on an 2.2 emulator, however it failed to run on 4.0 emulator. On debugging it turned out that getActionBar was returning null value. Though there was on-line help available for some other directions it just came to my mind to check AndroidManifest.xml file. There I saw only "android:minSdkVersion="8"" I remembered that there was a target SDK  as well which can be defined. So I checked a project created by eclipse and found the "android:targetSdkVersion="15"" line and added it to "uses-sdk " tag in AndroidManifest.xml and the app started working on 4.0 emulator.

This clears two things, first is that Idea IDE adds only minSDKVersion while eclipse adds targetSDKVersion as well. Which is reflected in new project also but could effect like this.

Second, if you search for getActionBar returning null you get loads of advice but maybe not this. So check if you are having this issue.

Thanks for reading. Thanks for Android guys for creating such a good documentation, which by and large so much better than Facebook developer docs. Only wish Facebook docs were also as clear as the Android docs.


  1. Thanks for this programming tutorial. Yes Android has a good documentation

  2. Well great post you have written for android OS. Thanks
    Mobile Apps Development india

  3. hey, thanks for providing this code to us..well written post.
    technical consulting services

  4. hey admin .. Nice post about Android development and I m also thankful to you for providing this programming script.. keep sharing..!!!

    IT Consulting Services

  5. Never known before, looks like some useful Android functions

  6. Tutorials written by you are awesome, they are easy to understand as well as easy to implement. just a piece of code implemented on my app.

  7. Congrats for making it possible for creating this blog. I may not always visit this blog to see more updates but i will consider every valuable information i read here. Please keep up the good work and good luck for the upcoming post.

    Way2sms login

  8. Thanks for sharing this code with us. It is really helpful for developers..
    web application development service