When you open the app, there's a flashback, and you'll see an error message from Android Studio, mainly:
Unable to add window – Token [email protected] is not valid
Cause analysis: Because a progress dialog box appears when you enter the app, the dialog's initialization must depend on activity, but if the dialog's initialization is placed in the activity's OnCreate method, an error will be made.
Because the activity is not created when the OnCreate method executes according to the activity's life cycle, the activity on which the dialog is dependent does not exist, so the initialization dialog must be an error.
Workaround: Place the initialization of the dialog box in the OnStart method. The OnStart method is called after the OnCreate method, or when the activity transitions from the stop state to the active state.
Unable to add window – token [email protected] is not valid error analysis record