Go to another Activity Android Studio [duplicated]

0

I have a problem with the following code:

 public void BotonAceptar (View vista){
        Intent intent= new Intent (DadesPersonals.this, EAC1.class);
        startActivity(intent);

       setContentView(R.layout.activity_eac1);
       EAC1 mostrar = new EAC1();
       mostrar.MostraryOcultarBotones();

My idea is to change to the EAC1 activity and once the screen is changed, show me the hidden buttons that are there.

But I get an error, can you help me? What do I have to do?

EDITED:

The flow of patanllas is as follows:

EAC page that with a button goes to the page: DADES that on this page there is a button to return to the EAC page. But I need to show hidden buttons when returning to this page.

The question is if I add the buttons () in the EAC1 in the create directly I delete the first screen that is the same but without buttons.

I hope you explained.

Error:

  

09-26 11: 15: 39.415 1586-1586 /? E / AndroidRuntime: FATAL EXCEPTION: main   java.lang.IllegalStateException: Could not execute method for   android: onClick at   android.support.v7.app.AppCompatViewInflater $ DeclaredOnClick Listener.onClick (App CompatViewInflater.j ava: 293)   at android.view.View.performClick (View.java:3511)

    
asked by Montse Mkd 26.09.2017 в 12:01
source

1 answer

2

The problem you're having is that the code of the buttons is running once it's called the startActivity() and that's why you're having an error. Since startActivity () does not end or instantly closes the code that is called, add the intent to process it later because it is a request, so in your case that code is executed and gives you an error.

To solve this I would move the code to show the buttons to the OnCreate () of the Activity EAC1 leaving your code as follows:

Current Activity

public void BotonAceptar (View vista){
        Intent intent= new Intent (DadesPersonals.this, EAC1.class);
        startActivity(intent);
}

Activity EAC1

 @Override
 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_eac1);
        MostraryOcultarBotones();
}
    
answered by 26.09.2017 в 12:57