Activity gets killed after returned from the camera

╄→гoц情女王★ 提交于 2020-01-24 20:27:06

问题


In my app I call the system camera to take a picture, and then handle the result in onActivityResult. It used to work, but now my calling activity gets killed sometimes, sometimes it works well.I need the big picture,so I must use intent.putExtra(MediaStore.EXTRA_OUTPUT, output),if without this(like use the intent data to get a bitmap) ,it works fine. after take a pic, and onclick the 'OK' button, I need it return to the activity which start the camera,but sometime it works fine,sometimes the parent activity is finished. after search,I set android:alwaysRetainTaskState="true",but this not work. my system is Galaxy S I9000,I also test this on other phone,but it works well. did anybody know why? here is my code

  private void startTakePhoto(){
    App.fileNameWithPath = Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator + System.currentTimeMillis()+".jpg";
    File file = new File(App.fileNameWithPath);
    Uri output = Uri.fromFile(file);
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, output);
    boolean flag = BaseUtil.hasImageCaptureBug();
    System.out.println(flag);
    //intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(fileNameWithPath)));
    //BaseUtil.saveImagePath(App.fileNameWithPath, this);
    startActivityForResult(intent, REQUEST_TAKE_PHOTO);
}
It like this :
I want is 
1. A  start B (stack: A,B)
2. B start camera activity and wait For Result (stack:A,B,camera) 
3. save picture,return B activity (stack: A,B)

but on step 3, it not return to B,but A.
It seems like B is finished by the system, why?

回答1:


http://developer.android.com/reference/android/app/Activity.html The reason is because memory menagement in Android. As i know your phone has about 100mb free operative memory, if your activity is not on foreground it can be destroyed. So that's why you should implement some methods of you activity to start it is onPause, onDestroy and on Resume methods. Just save all your info in Bundle and start Activity propelly.



来源:https://stackoverflow.com/questions/18869112/activity-gets-killed-after-returned-from-the-camera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!