アクティビティ B を開始するアクティビティ A と、画像を選択するためのギャラリーアプリであるアクティビティ B の startsForResult があります。私の問題は、画像を選択する (またはキャンセルを押す) と、アクティビティ B がプロセスを開始し、結果全体を処理する必要があるにもかかわらず、アクティビティ A に戻ることです。
さらに、アクティビティ A に戻った後、Eclipse はもうブレークポイントにジャンプしません。その後、アクティビティ B を開始し、ボタンを押してギャラリーアプリを再度開くと、正しい結果が返され、すべて正常に動作します。
ここで何が起こっているのか、誰か説明してもらえますか? 私はかなり長い間検索していましたが、私が得た唯一のヒントは、メモリの問題のためにアクティビティ B がスタックから削除された可能性があるということでした。しかし、なぜアクティビティ A ではなくアクティビティ B を削除するのでしょうか? 画像が選択されたときにギャラリーアプリが毎回アクティビティ B に戻るように、これを修正する必要があります。
@Override
public void onClick(View v) {
if(v.getId() == btnOk.getId())
{
handleOKClick();
}
else if(v.getId() == channelThumbnail.getId())
{
Intent pickImageIntent = new Intent(Intent.ACTION_PICK);
pickImageIntent.setType("image/*");
startActivityForResult(pickImageIntent, PICK_IMAGE_RESULT);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == PICK_IMAGE_RESULT && resultCode == RESULT_OK)
{
Uri selectedImage = data.getData();
try {
InputStream imageStream = getContentResolver().openInputStream(selectedImage);
Bitmap bmp = BitmapFactory.decodeStream(imageStream);
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
//Set Maximum size of an Thumbnail to 512x512
bmp = Utility.limitBitmapToBoundries(bmp, 256, 256);
this.channelThumbnail.setImageBitmap(bmp);
this.channelThumbnail.setBackgroundColor(Color.TRANSPARENT);
AddYamasChannelActivity.this.curSelectedImage = bmp;
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
}
}
private void handleOKClick()
{
//Check if Image was already selected, otherwise prompt the user to select an image
if(this.curSelectedImage == null)
{
Utility.showWarningDialog(this, R.string.error, R.string.alertdialog_addyamaschannel_no_image);
return;
}
//Check if Channelname is longer than 3 Characters
String channelName = et.getText().toString();
if(channelName.length() >= 3)
{
pb.setVisibility(View.VISIBLE);
et.setEnabled(false);
btnOk.setEnabled(false);
AddYamasChannelAsyncTask addYamasChannelAsyncTask= new AddYamasChannelAsyncTask();
addYamasChannelAsyncTask.execute(channelName, googleAccountName);
}
else
Toast.makeText(AddYamasChannelActivity.this, R.string.alertdialog_channelname_too_short, Toast.LENGTH_SHORT).show();
}