-1
How can I make a button that calls another screen, and on the other screen have a button that when you click, goes back to the home screen?
-1
How can I make a button that calls another screen, and on the other screen have a button that when you click, goes back to the home screen?
1
Screen 1
final Button myButton = (Button) findViewById(R.id.myButton);
myButton.setOnClickListener(View.OnClickListener {
@Override
public void onClick(View v) {
Intent i = new Intent(this@Tela1, Tela2.class);
startActivity(i);
}
});
Screen 2
You can use any button or even set a navigation button on your Toolbar
.
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#fff"
app:navigationIcon="@drawable/ic_back" /> <!-- este é o icone de navegação -->
And in the class of Screen 2:
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
You can also use a button whatever the result will be the same. What happens above is that you start a new Activity, but the previous one continues in the Stack, that is, it was not finished, only paused. So, when giving Finish, she is reopened as she has remained in the line of activities.
Feel free to ask new questions in the comment of this answer if there are any questions.
Browser other questions tagged android
You are not signed in. Login or sign up in order to post.
I’m having a problem with screen code 1: Intent i = new Intent(this, Proxpasso.class); Cannot resolve constructor
– user92401
You are using the above code within a Fragment?
– itscorey
I’m using inside the onCreate
– user92401
Okay, try the following:
Intent i = new Intent(getApplicationContext(), ProxPasso.class);
and tell me if it resolves.– itscorey
Stop the application from working
– user92401
Right. Do you know where the Androidmanifest.xml file is? And if so, the Activity Proxpasso file is set in this file?
– itscorey
No, but I just copied it from Screen 1 and it worked, but I have an error on Screen 2, setSupportActionBar(Toolbar); cannot be Applied to (android.widget.Toolbar)
– user92401
It is because the reference is incorrect. It must be
android.support.v7.widget.Toolbar
instead ofToolbar
– itscorey
Look for some
import
that leads to Toolbar and swaps for android.support.v7.widget.Toolbar and your problem will be solved. And if in your layout is Toolbar, switch to android.support.v7.widget.Toolbar as in the response code.– itscorey