几天来,我的应用中随机出现SIGSEGV错误。我什么都不做时崩溃了。
我开始分解代码以查看引起该分段的行,当我发现它是:(请打鼓声)时,我感到非常震惊
Activity.setResult(Activity.OK,intent)
什么?这对我来说仍然毫无意义!在下面的代码行中,我将向您展示我的代码前后,谁能告诉我为什么SIGSEGV正在发生?
之前
CommentActivity:
val comments = ArrayList<Comment>()
comments.add(comment)
/*Set the results*/
val intent = Intent()
intent.putExtra("comment_result", Utils.General.serializeToJson(comments))
this.setResult(Activity.RESULT_OK, intent)
this.finish()
MainActivity:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
switch (requestCode) {
//catch data from CommentActivity
case (INTENT_COMMENT): {
if (resultCode == RESULT_OK) {
String comments = intent.getExtras().getString("comment_result");
if (comments != null && !comments.isEmpty()) {
/*Save the instance to the database and expect the database observable to call the upload thread*/
Type type = new TypeToken<ArrayList<Comment>>() {}.getType();
ArrayList<Comment> list = Utils.General.Companion.deserializeFromJson(comments, type);
/*Save the instance to the database and expect the database observable to call the upload thread*/
DataSource.INSTANCE.saveComments(list);
} else {
showToast(getResources().getString(R.string.picture_lost), Toast.LENGTH_SHORT);
}
}
break;
}
====这在10秒到1分钟之间在MainActivity中崩溃了=====
之后-无崩溃
CommentActivity:
/*Set the results*/
DataSource.saveComments(comments)
this.finish()