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 8572051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:55:09+00:00 2026-06-11T18:55:09+00:00

Im trying to move from one screen to the other using buttons, i CAN

  • 0

Im trying to move from one screen to the other using buttons, i CAN move from main to secondary but when trying to get back from the second screen i get an error message “unfortunately, app has stopped”.

Note: I will have a 3rd layout/activity so i will copy the solution to this 3rd option.

Im new in android and wonder if you can provide a better approach to what im doing (activities ARE declared in manifest, actually when using the 2nd screen as main, it goes FINE to the 1st screen (as 2nd option) BUT when trying to get back to 2nd screen it gave me the error again), thx in advance!!:

package com.example.citas.medicas;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class Citas_Medicas extends Activity {
private Button btnIraRegistrarPaciente;
private Button btnIraRegistrarDoctor;
private Button btnIraRegistrarCita;
private Button btnIraReportePacientes;
private Button btnIraReporteHistorialCitas;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_citas__medicas);

    btnIraRegistrarPaciente = (Button)findViewById(R.id.btnIraRegistrarPaciente);
    btnIraRegistrarDoctor = (Button)findViewById(R.id.btnIraRegistrarDoctor);
    btnIraRegistrarCita = (Button)findViewById(R.id.btnIraRegistrarCita);
    btnIraReportePacientes = (Button)findViewById(R.id.btnIraReportePacientes);
    btnIraReporteHistorialCitas = (Button)findViewById(R.id.btnIraReporteHistorialCitas);

}

public void onStart()
{
    super.onStart();

    btnIraRegistrarPaciente.setOnClickListener(new OnClickListener()
            {
                public void onClick(View component)
                {
                    setContentView(R.layout.registrarpaciente);
                }
            }               
    );

}

}

Here is the secondary java (not sure if the onStart is fine):

package com.example.citas.medicas;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class Registrar_Paciente extends Activity implements OnClickListener {
private Button btnRegistrarPaciente;
private Button btnVolverMenuPrincipal1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.registrarpaciente);

    btnRegistrarPaciente = (Button)findViewById(R.id.btnRegistrarPaciente);
    btnVolverMenuPrincipal1 = (Button)findViewById(R.id.btnVolverMenuPrincipal1);

    btnRegistrarPaciente.setOnClickListener(this);
    btnVolverMenuPrincipal1.setOnClickListener(this);

}



  public void onStart()
  {
    super.onStart();

    btnRegistrarPaciente.setOnClickListener( 
            new OnClickListener()
            {
                public void onClick(View component)
                {
                    setContentView(R.layout.registrarpaciente);
                }
            }               
    );

    btnVolverMenuPrincipal1.setOnClickListener( 
            new OnClickListener()
            {
                public void onClick(View component)
                {
                setContentView(R.layout.activity_citas__medicas);

                    //Intent intent = new Intent(Registrar_Paciente.this, Citas_Medicas.class);
                    //startActivity(intent);
                }
            }
    );

  }
}
  • 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-06-11T18:55:10+00:00Added an answer on June 11, 2026 at 6:55 pm

    You may need change activity instead change layout in Activity. Take care of function SetContentView b/c it will release the memory allocated for the control in the layout you already set before.

    In First Activity:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_citas__medicas);
    
        btnIraRegistrarPaciente = (Button)findViewById(R.id.btnIraRegistrarPaciente);
    
        btnIraRegistrarPaciente.setOnClickListener(new OnClickListener()
                {
                    public void onClick(View component)
                    {
                        //setContentView(R.layout.registrarpaciente);
                        Intent intent = new Intent(Citas_Medicas.this, Registrar_Paciente.class);
                        startActivity(intent);
                    }
                }               
        ); 
    
    }
    

    In Second Activity:

    @Override
    public void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.registrarpaciente);
    
        btnRegistrarPaciente = (Button)findViewById(R.id.btnRegistrarPaciente);
    
        btnRegistrarPaciente.setOnClickListener(new OnClickListener()
                {
                    public void onClick(View component)
                    {
                        //setContentView(R.layout.registrarpaciente);
                        Intent intent = new Intent(Registrar_Paciente.this, Citas_Medicas.class);
                        startActivity(intent);
                    }
                }               
        );
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to using a SQL data reader to move records from one
Ok so I'm trying to move items from one listbox to another by using
I'm trying to move the data from one table to another based on names
I'm trying to move a control from one parent to another (if this will
I am trying to dynamically move a google map (v3) from one div to
I'm trying to move a MySQL database from a Linux machine to one running
Currently we're trying to move to JSF 2.0 from JSF 1.2 and one of
I am trying to move from MySQL to MySQLi but am having some problems.
I'm trying to move a file from one directory to another (in SD Card)
I want to know how to move from one class to other class in

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.