I’ve done this before, with luck, so I can’t understand why I’m messing it up now.
Quite simply, start a second activity from the main activity.
In my main Activity (Test.class):
Intent s = new Intent(Test.this, Settings.class);
this.startActivity(s);
My Settings Activity (Settings.class):
public class Settings extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.settings);
}
}
settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/test"
android:text="Test"
/>
</LinearLayout>
And here’s the application part of the AndroidManifest.xml file:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="com.frank.test.Test"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.frank.test.Settings"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
This just crashes. No log entries, no nothing. Not even when I surround the creating and starting of the intent/activity with a try-catch with a debug tag.
I’m blind, or deaf, I know. But I really HATE these crashes where there are no errors anywhere.
I’m starting the intent inside the main Acitvity’s onCreate() method, by the way.
Update: I also tried adding the second activity to the AndroidManifest.xml class like this:
<activity android:name=".Settings"></activity>
Few things you need to fix.
First, your layout:
You need to define width and height to your
TextViewas below:Second, you need to fix your
AndroidManifest.xml. You are not properly defining both of your activities. See below: