Android skip activity on back button press
Consider launching the main app and then launching the login screen as a custom modal dialog.
Tips for a modal launch:
builder.setCancelable(false)
- Do NOT use a static method and call show() as in the open source EULA examples. This implementation fails if the user turns the phone. Instead use the standard pattern onCreateDialog, getInstanceMyDialog, showDialog(int).
- The modal dialog can return data if you call it using startActivityForResult or the modal dialog can write to a custom preferences file.
In the manifest, add android:noHistory="true"
as an attribute of the login activity.
Calling finish()
after startActivity()
is the way to go. You should investigate on why it crashes in that case.