Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6545855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:38:11+00:00 2026-05-25T11:38:11+00:00

So, I have three activities/screens. On the first screen, there’s a button, that when

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:38:12+00:00Added an answer on May 25, 2026 at 11:38 am

    Both buttons are the same name and are declared wrongly.

      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();
            }
    
          });
        }
      });
    

    Try instead:

        Button goto3 = (Button) findViewById(R.id.goto3);
        goto3.setOnClickListener(new View.OnClickListener() {
           public void onClick(View view) {
               // Code here 
           }    
          });
    
        Button goto1 = (Button) findViewById(R.id.goto1);
        goto1.setOnClickListener(new View.OnClickListener() {
           public void onClick(View view) {
                // Code here
            }    
          });
    

    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.

        mBtnPlayCourse = (Button) findViewById(R.id.btn_screenstart_playcourse);
        mBtnNewCourse = (Button) findViewById(R.id.btn_screenstart_newcourse);
    
        mBtnPlayCourse.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                final Intent i = new Intent(Screen_Start.this, Screen_Players.class);               
                startActivity(i);
            }
        });
    
        mBtnNewCourse.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                final Intent i = new Intent(Screen_Start.this, Screen_CreateCourse.class);
                startActivity(i);
            }
        });
    

    In the AndroidManifest.xml:

        <activity android:name=".Screen_CreateCourse" android:label="@string/app_name">
        </activity>
    
        <activity android:name=".Screen_Players" android:label="@string/app_name">
        </activity>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three activities in my android app. First activity is main application screen
I have an app that is in portrait mode, but some screens should have
I have three activities in my app. I want to keep the screen awake
I have an android app that has various activities. for example there is a
I have some data that multiple Activities need to manipulate. Basically there is one
I have three unordered lists that have been created as Scriptaculous Sortables so that
I have an application which consists of two activities/screens and a java class from
I have three activities in my application ... I use an intent to navigate
I'm developing an Android Application that has three very similar Activities. I would like
Is it possible to have a split screen that would have a camera preview

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.