リクエストコードを使用してMainActivity
からInfomationActivity
に電話しました。しかし、MainActivity
を返すとき、それは非アクティブです。ここでの問題は何ですか? MainActivity
でResultCodeとRequestCodeが機能しない
、requestcodeを使用してInfomationActivity
を呼び出す:InfomationActivity
で
Intent intent = new Intent(MainActivity.this, InfomationActivity.class);
startActivityForResult(intent, 100);
、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
リターン:logcatで
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);
}
}
、私はresultcode = 3のときに実行されないことを確認してください。 resultcode = 3のときは実行されませんか?
と4、それはいいです。 –
整数値はこの結果には適用されません。異常な動作をする可能性がありますので、RESULT_OKのみを使用し、3または4をintとして1つのパラメータを設定することをお勧めします。 if-elseループので試してみてください – Vickyexpert
2つのケースが処理されていればOKですが、もっとケースが必要ですか??? –