I was following the basic tutorials on developers.android.com and came by creating the activity named DisplayMessageActivity. It is a blank activity with all the specifications given as shown in the tutorial. FYI, I am using Min SDK = API 8, Target SDK = API 16, Compile with = API 10
The next thing is that there are two errors:
I tried changing the API to 14 which called for another problem, it wants the minimum API to be 11.
That solves these problems, but the main problem is so many devices still use Gingerbread or maybe FroYo. Can't I write for them? Do I have to go higher? How to write for them?
First, you're going to want to make sure that you are compiling against the latest version of Android. You should update your sdk version because you're compiling for API 10 but targeting 16. Stuff may break if you do that, so it's best to stay updated to be safe.
This means right clicking on your project in Eclipse, clicking on Properties then clicking on Android. Check off the highest version API that is there. If you have the latest version, it is Android 4.2. Then in your AndroidManifest.xml, set the android:targetSdkVersion
to what you chose (my case api 17).
This should ensure that your app can run on basically HoneyComb to JellyBean. However, this app wants to run on at least froyo. This next part will allow your app to run on all devices.
Make a method like this:
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
It checks to see which API it is running on and only if it is honeycomb and above, enables the action bar.
Call it from onCreate()
You will need to take out the getActionBarCall that is in onCreate()
as it is not needed anymore there.
As for home not being enabled, it might have just been a wrong project target or you forgot to write android.R.id.home
and instead wrote R.id.home
.
Lastly with all these changes you should clean your project (Project -> Clean).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With