Android: How to prevent certain methods from being created when Application created?

49 views Asked by At

When I create an Android application within Eclipse Juno with Target: Android-19 (4.4.2) , I only want the onCreate() method to be created within my Activity.

However, at the minute I am getting the following when I create my Activity, Note that I do not want to use fragments or the action bar within my application.

public class MainActivity extends Activity {

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

I know that I can just delete these methods but it would be more convenient not to do so.

How can I ensure that the onCreateOptionsMenu() and onOptionsItemsSelect() methods are not created when I created an Android application?

1

There are 1 answers

0
4tee On

Simple. When you create a new project, instead of picking "Blank Activity", you pick "Empty Activity". That's all.