<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity
+ android:name="com.example.myfirstapp.DisplayMessageActivity"
+ android:label="@string/title_activity_display_message"
+ android:parentActivityName="com.example.myfirstapp.MainActivity" >
+ <meta-data
+ android:name="android.support.PARENT_ACTIVITY"
+ android:value="com.example.myfirstapp.MainActivity" />
+ </activity>
</application>
</manifest>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/button_send" />
+ android:text="@string/button_send"
+ android:onClick="sendMessage" />
</LinearLayout>
<string name="button_send">Send</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
+ <string name="title_activity_display_message">My Message</string>
</resources>
--- /dev/null
+package com.example.myfirstapp;
+
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Build;
+import android.os.Bundle;
+import android.support.v4.app.NavUtils;
+import android.view.MenuItem;
+import android.widget.TextView;
+
+public class DisplayMessageActivity extends Activity {
+
+ @SuppressLint("NewApi")
+ @Override
+ protected 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);
+
+
+ // Make sure we're running on Honeycomb or higher to use ActionBar APIs
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+ // Show the Up button in the action bar.
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ NavUtils.navigateUpFromSameTask(this);
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}
package com.example.myfirstapp;
import android.app.Activity;
+import android.content.Intent;
import android.os.Bundle;
+import android.view.View;
+import android.widget.EditText;
public class MainActivity extends Activity
{
+ public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
+
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
+
+ /** 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);
+ }
}