[英]Keeping Activity when “Don't Keep Activities” is set
i am having an activity that calls the gallery to allow the user to select an image and wait for this image to display for the user. 我正在进行一项调用图库的活动,以允许用户选择图像并等待该图像为用户显示。
if the user used the "don't keep activity" option in development options. 如果用户在开发选项中使用了“不保留活动”选项。 my application crashes when the user selects the image.
用户选择图像时,我的应用程序崩溃。
is there an option to keep my activity from being destroyed. 有没有选择可以防止我的活动遭到破坏。 if not how can i handle this so that the application does not crash
如果没有,我该如何处理,这样应用程序不会崩溃
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
(copy of my answer to similar question - I don't like when there's "see my answer in another question" link) (我对类似问题的答案的副本-当出现“在另一个问题中看到我的答案”链接时,我不喜欢)
I switched to Intent.ACTION_GET_CONTENT with just mime-type and it seems to work better. 我仅使用mime类型切换到Intent.ACTION_GET_CONTENT,它似乎工作得更好。 I guess an HTC bug.
我猜是HTC错误。
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.