I have such a puzzle.

The user, when he first opens the application, enters the first activation and is registered. I save it locally and when it opens the application a second time, then the java class of this first activation immediately checks if this id was and if so, the intent opens the main activation.

Everything seems logical, but I have a button on this basic activation when I click on that the first activation should open to the user, and here’s the question, because as I said on this first activation, I have a check that sees that the user is already registered and again sends it to the main activation.

How to be here?

I need to have a check, and so that I can press the button again to open the first screen ...

I just had the idea to create ahead of the first activation, splash activation in which to check whether this user was registered, if yes, then he goes to the main screen, and from it he can press the button and return to the first one, and if splash activation makes a check and there is no such ID, then it gets on the first activation.

But the problem is that I really do not want to sculpt one more activi ...

What can be done here?

  • Maybe you just need to reset the ID by clicking on the button in the second activation? - temq

2 answers 2

In the second activity add in the intent any value from which you want to go to the first. Type

 Intent intent = new Intent(SecondActivity.thhis, FirstActivity.class); intent.putExtra("value", "value"); startActivity(intent); finish(); 

In the first onCreate call

 if(getIntent().getStringExtra("value") != null){ //resume }else{ if (firstTime){ //first logic }else{ //startActivity(FirstActivity.this, SecondActivity.class); } } 

I don’t know how true that is. The first thing that came to mind. Although the idea of ​​a test screen looks normal.

  • Yes, the idea is really interesting ... Although I still thought, I made a simple animation to splash up activations and didn’t look bad - Aleksey Timoshchenko

Surely you keep some flag in SharedPreferences that the user is registered and check this flag and throw it on the second activation. So in the second activation you can do this: clean the sharedPreferences and just run the first activation through the intent

 FirstActivity { if(sharedPreferences.userIsRegistered()){ startActivity(new Intent(this, SecondActivity.class)); } } SecondActivity { sharedPreference.setUserIsRegistered(false); startActivity(new Intent(this, FirstActivity.class)); } 
  • Yes, but if I clean the pref then how do I know that this is the same user, if he opens the application for the 2nd time? Or every time he gets to the first activation, overwrite the pref? - Aleksey Timoshchenko
  • @AlekseyTimoshchenko you can leave the userId and userIsRegistered parameters, and for example, showRegisteredScreen, and depending on this parameter, dance if (sharedPreferences.userIsRegistered () &&! SharedPreferences.showRegisteredScreen ()) {startActivity (new Intent (this, SecondActivity.class) ; } SecondActivity {sharedPreference.setshowRegisteredScreen (true); startActivity (new Intent (this, FirstActivity.class)); } - artemiygreg 2:58 pm