Question

While creating a project using eclipse i have Minimum SDK required as Android 2.2(Froyo) and Target SDK as Android 4.2(Jelly Bean) compile with Android 4.3. I have used sqlitebrowser v2.ob1 for creating database. My app runs without any errors (few lines in red in logcat though) and meets my requirements when i run it in an emulator. I tried 3 different emulators and it works fine. But when i tried this app in a mobile device it shows force close whenever there is something to do with database. I mean to say that it shows force close when it has to retrieve from database or connect to database. By searching i learned that just the .apk file is enough for the app to run even if externally created database is used in it (copying to assets folder and then to the default location). My questions are

  1. Shouldn't my app work fine in any device ranging from Android 2.2 to 4.2 ?

  2. Should i try compiling the app with Android 4.2 instead?

  3. Am not sure about the version of the device i tried it in but am sure its within 2.2 and 4.2 . (Probably gingerbread). Other than plugging the device to PC via USB and seeing logcat (bcoz i dont own an android mobile phone) what can i do to solve this?

  4. How is the app's version, emulator and version of mobile or any other device related?

  5. My app can run on what versions of devices?

This is my first android app so any help is appreciated. Thanks in advace

Was it helpful?

Solution

It's possible that you are using a feature in your application that isn't supported by a lower version of the SDK. It's difficult to tell you exactly what that might be without any source code or stacktrace, but I can clear up your understanding of minSdkVersion and targetSdkVersion.

Consider that with each new version of the Android SDK, additional features and APIs are introduced that did not exist in previous versions. Obviously, the older versions of Android don't support those features.

When you specify a targetSdkVersion you are specifying that you are using features that were introduced in that particular version of Android. You are also implying that you have tested your application at that particular API level, and that it works as it should.

When you specify a minSdkVersion that is lower than your targetSdkVersion, you are implying that your application will work properly on a lower API level because you have manually programmed tests or checks in your code to ensure that the current API level is compatible with a feature before running it.

For example, if I wanted to run a feature introduced in Jelly Bean but I want to retain support for a lower API level (e.g. Gingerbread), I might add the following check before I run the feature (see other version codes here):

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    // run some code specific to API level 16
}

The Android SDK can automatically deal with code introduced in a lower API level, but it can't automatically deal with code specific to a higher API level.

So with that in mind, to answer your questions:

  1. No, it's only guaranteed that your application will work properly on Android 4.2. It's up to you to ensure that it remains backwards compatible for earlier versions that you wish to support.

  2. It shouldn't matter. Instead, you should first determine if your application runs on a device/emulator that is running the same API level as you are targeting (Android 4.2, API level 17), then run it on a device/emulator running a lower version and try to isolate the code that is causing it to crash (logcat will be helpful).

  3. You can check the Android version of a device by going into Settings > About phone > Android version. If it is running Gingerbread, keep in mind that a lot of new features have been introduced since then and your application might be using some of those features. For the emulator, you can specify an API level when you create an emulator (you can download other versions to use from the SDK Manager).

  4. I think my answer so far has made this relationship clear.

  5. To reiterate, your application WILL run on any device running Android 2.2 or later, but it can crash if you are using features from a higher API level than the device is running.

If this is still not clear, you should read more about supporting multiple platform versions in the Android documentation: here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top