android - 从拾取相机 Intent 回来后 fragment 已经激活

标签 android android-fragments

我有 fragment A,它会通过点击按钮调用 fragment B。

Fragment a = FragmentA
            .getInstance();

    // Supply index input as an argument.
    Bundle args = new Bundle();
    args.putBoolean(GlobalConstants.WANT_START_GAME, false);
    pokerOnlineProject.setArguments(args);

    FragmentTransaction transaction = getFragmentManager()
            .beginTransaction();
    transaction.replace(R.id.poker_online_container, A,
            "A");
    transaction.addToBackStack(null);
    transaction.commit();

在这个 fragment B 中,我使用以下代码在 android 操作系统中调用相机应用程序:

Intent i = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

startActivityForResult(i, RESULT_LOAD_IMAGE);

之后,我单击后退按钮,我的应用程序将返回 fragment A 而不是 fragment B,当我尝试触摸 fragment A 上的按钮时出现异常“fragment 已激活”。

最佳答案

您的照片保存在PATH_TO_SAVE 位置。

你应该在 onActivityResult 中做这样的事情:

File file = new File(PATH_TO_SAVE);

Bitmap bmp = BitmapFactory.decodeFile(file.getPath());

关于android - 从拾取相机 Intent 回来后 fragment 已经激活,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18586623/

相关文章:

android - 在 Android 中停止线程已被弃用

androidx.appcompat.view.menu.ActionMenuItemView 无法转换为 android.view.MenuItem

android - 如何从 Glide 获取图像的宽度和高度

android - 使用哪种方法将参数传递给 Fragment

java - 窗口回调 onMenuOpened 和 onPanelClosed 用于随工具栏膨胀的菜单

android - 数据不显示在 gridView Android 中

java - 在 Android 中将 RGB 值数组转换为图像

android - 图片下载 : memory leak using LazyList

android - 如何正确从 Material 设计 TextInputLayout 中获取文本?

android - Creative Ziio 和安卓开发,adb