Thanks P.T. for what seems like the correct answer to the question Building Applications with Multiple SDK Applications in Eclipse without Losing Compilation Check Time . However, when I try to use the @TargetApi () annotation as recommended, it generates syntax errors.
@TargetApi(11)
public class DisplayMessageActivity extends Activity {
@Override
@TargetApi(11)
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
@TargetApi(11)
getActionBar().setDisplayHomeAsUpEnabled(true); }
generates two syntax errors in the @TargetApi line when it is in the middle of the code, as shown in location 3:
x Syntax error, insert "enum Identifier" to complete EnumHeaderName
x Syntax error, insert "enumBody" to complete BlockStatements
Errors exist whether there is a line @TargetApibefore ifor after the statement , as shown. Are there any preconditions (import) or other considerations not mentioned in Lint API Check http://tools.android.com/recent/lintapicheck for @TargetApi () to work correctly?
--- 9/3/2012 ---
@TargetApi ( 1) ( 2, @Override), :
x TargetApi cannot be resolved to a type
x The attribute value is undefined for the annotation type TargetApi
--- 9/4/2012 ---
:
package com.example.my.first.app;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class DisplayMessageActivity extends Activity {
@TargetApi(11)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true); }
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
setContentView(textView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_display_message, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}