- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用请求代码从 MainActivity
调用到 InfomationActivity
。但是,当返回 MainActivity
时,它处于非 Activity 状态。这里有什么问题?
在 MainActivity
中,使用请求代码调用 InfomationActivity
:
Intent intent = new Intent(MainActivity.this, InfomationActivity.class);
startActivityForResult(intent, 100);
在InfomationActivity
中,返回一个resultcode:
if(btnAlarmInfo.getVisibility() == View.VISIBLE){
//run
Log.d("abc", note.getTitle() + "/" + note.getNote() + "/" + note.getDateTime() + "/" + note.getColorBackground());
Log.d("abc", Integer.toString(images.size()));
Intent intent = getIntent();
intent.putExtra("title", note.getTitle());
intent.putExtra("note", note.getNote());
intent.putExtra("time", note.getDateTime());
intent.putExtra("color", note.getColorBackground());
intent.putParcelableArrayListExtra("image", images);
setResult(3, intent);
finish();
}else{
//run
Intent intent = getIntent();
intent.putExtra("title", note.getTitle());
intent.putExtra("note", note.getNote());
intent.putExtra("time", note.getDateTime());
intent.putExtra("color", note.getColorBackground());
intent.putExtra("day", note.getDayAlarm());
intent.putExtra("hour", note.getHourAlarm());
intent.putParcelableArrayListExtra("image", images);
setResult(4, intent);
finish();
}
当 MainActivity
返回时:
if(requestCode == 100){
if(resultCode == 3){
//not run ????????
Log.d("abc", "it's me");
String title = data.getExtras().getString("title");
String note = data.getExtras().getString("note");
String time = data.getExtras().getString("time");
String color = data.getExtras().getString("color");
ArrayList<Image> image = data.getParcelableArrayListExtra("image");
Log.d("abc", Integer.toString(image.size()));
ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>();
for(int i = 0; i < image.size(); i++){
bitmaps.add(image.get(i).getImage());
}
Note note1 = new Note(title, note, false, time, color, "", "", bitmaps);
this.addNote(note1);
}else if(resultCode == 4){
//run
String title = data.getExtras().getString("title");
String note = data.getExtras().getString("note");
String time = data.getExtras().getString("time");
String color = data.getExtras().getString("color");
String day = data.getExtras().getString("day");
String hour = data.getExtras().getString("hour");
ArrayList<Image> image = data.getParcelableArrayListExtra("image");
ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>();
for(int i = 0; i < image.size(); i++){
bitmaps.add(image.get(i).getImage());
}
Note note1 = new Note(title, note, true, time, color, day, hour, bitmaps);
this.addNote(note1);
}
}
在 logcat 中,当 resultcode = 3 时,我看到它不运行。为什么当 resultcode = 3 时,它不运行?
最佳答案
应该在启动的 Activity 中使用预定义值 RESULT_OK
、RESULT_CANCELLED
或 RESULT_FIRST_USER
之一设置结果代码.
像 3 和 4 这样的设置值在这里不一定有定义的行为;如果它们对您有某种意义(并且不仅仅是随机的),则将它们作为 Intent 的另一个额外内容传回。使用 RESULT_OK
代替它们。
此外,对于您用来传回结果的 Intent,我建议使用 new Intent()
创建一个新 Intent 而不是重复使用用于启动 Activity 的 Intent(即getIntent()
给你什么)。
无论如何,我建议您查看this section of the docs ,它处理开始 Activity 和获得结果。
关于android - ResultCode 和 RequestCode 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38517342/
我想知道我是否正确理解了 requestCode 和 resultCode 的概念?基本上,我有一个与 Activity 关联的任意整数(requestCode)。例如,在 Notepad tutor
我是 Java 和 Android 新手,但我有一个应用程序可以从相机拍摄照片并将其保存为文件。我可以启动相机并拍照,但在 onActivityResult 中,resultCode 始终为 RESU
我使用请求代码从 MainActivity 调用到 InfomationActivity。但是,当返回 MainActivity 时,它处于非 Activity 状态。这里有什么问题? 在 MainA
当我在 Nouget 版本中使用相机 Intent 时,相机 Intent 完美运行。 我的问题:但是 resultCode (onActivityResult()) 总是返回取消。 注意:相同的代码
我总是用下面的代码得到 ResultCode = 0。 这是我处理setResult的代码 @Override public void onResponse(Call call,
这可能是一个基本问题,但我希望能弄清楚一些。 我想做的是:1) 使用 requestCode 启动一个 Activity ,并处理两个操作onActivityResult,一个使用 RESULT_OK
我开发了一个提示日历应用程序编辑事件的 Android 应用程序。 我使用 startActivityForResult() 打开日历。编辑并保存事件后,onActivityResult() 中的 r
我正在尝试在我的 android 应用程序中使用摄像头进行开发。 问题是相机总是返回结果代码 0,无论我是按完成还是取消。我使用的代码 fragment 如下: protected void star
我的脚本中有以下代码行,它不是直接调用 exe,而是调用一个批处理文件。 Exec(ExpandConstant('{app}\App\bin\migrate.bat'), '', '', sw_sh
我对 onActivityResult 有疑问,无论我在做什么,我都无法获得正确的 resultCode。 我知道有类似的问题,但最后他们没有帮助我,我无法解决 MainActivity: 将打开新
我正在尝试在我的应用程序中包含一个摄像头,用于将文件本地保存在 SD 卡上。相机应用程序启动,但 resultCode 始终为 0。我已将以下权限添加到我的 list 中: 这是我的相机的代码:
当我尝试拍摄照片并将其存储在外部存储器中时,我卡在了一个应用程序上。相机 Intent 有效,但我无法确认拍摄的图像。然后我把onActivityResult改成下面这样监听resultCode。触摸
测试时In-App Updates ,更新下载但安装失败,onActivityResult 中的 resultCode 为 0 (RESULT_CANCELED)。 另外,更新版本不是最新更新到tra
我有一个 fragment 的 Activity ,然后该 fragment 调用某个 Activity ,该 Activity 将为第一个 Activity 提供一些值(value)。我使用 onA
下面是我从别人的例子中找到的两个函数。在检查 resultCode 之前,似乎对我来说效果很好。无论用户是按 OK 还是 Cancel,resultCode 都是零。你能告诉我为什么吗?此代码存在于继
关于类似主题的问题有很多,但在四处搜索后,我没有找到与我的问题相匹配的问题。 我知道如何为结果启动 Intent ,并覆盖 onActivityResult() 来处理这些 Intent ,但出于某种
我想显示ZXING的扫描结果。我将 ZXING 集成到我的 Android 应用程序中,扫描工作正常。现在我想在 TextView 中显示条形码编号结果。我在我的项目中使用 zxing 库。我设置了
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我想尝试来自 firebase 的应用程序邀请 - 不幸的是 onActivityResult 报告 onActivityResult 3。仅使用本文档中的代码:https://firebase.go
我正在启动从图库中挑选图片的 Intent ,但 Intent 总是返回结果代码 RESULT_CANCELED。我尝试了很多不同的代码,但没有任何帮助让我觉得我可能遗漏了一些东西,比如在 Andro
我是一名优秀的程序员,十分优秀!