[Solved] android-how to make a login?


On orientation change, all life cycle functions of the Activity are called, because it is reconstructed from zero. Your application must take this into account. The current activity goes onPause() onStop() onDestroy(), then the new Activity goes onCreate() onStart() onResume(), in that order.

Therefore you must store the fact that you have logged in, in such a way that the application does not forget. Peristent data storage can be done with SharedPreferences for example, if you don’t want to use anything more complicated. Check out Android getDefaultSharedPreferences for this.

What you could probably do (but it seems like a haxory solution rather than a good one) is that in the onSaveInstanceState(Bundle bundle) function you save out the current value of the boolean that indicates being logged in into the Bundle, and then in onDestroy() you set it to false in the SharedPreferences. In the onCreate(Bundle bundle) function, if the Bundle isn’t null, then update the SharedPreferences’ boolean according to the Bundle’s content. If the user is “logged in” according to the boolean, don’t display the dialog.

solved android-how to make a login?