The Android Starter Code
We have just created an app called Starter and this is currently showing in the development screen. The main Java file, MainActivity.java is already open in the workspace and all we have to do to view it is to click on its tab. However if it is not already open then it can be found in the projects pane at
app/java/com.androidjavaapps.starter, or
app/src/main/java/com.androidjavaapps.starter
Double clicking on this name opens the file in the workspace pane where we can edit it and develop our app.
Default code is generated by the IDE for whatever form factor you selected. If that was the blank activity the code is as follows:-
package com.yourdomainname.starter;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
@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
getMenuInflater().inflate(R.menu.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.
// if you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}