0
I’m having trouble giving the action to the home button, I’m managing to implement without problems the button according to the code
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
But I don’t know how to define to which Activity he should go and how to make him "kill" the Activity where you are. The described so far is indicated in the image below as 1
I would also like help with the described as 2, it works to get back on screen (Activity) previous, but I’d like to set it to go back on the main screen but haven’t found any method to treat this button.
The idea is, the button 1 go back to the Activity previous and button 2 go back to the Activity leading "Home" and that whenever you return to any place the closed page is "killed", thus not consuming processing with what would not be used.
How could I set an ID to the top button (1)? Whereas I get it calling function:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
 getSupportActionBar().setHomeButtonEnabled(true);
E has no ID (at least not visible)... Thank you :)– Guilherme HS
@Guilhermehs, Look for the method
onCreateOptionsMenu()
in your Activity that displays Toolbar and see which layout file is used to define the menu. Then go to that file and see what the back button id is– regmoraes
I couldn’t find this method
onCreateOptionsMenu()
has some specific place that she gets?– Guilherme HS
It stays in the Activity that contains Toolbar. If you’re a little hard to find, open the Activity file and press Alt+7 to open the panel of class manure and then click on the icon of az at the top of that panel. Now just look for the method
onCreateOptionsMenu()
– regmoraes
So, that’s the problem, it’s not in mine Activity this method, look at the print how is mine Structure, what is selected with the mouse is what "invokes" the button 1
– Guilherme HS
@Guilhermehs, already understood what you did, vc is not using a Toolbar, but rather the standard Android Action Bar. I reedited the answer. just change the id.do.botao.back.da.Toolbar for android.R.id.home
– regmoraes
That I swear is the last question :/ ..... When I use the
finish();
he does not "kill" the Activity that I am, it just goes to the other and it stays active, so much so that when it gets to the main screen if I press the button to return (2) he will start to actually close the screens that before he just exchanged for another, IE, he is just changing screen, thefinish()
is not having the effect of closing itself, it’s just replacing, if you know what I mean :/ (I’ve tried using theActivityAtual.this.finish();
but makes a mistake.– Guilherme HS