-1

I am new to android-programming. I installed the SDK and added the library and when I create a new project I get this error:

ActionBarActivity is deprecated

I use android support library 22.2 and android 5.1.1(API 22).

package com.example.ww;

import android.support.v7.app.ActionBarActivity;//problem
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity { //problem

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
  • 1
    Not a duplicate - the referenced link pertains to Android Studio -- this is an issue pertaining to Eclipse – terary May 14 '16 at 17:28

1 Answers1

2

Replace ActionBarActivity with AppCompatActivity.

You don't need to do anything, just because it's deprecated doesn't mean it's not functional. It means it will not be supported in the future. Eclipse should be giving you a warning, not an error.

Here's the current souce code of ActionBarActivity, from the Android source code:

/**
 * @deprecated Use {@link android.support.v7.app.AppCompatActivity} instead.
 */
@Deprecated
public class ActionBarActivity extends AppCompatActivity {
}

To clarify, all you need to do is replace

public class MainActivity extends ActionBarActivity {

with

public class MainActivity extends AppCompatActivity {
Anubian Noob
  • 13,426
  • 6
  • 53
  • 75