Code still runs after startActivity()
That's normal behaviour. startActivity()
does not terminate current one nor instantly aborts/quits the code it is called from. It adds a new intent to the handler's queue for further processing, yet this intent won't be handled by the framework unless control is returned to the system event loop, which usually means unless your method ends executing.
If you really need to terminate current activity just call finish()
in your method to tell the framework you done with this one. Note, again, that finish()
does not terminates the current Activity instantly, so if you got code after finish()
it will be executed. If that's not your intention, use i.e return;
to return control to the framework just after finish()
call.
Snippet from documentation:
void finish ()
Call this when your activity is done and should be closed. The ActivityResult is propagated back to whoever launched you via onActivityResult().
This is the normal behavior. The startActivity() is just a 'request' it doesn't to launch a new activity, the current one will remain executing the rest of the code until its 'death' then the onPause() followed by the onDestroy() is executed. You can read amore about the Activity life cycle here: http://developer.android.com/training/basics/activity-lifecycle/starting.html