I have an activity called Place
I come to Place
activity from its previous activity called City
.
I have added back button to the toolbar in Place
activity using the following code:
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true)
I want to set the back button to go back to City
activity
But City
activity needs some parameters to be passed to it.
So how to tell the back button to go to City activity, without need to pass the parameters to it.
According to your Question.You should use
finish ()
Example
In your AndroidManifest.xml file, add tag android:parentActivityName and point it to where you want to go on back button. In java you need to call
method, which you have already done. This will help.
You can simply use:
to set up your backbutton on toolbar.
In Manifest:
And finally use:
In your
backButton
you just callfinish();
and you close Activity without need to pass parameter to other Activity.