Calling completion () after starting another activity only works sometimes

I have a splash screen that handles automatic login. If the user is logged in, it sends s / he directly to the main activity via the following code:

Intent intent = new Intent(activity, MainActivity.class);
activity.startActivity(intent);
activity.finish();

      

If the activity is a complete activity (I don't use this

it because this method is common for automatic logins, manual logins, social logins, etc.)

However, about 70% of the time, the splash screen still remains after the main activity has completed. This does not happen during debugging. It looks like it happens when the login is fast, so it probably never happens during debugging (because things get slow).

Logging helped me figure out what is finish()

actually called when the problem occurs , but is onDestroy()

not.

I tried FLAG_ACTIVITY_CLEAR_TOP

it but it doesn't help. noHistory

works but brings unnecessary finishing animation and really I want to know what is the problem with this code. I've always used it and don't understand why it fails.

Thanks in advance.

+3


source to share





All Articles