How can prevent when user click back, only back to one page before the login Activity
. If hit the last page before login Activity
, then exit the app. Now, if i click go back it will show the login page and need login again. Once user login, unless they click logout button, otherwise don't show login Activity
.
Any idea on this? Thank you.
If you would like to simply prevent the back button to navigate back to your login Activity
, you could just set the android:noHistory
attribute to true
for your login Activity
in your Manifest.
Something like this:
<activity
android:name=".LoginActivity"
android:noHistory="true" />
Always open your activity after splash screen. Decide which activity you want to navigate the user using the stored login data. To store login data use shared preferences. But at the time of login, after logging in if user clicks back, user will be navigated back to login activity. So once the user successfully logged in clear the activities on stack while navigating the user to main/home activity
Intent intent = new Intent(this, A.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With