简体   繁体   中英

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

code to start gallery

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

Error

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. I guess an HTC bug.

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM