Android Eclipse Lint API Validation

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)    // location 1
public class DisplayMessageActivity extends Activity {

    @Override
    @TargetApi(11)    // location 2
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            @TargetApi(11)    // location 3
            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);
        // ActionBar introduced in Android 3.0 Honeycomb API 11
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            getActionBar().setDisplayHomeAsUpEnabled(true); }   // Up Navigation

        // Get the message from the intent
        Intent intent = getIntent();
        String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

        // Create the text view
        TextView textView = new TextView(this);
        textView.setTextSize(40);
        textView.setText(message);

        // Set the text view as the activity layout
        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);
    }

}
+5
3

FizzBuzz Android ?.

@TargetApi(nn) :

import android.annotation.TargetApi;

- @Override. , ​​ ADT http://tools.android.com/recent/lintapicheck, .

+9

- (, , ). , , :

/** Indicates that Lint should treat this type as targeting a given API level, no matter what the
    project target is. */
@Target({TYPE, METHOD, CONSTRUCTOR})
@Retention(RetentionPolicy.CLASS)
public @interface TargetApi {
    /**
     * This sets the target api level for the type..
     */
    int value();
}
+2

API

0

All Articles