Hello!
As the saying goes:

"Repetition is the mother of learning!"

For the hundredth time this question arises.
There are several activations (not to be replaced with fragments), you need to organize transitions between them.

Those. either we go after authorization immediately to the main screen of the closed part ( MainActivtiy ), or go to create an access code (which allows us not to enter a login and password each time). BUT we have already logged in!

I know several ways to solve this problem:

 android:parentActivityName в манифесте 

startActivityForResult() followed by onActivityResult() .

Well, onBackPressed() .

Only confusion is constantly being generated - some kind of activation is saved or transitions are looped back by pressing the button ... finish () I call whenever I process pressing backward or when setResult(RESULT_CANCELLED); .

Picture:

alt text

Blue and green are the ideal scenario, the script is interested in the red arrows made. Simply put, when we are logged in and reluctant to do an access code, we need to go to the MainActivity screen.

Scenario:

Start, go to the authorization.

Logged in
Let's go create an access code codeEnter.

Moved to the next preConf screen.

Returned to codeEnter.

Returned to LoginActivity.

Returned to StartActivity.

It is important that the same script be executed by pressing the back button (in principle), we forget the actionBar for a while.

    1 answer 1

    If I understand you correctly, @ Garf1eld , then you need a way to correctly switch to MainActivity if the user is logged in.

    I can only offer verification:

    • online -> send a request to a server and verify the answer locally.

    • offline (I don’t know the purpose of offline authorization on a smartphone, but still) -> after successful authorization, save the value of the key boolean enter = true to SharedPreferences. If not authorized, then enter = false ; if it logs out of the account, then assign enter = false .

    Check for successful authorization. If yes, then on MainActivity .

     // код для **офлайн** версии. if (enter == true) { // авторизован, переходим к приложению startActivity(new Intent(StartActivity.this, MainActivity.class); } else { // не авторизован, переходим к активности авторизации startActivity(new Intent(StartActivity.this, AutorizationActivity.class) } 

    UPD You can try to customize onBackPressed ();

     @Override public void onBackPressed() { startActivity(new Intent(ТЕКУЩАЯ_АКТИВНОСТЬ.this, ППВСА.class)); // ППВСА - ПРЕДЫДУЩАЯ ПО ВАШЕЙ СТРУКТУРЕ АКТИВНОСТЬ // задать кастомизацию в каждом классе } 
    • You did not quite understand me correctly, I need to understand how to make the user click on the button back or back in the actionBar to switch to the screen I need. The main thing that interests me is when we create an access code and decide to return to the previous screen, and then generally decide to return to the very beginning. Here I can not build such a logic, all the time goes to it is unclear what screens. - Garf1eld
    • @ Garf1eld, updated the answer. - web_alex
    • one
      We will consider your answer to be correct) Yes, finally it turned out. @Override public void onBackPressed () {startActivity (new Intent (CURRENT_ACTIVITY.this, PPACAclass)); finish (); } - Garf1eld
    • @ Garf1eld, glad to help. Good luck in development ;-) - web_alex