Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6004645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:17:32+00:00 2026-05-23T01:17:32+00:00

I am getting back to work on an app I worked on a while

  • 0

I am getting back to work on an app I worked on a while ago, when I had everything built around Android 2.2 Froyo.

I have updated my SDK for the latest APIs and noticed that the ClipboardManager features I was using are deprecated. I updated the code to use the newer ClipData model and tried it out on my Froyo phone and, of course, I get a NoClassDefFoundError in the new code.

I’ve had a look around SO and haven’t found any real discussions of general strategy for maintaining backwards compatibility.

I’m not entirely sure how I should handle this and other situations where the API differs, because I want users of all versions to be able to use my app.

Should I be doing a check as follows?

if(version == old){
   use old API;
} else {
   use new API;
}

If so, I have deprecated code in my class and Eclipse will have the warning there forever.

On the other hand, I could just build against an old version of the API and hope that new versions will handle it okay. But then I run the risk of building against buggy or low-performance code when a better alternative is available.

What is the best way to deal with this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:17:32+00:00Added an answer on May 23, 2026 at 1:17 am

    You can do that (checking the API version).

    You can also use reflection to call the newer classes.

    I wouldn’t worry about using deprecated methods as all Android versions are backwards compatible, saying that you want to watch when things are for 3.0 Honeycomb as these are a little different.

    Here’s an explanation of how to use reflection: (yes it’s been on SO before, so maybe search for reflection)

    http://www.youtube.com/watch?v=zNmohaZYvPw&feature=player_detailpage#t=2087s

    I’m looking at making the project this is in available but until then here’s some code:

    (You could do this in a class that extends Application i.e. one time setup)

     public static Method getExternalFilesDir;
    
        static {
                try {
                        Class<?> partypes[] = new Class[1];
                        partypes[0] = String.class;
                        getExternalFilesDir = Context.class.getMethod("getExternalFilesDir", partypes);
                } catch (NoSuchMethodException e) {
                        Log.e(TAG, "getExternalFilesDir isn't available in this devices api");
                }
        } 
    

    Now getExternalFilesDir() is only available on API level 8 or above, so I want to use this if they have (Froyo), but otherwise I need another method.

    Now I have my test for the method I can go ahead and attempt to use it:

      if(ClassThatExtendsApplication.getExternalFilesDir != null){
                Object arglist[] = new Object[1];
                arglist[0] = null;  
                File path = (File) ClassThatExtendsApplication.getExternalFilesDir.invoke(context, arglist);
               // etc etc
      } else {
          // Not available do something else (like your deprecated methods / or load a different class / or notify they should get a newer version of Android to enhance your app ;-))
      }
    

    Hope that helps and shortcuts a lot of googling 🙂

    P.S. if in the else you want to use your deprectated methods still, just add the @SuppressWarnings("deprecation") annotation above it, This will get rid of the warning and you have done it for the right reasons as you are using the latest API’s when possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A while back, my android map app stopped getting Google Satellite tiles. Now that
I have been sharpening the coding knives and getting back into dev. A few
On 10.7.2 I have trouble getting standard NSDistributedNotifications to work out of the box.
I’m having trouble getting a AJAX/JSON function to work correctly. I had this function
I’m having trouble getting a AJAX/JSON function to work correctly. I had this function
So here's the scoop: I wrote a tiny C# app a while back that
I've had some problems with handling forms and getting back to basics after an
I'm making an Android app using Processing, and have decided to port my code
About 2 years ago I worked on a WCF app, using VS 2008. I
I have a running JQueryMobile App that Im developing with PhoneGap for Android/IPhone, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.