我正在调用图库的活动,允许用户选择图像并等待该图像显示给用户。
如果用户在开发选项中使用了“不要保持活动”选项。当用户选择图像时,我的应用程序崩溃。
是否可以选择防止我的活动被销毁。如果不是我怎么能处理这个,以便应用程序不会崩溃
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
答案 0 :(得分:0)
(我对类似问题的回答的副本 - 我不喜欢当有“在另一个问题中看到我的答案”链接时)
我只使用mime-type切换到Intent.ACTION_GET_CONTENT,它看起来效果更好。我想是一个HTC错误。
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");