【问题标题】:Start Activity For Result Not return to calling activityStart Activity For Result 不返回调用活动
【发布时间】:2017-01-19 06:53:26
【问题描述】:

我有一个片段,它像这样调用从图库意图中选择图像

  Intent intent=new Intent();
  intent.setType("image/*");
  intent.setAction(Intent.ACTION_GET_CONTENT);
  startActivityForResult(Intent.createChooser(intent,"Complete Action Using"),1);

我已成功执行上述启动电话库的方法,我可以从那里选择图像,但应用程序应该返回调用片段但它不是,即使我可以看到 onActivityonResult 在 LogCat 中调用

我还有一个从地图返回到调用片段的获取位置,但是在选择图像时我没有返回调用活动,而是显示父活动第一个片段

这是我的onActivityResult

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==1 && resultCode==getActivity().RESULT_OK){

        Log.d(TAG,"Request Code is 1 Running: "+requestCode+" "+resultCode);
        Uri imageNameURL=data.getData();
        Log.d(TAG,imageNameURL.toString());
        ImagePath=getPath(imageNameURL);
        Log.d(TAG,"onActivityResult "+ImagePath);
        bitmap= BitmapFactory.decodeFile(ImagePath);

    }
    else if (requestCode==2 && resultCode==getActivity().RESULT_OK){

        Log.d(TAG,"Request Code 2 Running");
        LatLngBounds LL= PlacePicker.getLatLngBounds(data);
        double lat=LL.northeast.latitude;
        double longi=LL.northeast.longitude;
        double lat2=LL.southwest.latitude;
        double longi2=LL.southwest.longitude;            
        }

    }

【问题讨论】:

  • 调用活动可能在尝试加载该位图时崩溃。您应该发布一个带有任何错误消息的 logcat,并准确描述发生了什么,因为我不确定我是否理解您到目前为止发布的内容。
  • 日志中没有错误我只能看到活动结果正在调用,但我的地图活动返回到同一片段,并且我在 LogCat 中看到了活动结果日志中的图像
  • 不要过滤logcat,也许你会看到相关的异常或崩溃。
  • @DavidWasser 我总是将我的 logcat 设置为 verbose
  • 我不是那个意思。我的意思是不要按您的应用程序的包名称进行过滤。大多数 IDE 使用应用程序的包名称自动设置 logcat 过滤器。如果您使用这种类型的过滤器,您将错过任何由 android 框架生成的异常或消息,而这些消息通常正是您需要为您指出解决问题的正确方向的消息。

标签: android android-fragments android-intent onactivityresult startactivityforresult


【解决方案1】:

有时在 AndroidManifest.xml 中开启 noHistory=false 可以工作。我认为这几乎是一件被遗忘的事情。

怎么做?

打开AndroidManifest.xml文件,找到包含onActivityResult()方法的文件标签,输入android:noHistory="false"

喜欢这个!

<activity
        android:name="MyActivityClassName"
        android:screenOrientation="portrait"
        android:noHistory="false"
        />

希望对某人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多