Activity Did Not Call Finish? (api 23)
Solution 1:
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
<stylename="AppTheme"parent="android:Theme.Translucent">
...
</style>
while the normal styles.xml has
<stylename="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.
Solution 2:
I found a workaround. Call setVisible(true)
in onStart()
:
@OverrideprotectedvoidonStart() {
super.onStart();
setVisible(true);
}
Solution 3:
This is a bug in Android M developer preview. More details
Solution 4:
My invisible Activity shows a confirmation dialog. This did lose the material design look when I used android:Theme.Translucent.NoTitleBar
.
So, based on answers above and CommonWare's blog and the Android themes definitions I use this style, which extends a normal AppCompat.Light theme:
<stylename="AppTheme.NoDisplay"parent="Theme.AppCompat.Light"><itemname="android:windowBackground">@android:color/transparent</item><itemname="android:windowContentOverlay">@null</item><itemname="android:windowIsTranslucent">true</item><itemname="android:windowAnimationStyle">@android:style/Animation</item><itemname="android:windowDisablePreview">true</item><itemname="android:windowNoTitle">true</item></style>
Solution 5:
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:
publicclassBootstrapActivityextendsActivity {
@OverrideprotectedvoidonCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!userLoggedIn) {
startActivity(newIntent(this, LoginActivity.class));
} else {
startActivity(newIntent(this, MainActivity.class));
}
finish();
}
}
Post a Comment for "Activity Did Not Call Finish? (api 23)"