Click here to Skip to main content
13,201,763 members (72,801 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 19 Jul 2013

Write Code for Different Android Versions in Your App

, 19 Jul 2013
Rate this:
Please Sign up or sign in to vote.
Simple approach to handle fragmentation


Fragmentation has been a big issue in Android since the beginning and everyone has different views about it. I personally don't think that there is an effective way to avoid fragmentation at the rate Android is growing at. So, fragmentation is something we should, as devs, adapt to in our developer frame of mind. 

Using the code

I know, we can always publish different apks to handle different android versions, but this may not be the optimal choice in all cases. So, here is little code snippet showing how to handle fragmentation to a certain extent in Android: 

    public boolean onCreateOptionsMenu(Menu menu) 
            //Write code specific for Gingerbread devices 
            //Write code specific for HONEYCOMB devices
            //Write code specific for ICE_CREAM_SANDWICH devices
        else if(Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN)
            //Write code specific for JELLY_BEAN devices
        return true;

The above code is just a simple example, that shows how you can create different menu options for different Android versions. Let me know in the comments, if you guys have any questions/suggestions. 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Amanpreet Mukker
Software Developer
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 4 Pin
ridoy19-Jul-13 20:11
memberridoy19-Jul-13 20:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171020.1 | Last Updated 19 Jul 2013
Article Copyright 2013 by Amanpreet Mukker
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid