0

我有一个调用图库以允许用户选择图像并等待该图像显示给用户的活动。

如果用户在开发选项中使用了“不保留活动”选项。当用户选择图像时,我的应用程序崩溃。

是否有一个选项可以防止我的活动被破坏。如果不是,我该如何处理,以免应用程序崩溃

启动画廊的代码

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

错误

06-22 15:23:42.132: E/AndroidRuntime(4202): FATAL EXCEPTION: main
06-22 15:23:42.132: E/AndroidRuntime(4202): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.exm.imageselect/com.exm.imageselect.HomeActivity}: java.lang.IllegalStateException: No activity
06-22 15:23:42.132: E/AndroidRuntime(4202):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at android.app.ActivityThread.access$600(ActivityThread.java:128)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at android.os.Looper.loop(Looper.java:137)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at android.app.ActivityThread.main(ActivityThread.java:4514)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at java.lang.reflect.Method.invokeNative(Native Method)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at java.lang.reflect.Method.invoke(Method.java:511)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at dalvik.system.NativeStart.main(Native Method)
06-22 15:23:42.132: E/AndroidRuntime(4202): Caused by: java.lang.IllegalStateException: No activity
06-22 15:23:42.132: E/AndroidRuntime(4202):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1089)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1084)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1875)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1137)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at android.app.Activity.performStart(Activity.java:4475)
06-22 15:23:42.132: E/AndroidRuntime(4202):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1943)
06-22 15:23:42.132: E/AndroidRuntime(4202):     ... 11 more
4

1 回答 1

0

(我对类似问题的回答的副本 - 我不喜欢“在另一个问题中查看我的回答”链接)

我只使用 mime-type 切换到 Intent.ACTION_GET_CONTENT,它似乎效果更好。我猜是HTC的错误。

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
于 2013-09-24T21:38:45.670 回答