Android onActivityResult导致同一活动的多个实例

时间:2016-02-26 10:55:32

标签: android android-activity

我有三项活动:MessagesActivityMessagesAttachPhotoActivityImageGalleryActivity。从MessagesActivity开始,我按照以下方式启动MessagesAttachPhotoActivity

  intent = new Intent(this, MessagesAttachPhotoActivity.class);
  bundle = new Bundle();
  bundle.putInt("Request", MessageThread.MessageType.IMAGE);
  intent.putExtras(bundle);
  intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
  intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
  startActivityForResult(intent, MessageThread.MessageType.IMAGE);

然后从MessagesAttachPhotoActivity开始ImageGalleryActivity,如下所示;

intent = new Intent(this, MessagesAttachPhotoActivity.class);
bundle = new Bundle();
bundle.putInt("Request", MessageThread.MessageType.IMAGE);
intent.putExtras(bundle);
startActivityForResult(intent, MessageThread.MessageType.IMAGE);

ImageGalleryActivity中,我将结果返回MessagesAttachPhotoActivity

Intent photoIntent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("item", imagePath);
photoIntent.putExtras(bundle);
setResult(Activity.RESULT_OK, photoIntent);
finish();

问题是,evrytime我从ImageGalleryActivity返回,创建了一个新的MessagesAttachPhotoActivity实例。我怎么能避免这个?我想从ImageGalleryActivity访问MessagesAttachPhotoActivity约20次。请有人帮忙。

0 个答案:

没有答案