微信支付问题:WeChatNotifyActivity} did not call finish() prior to onResume() completing

本文探讨了在Android Studio中进行微信支付集成时遇到的应用崩溃问题。通过对崩溃日志的分析,发现是由于特定Activity未在onResume()完成前调用finish()导致。文章提供了两种解决方案:一是设置正确的主题,二是调整targetSdkVersion。

   在前人留的工程项目中进行渠道替换对接支付,使用的微信支付,但是以前一直都是通过现在支付把微信支付进行了融合,而且只有微信支付,(现在支付是一个集成了支付宝,微信,百度金融,京东金融等平台的聚合类sdk)不知道当初为什么这样设计,只有微信的还有选聚合的sdk。

在Eclpise转Android Studio运行的项目中进行微信支付操作正常,但是当 我把项目中代码全部放到 Android Studio 形式的 工程时再运行出现 调用相应的Activity崩溃。

           

     Android Studio项目                      Eclipse 转 Android Studio项目                                                                                         


崩溃如下:  Caused by: java.lang.IllegalStateException: Activity {com.orange.org_player_new_alone194818.game4399/com.ipaynow.wechatpay.plugin.inner_plugin.wechat_plugin.activity.WeChatNotifyActivity} did not call finish() prior to onResume() completing


在华为4.4的系统上没有出现这个问题,就可能和系统有关。

关键之处就是 did not call finish() prior to onResume() completing

在网上搜到一个 An activity without a UI must call finish() before onResume() completes ,而我们的问题也是和这个类似的。在Android 源码中

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()");
    }
}


主要部分:

 // 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");
       }
   }

这部分源码就是抛出的崩溃日志
An activity without a UI must call finish() before onResume() completes
也就是我们的Activity 没有UI,所以 要进行主题设置。

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


把主题设置为 如上即可。
但是从Eclipse 转的项目 Android Studio ManiFest 都一样,为什么会出现以前项目android:theme 不是Translucent.NoTitleBar可以正常运行,自己创建的 Android Studio会崩溃,然后想了一下应该是 gradle targetSdkVersion 配置问题,targetSdkVersion已经超过6.0了,以前的没有这么高所以运行的时候并不优先选择 6.0系统,而是选择 targetSdkVersion 运行的环境。


所以修复这个问题可以通过修改相应的 activity theme,也可以通过修改targetSdkVersion 修复这个问题




                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值