[英]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方法上有问题,以下是这种情况的发生
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.