我使用请求码从MainActivity
调用到InfomationActivity
。但是,当返回MainActivity
时,它不活动。这里有什么问题?ResultCode和RequestCode不起作用
在MainActivity
,使用requestcode叫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时,它不会运行?
与4,很好。 –
整数值不适用于此结果,它可能表现不正常,所以我建议您仅使用RESULT_OK并将其中的一个参数设置为3或4作为整数,主要的是您不需要将所有值都放入如果 - 其他循环,所以试试 – Vickyexpert
如果有2个案件处理,它会好的,但我想更多的情况下? –