Alex Rivera | Logout

Android skip activity on back button press

Asked 2011-04-08T10:56:02.687
18

I have a login screen in which the user logs in. After that the user will be taken to a main screen.

Now my problem is when the back button is pressed the user is taken to the login screen again.

Is there any way to fix this problem?

I have tried calling finish() right after startActivity() but it only made the application crash and didn't seem a good solution either.

Edit
Report

1 Answer

1

Consider launching the main app and then launching the login screen as a custom modal dialog.

Tips for a modal launch:

  1. builder.setCancelable(false)
  2. 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).
  3. The modal dialog can return data if you call it using startActivityForResult or the modal dialog can write to a custom preferences file.
answered 2011-04-08T17:53:37.970

Your Answer