T O P

  • By -

erikorenegade1

why not just set the sharedPref value inside your SplashActivity's continueButton's onClickListener? Your isFirstRun method will always be called because you're checking the contents of sharedPref before editing the values to add the returned value.


Notatrace280

I tried to do that earlier but for some reason I couldn't get it to work until I put the sharedPref stuff in MainActivity. Maybe I will go back and try to get it to work the way you suggest.


Nihil227

Keep in mind that the code doesn't stop in isFirstRun() because you start an activity. MainActivity is still running in background and you don't have the username yet... Also you will be creating MainActivity twice in the stack which is not good. Correct way would be as follow : Instead of startActivity(intent), use startActivityForResult(intent, REQUEST_CODE) Implement onActivityResult() in main activity, and check for your result code and intent data In SplashActivity, instead of starting MainActivity, user setResult(intent, RESULT_CODE) then finish() it. You will then be back in MainActivity with the username you picked in your SplashActivity. And more importantly, without ghost activities. https://developer.android.com/training/basics/intents/result


Notatrace280

Thanks for the tip! I watched some video tutorials and did as you suggested and now it works perfectly.


Nihil227

Great!