Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8503025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:38:45+00:00 2026-06-11T01:38:45+00:00

Thanks P.T. for what looks like the correct answer to question Building multi-SDK Android

  • 0

Thanks P.T. for what looks like the correct answer to question Building multi-SDK Android apps in Eclipse without losing compile-time checks. 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 on the @TargetApi line when it is in the middle of the code as shown at location 3:

x Syntax error, insert "enum Identifier" to complete EnumHeaderName
x Syntax error, insert "enumBody" to complete BlockStatements

The errors exist whether I have the @TargetApi line before the if statement or after it as shown. Are there any prerequisites (imports) or other considerations not mentioned in the Lint API Check article http://tools.android.com/recent/lintapicheck to get @TargetApi() working correctly?

— Edit 9/3/2012 —

If I move the @TargetApi annotation to before the class definition (shown as location 1) or before the method definition (shown as location 2, either before or after the @Override annotation), I get different errors:

x TargetApi cannot be resolved to a type
x The attribute value is undefined for the annotation type TargetApi

— Edit 9/4/2012 —

Here is the full source code:

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);
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:38:46+00:00Added an answer on June 11, 2026 at 1:38 am

    FizzBuzz provided the answer to this in How do you version code in Android without compiler warnings?.

    In addition to the @TargetApi(nn) annotation in the code, you also need to import the definition of that annotation:

    import android.annotation.TargetApi;
    

    For some unknown reason, an import is not required to use the @Override annotation. It would be helpful if the ADT documentation http://tools.android.com/recent/lintapicheck were fixed to eliminate the bogus code example and mention the required import.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question div which looks like so: <div class=Q> <div id=Q1><span>1. </span>Which
Suppose file1 looks like this: bye bye hello thank you And file2 looks like
Well to me Perl sometimes looks abit Abracadabra so many thanks for the patience
thanks for taking the time to look at my question. I've been diving into
I am creating a question and answer site using PHP. Questions are viewed on
The answer to a previous question showed that Nexus implement a custom authentication helper
All, This question probably has a very simple answer - something I'm overlooking. But
Say I have a string that looks like this: str = The &yquick &cbrown
I have been searching for an answer to this question for days and it
There are a few questions that approach an answer to this question, but none

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.