Pressing back does not return as expected

0

I run into the following problem:

If I take a tour of my app and go through the layouts, when I click the button on the back of the mobile terminal, I see that it is not going backwards as I expect, but that it goes back on the path I have made in the app, going through all the layouts that I've gone through, until the end of the app.

Let's see if I can explain myself well .. Suppose this is a summary of my layouts in the app

Main
    layout1
        layout1.1
        layout1.2
    layout2
        layout2.1
    layout3
    layout4

I enter the application and do this tour:

  

Main - > layout1 - > Layout1.1 - > Layout1.2 - > Main - > layput2 - > layout

By giving it back in that last point where the user finds himself what the application does is to go through absolutely all the layouts he has visited. That is:

  

Layout2 - > Main - > layout1.2 - > layout1.1 - > Layout1 - Main

By clicking on the back button of the mobile terminal, I would like it to go wherever it is to the layout that is hierarchically behind and not to go through all the layouts that the user has visited again

EDIT:

Okay, I've realized this happens to me because in the layoutX.X it goes back to the previous page, not because of the back button of the mobile, but because I have a button in that activity that when executing it, an Intent to the previous layout, and that's why when you give it back, it makes that whole journey.

Is there any SIMULAR way that I give to the back button but to do it by clicking on a button and not doing it by means of the Intent?

    
asked by Rodrypaladin 17.11.2018 в 10:17
source

1 answer

0

Vale found the solution myself, I publish it in case some newbie is with the same problem.

onBackPressed();

onBackPressed () is the same as hitting the button on the back of our mobile terminal

    
answered by 17.11.2018 / 10:41
source