Basic Intro to android(Will be updating later)

Post on 05-Jul-2015

78 views 3 download

description

Basic Intro to android application development. Taken from a 2 hour sessions. Covers very basic topics. (Will upload an advanced elaborate slide later) Session Taken at Illahia.

Transcript of Basic Intro to android(Will be updating later)

Download the Android SDK.

Install the ADT plugin for Eclipse (if you’ll use the Eclipse IDE).

Download the latest SDK tools and platforms using the SDK Manager.

Creating an Android Project

Running Your App

1. Run on a Real Device

2. Run on the Emulator

Directories and Files in the Android project

Building a Simple User Interface

android:onClick="sendMessage"

public void sendMessage(View view) {

// Do something in response to button

}

Build an Intent

Intent intent = new Intent(this, DisplayMessageActivity.class);

To provides runtime binding between separate components(as two activities)

Intent intent = new Intent(this, DisplayMessageActivity.class);

EditText editText = (EditText) findViewById(R.id.edit_message);

String message = editText.getText().toString();

intent.putExtra(EXTRA_MESSAGE, message);

public class MainActivity extends ActionBarActivity {

public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

...

}

/** Called when the user clicks the Send button */

public void sendMessage(View view) {

Intent intent = new Intent(this, DisplayMessageActivity.class);

EditText editText = (EditText) findViewById(R.id.edit_message);

String message = editText.getText().toString();

intent.putExtra(EXTRA_MESSAGE, message);

startActivity(intent);

}

Create the Second Activity

Receive the Intent

Intent intent = getIntent();String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

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

}