简体   繁体   English

为什么在重新启动应用程序时在onActivityResult上获取NullPointerException?

[英]why am getting NullPointerException on onActivityResult while relaunching the app?

I have a problem on onActivityResult method of an activity(Cordova activity), following is the case where this happens 我在活动(Cordova活动)的onActivityResult方法上有问题,以下是这种情况的发生

  1. Launch a Activity1 启动一个活动1
  2. StartActivityForResult named Activity2 StartActivityForResult名为Activity2
  3. Press home button 按下主页按钮
  4. Relaunch the app through clicking on app icon 通过单击应用程序图标重新启动应用程序

am getting the splash activity called and then activity1 is called but this gives me nullpointerException on onActivityResult and the activity is not displaying the view as well. 在获取启动活动,然后调用activity1,但这在onActivityResult上给了我nullpointerException,该活动也没有显示视图。

Can anyone give me the solution to avoid this error? 谁能给我解决方案以避免此错误?

<activity
        android:name=".MDLIVEMain"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:taskAffinity=""
        android:clearTaskOnLaunch="true"
        android:finishOnTaskLaunch="true"
        android:excludeFromRecents="true"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar"
        android:windowSoftInputMode="adjustResize" />

Starting activity for result part 结果部分的开始活动

 Intent passcodeIntent = new Intent(getActivity(), PasscodeActivity.class);
 passcodeIntent.putExtra("passcode_data_page",passcodeDataPage);
 startActivityForResult(passcodeIntent, PASSCODE_RESULT_PAGE);

OnaActivityResult code OnaActivityResult代码

     @Override
    protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
        CordovaPlugin callback = this.activityResultCallbacks;
        try {
            Log.d("onActivityResult",requestCode+"-"+responseCode+"");
            if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) {
                mConnectionResult = null;
                mPlusClient.connect();
            }

            if (callback != null) {
                callback.onActivityResult(requestCode, responseCode, intent);
            }
            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    mConnectionProgressDialog.dismiss();
                }
            });

            if (requestCode == PASSCODE_RESULT_PAGE) {
                if (responseCode == RESULT_OK) {
                    activityVisible = true;
                    this.callbackContext.success(intent.getExtras().getString("passcode_pin"));
                } else {
                    this.callbackContext.success(intent.getExtras().getString("passcode_pin"));
                    isFromPasscodePage = true;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
//            finish();
        }
    }

Error come here 错误来这里

this.callbackContext.success(intent.getExtras().getString("passcode_pin"));
                isFromPasscodePage = true;

onActivityResult() android:launchMode="singleTask"android:launchMode="singleTask" ,请尝试删除此属性。

Dismissing a (progress) dialog in onActivityResult is questionable. 在onActivityResult中关闭(进度)对话框是有问题的。 onActivityResult is called after some other activity was active. 其他活动处于活动状态后,将调用onActivityResult。 In any case calling it from a runnable is unnecessary. 无论如何都不需要从可运行对象调用它。

You are calling intent.getExtras().getString. 您正在调用intent.getExtras()。getString。 There is no guarantee that the intent has extras or a string "passcode_pin" especially if the passcode activity was cancelled. 不能保证意图中有额外内容或字符串“ passcode_pin”,尤其是在取消密码活动的情况下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在此应用程序中出现NullPointerException? - Why am I getting a NullPointerException in this app? 使用相机后,我从android应用程序中的onActivityResult获取了NullPointerException和失败传递结果异常 - I am getting a NullPointerException and Failure Delivering Result exception from onActivityResult in my android app after using the camera 为什么会出现NullPointerException? - Why am I getting NullPointerException? 我正在创建一个项目,并且在运行时遇到麻烦,我试图清理该项目,然后重新启动 - i am creating a project and getting this trouble while running i have tried to cleaning the project relaunching it 为什么onActivityResult返回,但是我得到了正确的requestCode? - Why does onActivityResult return, but I am getting the correct requestCode? 为什么在Firebase中的onChildAdded中得到NullPointerException? - Why am I getting NullPointerException in onChildAdded in Firebase? 为什么在.setOnTouchListener()上得到nullpointerexception? - Why am I getting a nullpointerexception on .setOnTouchListener()? 为什么在此项目中出现NullPointerException? - Why am I getting a NullPointerException in this project? 为什么我在此行上收到NullPointerException? - Why am I getting a NullPointerException on this line? 为什么我会收到 nullpointerexception (Android)? - Why am I getting a nullpointerexception (Android)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM