How to create new activity in AndroidStudio 2.3.3?

2

Hi, I would like to know how to create an activity in AndroidStudio 2.3.3, about 1 year ago I created activities with something similar to this:

Intent i = new Intent(algo,algo);
i.startActivity();

But I see that currently the startActivity () method; does not exist. Please tell me which is the homologous way to do it now, thanks.

    
asked by Parzival 17.06.2017 в 14:40
source

3 answers

2

It is created as follows:

Intent intent = new Intent(DeAquiVengo.this,AquiVoy.class);
startActivity(intent);

The first parameter of new Intent (), is the file where you are writing the code and the second is where you are going.

As a recommendation, put the following function at the end so that you can close said xml because it will not be left behind.

finish();
    
answered by 17.06.2017 / 14:58
source
2

If what you mean is to open a Activity from another, it would be like this:

Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
    
answered by 17.06.2017 в 14:55
1

If you try to get the method of class Intent , there is no such method:

Intent i = new Intent(algo,algo);
i.startActivity(); //* incorrecto.

The startActivity () method comes from the < a href="http: // https: //developer.android.com/reference/android/content/Context.html#startActivity (android.content.Intent)"> context (not class Intent ), for example if you are inside an Activity only calls the method:

Intent intent = new Intent(MainActivity.this,  otraActivity.class);
startActivity(intent);
    
answered by 17.06.2017 в 15:27