Activity did not call finish? (API 23)

后端 未结 8 1685
渐次进展
渐次进展 2020-12-08 06:47

I am getting the following error and i have no clue as to why its happening.

Error:

08-23 17:07:46.533  22454-22454/com.a.b.c E/Andr         


        
相关标签:
8条回答
  • 2020-12-08 07:40

    I have found the actual intended fix for this. The Theme.NoDisplay is only for

    activities that don't actually display a UI; that is, they finish themselves before being resumed.

    Source: Android Dev

    Therefore, if you assign this theme to an activity you must call finish() before exiting onCreate() (i.e. before the system calls onResume) This is why the error says "did not call finish() prior to onResume()".

    So the actual usecase for this theme is bootstrap activities and the like, for example like this when you have to determine whether you show the login or main view depending on whether the user is already authenticated:

    public class BootstrapActivity extends Activity {
    
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if (!userLoggedIn) {
                startActivity(new Intent(this, LoginActivity.class));
            } else {
                startActivity(new Intent(this, MainActivity.class));
            }
            finish();
        }
    
    }
    
    0 讨论(0)
  • 2020-12-08 07:41

    I'm having the same problem, the same crash with the

    did not call finish() prior to onResume() completing

    error message. So I created the v23\styles.xml

    <style name="AppTheme" parent="android:Theme.Translucent">
    ...
    </style>
    

    while the normal styles.xml has

    <style name="AppTheme" parent="android:Theme.NoDisplay">
    ...
    </style>
    

    It works fine, no longer crashes. However, I don't know how good is this solution, to use Theme.Translucent in API 23, especially as it is defined as

    Theme for translucent activities (on API level 10 and lower).

    I really hope they fix this bug.

    0 讨论(0)
提交回复
热议问题