0

I've got a project written for API 11 and up, no I need it available for 2.3.3 OS devices either, so need to use Support Library. What is the easiest way to go with it? I know some methods have different names for Fragments, for instance. Can it be possible to use "Find and Replace All"?

Eugene
  • 59,186
  • 91
  • 226
  • 333

2 Answers2

2

For the most part, yes it will be possible. You'll also have to change less than you think, for example the Fragment class is fine.

You will have to change getFragmentManager to getSupportFragmentManager, as well as changing your base Activity to a FragmentActivity. Those are the most common two off the top of my head.

The easiest way is to change the target to 2.2, add the support-package as a library, and see what breaks and then fix it-- and once you have a replacement fix you can use find and replace all to fix all instances of the issue.

edthethird
  • 6,263
  • 2
  • 24
  • 34
  • Thanks! What about preferences? This could be a problem I think. – Eugene Jul 10 '12 at 19:56
  • yeah, that wasn't back-ported. Check this out: http://stackoverflow.com/questions/5501431/was-preferencefragment-intentionally-excluded-from-the-compatibility-package – edthethird Jul 10 '12 at 19:58
  • You don't need to change the project build to debug your app... this is what `Android lint` is for... – Alex Lockwood Jul 10 '12 at 20:00
  • edited, thank you-- as I mentioned those class changes are off the top of my head, the OP will have to do some investigation himself – edthethird Jul 10 '12 at 20:05
0

Can it be possible to use "Find and Replace All"?

As far as I'm concerned, it's never a good idea to do a simple "Find and Replace All"... it's far too easy to make a mistake.

What is the easiest way to make the transition?

The change is very simple and should not require you to change your build target at all (assuming you are targeting Android 1.6 or above, of course). The key changes you must make are:

  1. For each Activity that makes use of the support libraries, have it extend FragmentActivity instead.

  2. In each FragmentActivity, replace all calls to getLoaderManager() with getSupportLoaderManager().

  3. In each FragmentActivity, replace all calls to getFragmentManager() to getSupportFragmentManager().

  4. Replace all relevant android.* imports with their corresponding support.v4.* import statements.

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250