安卓6.0以上机型微信登录时提示Activity did not call finish() prior to onResume() completing

**

安卓6.0以上机型微信登录时提示Activity did not call finish() prior to onResume() completing

**

今天遇到这样的一个bug,我的测试机是Android 6.0以上机型,点击微信第三方登录的时候出现这种情况:

Activity {hz.helpme_repair/hz.helpme_repair.wxapi.WXEntryActivity}
did not call finish() prior to onResume() completing,然后在网上搜索了一下,有其他的报错提示(An activity without a UI must call finish() before onResume() completes ),但是使用这种方法都适用

Android 6.0相应的源码:

final void performResume() {
    performRestart();
    mFragments.execPendingActions();
    mLastNonConfigurationInstances = null;
    mCalled = false;
    // mResumed is set by the instrumentation
    mInstrumentation.callActivityOnResume(this);
    if (!mCalled) {
       throw new SuperNotCalledException(
           "Activity " + mComponent.toShortString() +
           " did not call through to super.onResume()");
    }

    // invisible activities must be finished before onResume() completes
    if (!mVisibleFromClient && !mFinished) {
        Log.w(TAG, "An activity without a UI must call finish() before onResume() completes");
        if (getApplicationInfo().targetSdkVersion
                > android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
            throw new IllegalStateException(
                   "Activity " + mComponent.toShortString() +
                   " did not call finish() prior to onResume() completing");
       }
   }
   // Now really resume, and install the current status bar and menu.
   mCalled = false;
   mFragments.dispatchResume();
   mFragments.execPendingActions();
   onPostResume();
   if (!mCalled) {
       throw new SuperNotCalledException(
           "Activity " + mComponent.toShortString() +
           " did not call through to super.onPostResume()");
    }
}

主要是因为微信登录界面没有界面的情况下,需要把Activity的样式设置为透明。否则在6.0以上机型登录时会出现崩溃现象。既然我的activity是没有UI的,出错的activity主题的配置如下:

<activity android:name=".DialogActivity" 
   android:theme="@android:style/Theme.NoDisplay/>

这个一个没有UI的主题,为了解决问题,只需要将主题改成透明的即可,ps:记住透明不等于没有UI哦,如下所示:

<activity android:name=".DialogActivity" 
    ...
    android:theme="@android:style/Theme.Translucent.NoTitleBar"/>

猜你喜欢

转载自blog.csdn.net/zxt94/article/details/74301458