So, I have three activities/screens. On the first screen, there’s a button, that when pressed, opens the second screen. On the second screen, there’s a button to open screen 3, but also another button to go back to screen 1. I can’t get both buttons on screen 2 to work. (Either one works and the other doesn’t and vice versa).
Screen 1 Java:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class FirstActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button next = (Button) findViewById(R.id.part1to2);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Screen2.class);
startActivityForResult(myIntent, 0);
}
});
}
}
Screen 2.java:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Screen2 extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
Button next = (Button) findViewById(R.id.goto1);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent();
setResult(RESULT_OK, intent);
Button next = (Button) findViewById(R.id.goto3);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Screen3.class);
startActivityForResult(myIntent, 0);
finish();
}
});
}
});
}
}
Screen 3.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Screen3 extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.third);
}
}
And my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gamer.network2"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".FirstActivity"
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=".Screen2"></activity>
<activity android:name=".Screen3"></activity>
</application>
</manifest>
So, how do I get both buttons on Screen 2 to work at the same time?
Both buttons are the same name and are declared wrongly.
Try instead:
Edit: Cole, see below, this is code working from an app of mine, with two different buttons pointing to two different activities. I have also included the code from the AndroidManifest.xml.
In the
AndroidManifest.xml: