dak*_*aka 31 android runtime-error android-lifecycle android-6.0-marshmallow
我收到以下错误,我不知道为什么会发生这种情况.
错误:
08-23 17:07:46.533 22454-22454/com.a.b.c E/AndroidRuntime? FATAL EXCEPTION: main
Process: com.a.b.c, PID: 22454
java.lang.RuntimeException: Unable to resume activity {com.a.b.c/com.a.b.c.MainActivity}: java.lang.IllegalStateException: Activity {com.a.b.c/com.a.b.c.MainActivity} did not call finish() prior to onResume() completing
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: Activity {com.a.b.c/com.a.b.c.MainActivity} did not call finish() prior to onResume() completing
at android.app.Activity.performResume(Activity.java:6324)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3092)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Run Code Online (Sandbox Code Playgroud)
码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println("Started");
}
Run Code Online (Sandbox Code Playgroud)
我试图在运行Android 6.0(API 23)的AVD上运行代码,适用于API 22.
Ale*_*ang 20
我有同样的问题,同样的崩溃
did not call finish() prior to onResume() completing
Run Code Online (Sandbox Code Playgroud)
错误信息.所以我创建了v23\styles.xml
<style name="AppTheme" parent="android:Theme.Translucent">
...
</style>
Run Code Online (Sandbox Code Playgroud)
而普通的styles.xml有
<style name="AppTheme" parent="android:Theme.NoDisplay">
...
</style>
Run Code Online (Sandbox Code Playgroud)
它工作正常,不再崩溃.但是,我不知道这个解决方案有多好,在API 23中使用Theme.Translucent,特别是因为它被定义为
半透明活动的主题(API级别10及更低级别).
我真的希望他们能解决这个问题.
Sam*_*Sam 18
我找到了一个解决方法.通话setVisible(true)中onStart():
@Override
protected void onStart() {
super.onStart();
setVisible(true);
}
Run Code Online (Sandbox Code Playgroud)
我的隐形活动显示了一个确认对话框。这确实失去了材料的设计外观,当我使用android:Theme.Translucent.NoTitleBar。
因此,基于上面的答案和 CommonWare 的博客以及 Android 主题定义,我使用了这种样式,它扩展了一个普通的 AppCompat.Light 主题:
<style name="AppTheme.NoDisplay" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我已经找到了实际的解决方法。该Theme.NoDisplay仅对
不实际显示 UI 的活动;也就是说,他们在恢复之前完成了自己。
来源:Android 开发
因此,如果您分配这个主题的活动中,你必须调用finish()退出之前onCreate()(系统调用之前即onResume)这就是为什么错误说“没有调用完成()之前的onResume()”。
因此,该主题的实际用例是引导程序活动等,例如,当您必须根据用户是否已通过身份验证来确定是显示登录视图还是主视图时:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13263 次 |
| 最近记录: |