Starting Another Activity
[android/MyFirstApp.git] / src / com / example / myfirstapp / DisplayMessageActivity.java
1 package com.example.myfirstapp;
2
3 import android.annotation.SuppressLint;
4 import android.app.Activity;
5 import android.content.Intent;
6 import android.os.Build;
7 import android.os.Bundle;
8 import android.support.v4.app.NavUtils;
9 import android.view.MenuItem;
10 import android.widget.TextView;
11
12 public class DisplayMessageActivity extends Activity {
13
14     @SuppressLint("NewApi")
15     @Override
16     protected void onCreate(Bundle savedInstanceState) {
17         super.onCreate(savedInstanceState);
18         // Get the message from the intent
19         Intent intent = getIntent();
20         String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
21
22         // Create the text view
23         TextView textView = new TextView(this);
24         textView.setTextSize(40);
25         textView.setText(message);
26
27         // Set the text view as the activity layout
28         setContentView(textView);
29
30
31         // Make sure we're running on Honeycomb or higher to use ActionBar APIs
32         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
33             // Show the Up button in the action bar.
34             getActionBar().setDisplayHomeAsUpEnabled(true);
35         }
36     }
37
38     @Override
39     public boolean onOptionsItemSelected(MenuItem item) {
40         switch (item.getItemId()) {
41         case android.R.id.home:
42             NavUtils.navigateUpFromSameTask(this);
43             return true;
44         }
45         return super.onOptionsItemSelected(item);
46     }
47 }