Commits

Giulio Piancastelli committed 385f546

Add a second activity.

  • Participants
  • Parent commits 1253e47

Comments (0)

Files changed (6)

AndroidManifest.xml

                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
+        <activity android:name="B"></activity>
 
     </application>
 </manifest>
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    >
+<TextView  
+    android:layout_width="fill_parent" 
+    android:layout_height="wrap_content" 
+    android:layout_margin="5dp" android:text="@string/b_label"/>
+</LinearLayout>

res/layout/main.xml

     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" android:text="@string/a_label"/>
+<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/launch_b_button" android:id="@+id/launch_b_button"></Button>
 </LinearLayout>

res/values/strings.xml

 <resources>
     <string name="a_label">Activity A</string>
     <string name="app_name">Android-Lifecycle</string>
+    <string name="b_label">Activity B</string>
+    <string name="launch_b_button">Launch B</string>
 </resources>

src/it/synergia/courses/android/lifecycle/A.java

 package it.synergia.courses.android.lifecycle;
 
 import android.app.Activity;
+import android.content.Intent;
 import android.os.Bundle;
 import android.util.Log;
+import android.view.View;
+import android.widget.Button;
 
 public class A extends Activity {
 	private static final String TAG = "ANDROID_LIFECYCLE";
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
+        Button launchButton = (Button) findViewById(R.id.launch_b_button);
+        launchButton.setOnClickListener(new View.OnClickListener() {
+			public void onClick(View v) {
+				Intent intent = new Intent(A.this, B.class);
+				startActivity(intent);
+			}
+		});
         log("ON_CREATE");
     }
 

src/it/synergia/courses/android/lifecycle/B.java

+package it.synergia.courses.android.lifecycle;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+
+public class B extends Activity {
+
+	private static final String TAG = "ANDROID_LIFECYCLE";
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.b);
+		Log.i(TAG, "ON_CREATE " + getClass().getSimpleName());
+	}
+
+}