活动就会被杀死从相机后返回 [英] Activity gets killed after returned from the camera

查看:141
本文介绍了活动就会被杀死从相机后返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我调用系统相机拍照,然后处理结果的onActivityResult。它用于工作,但现在我的呼吁活动有时被杀害,
有时它的工作原理well.I需要大画面,所以我必须用 intent.putExtra(MediaStore.EXTRA_OUTPUT,输出),如果没有这个(如使用意图的数据来获得一个位图),它工作正常。
采取经过事先知情同意,并在的onclick确定按钮,我需要它返回到活动
其中启动摄像头,但有时它工作正常,有时父活动结束。搜索后,我设置的android:alwaysRetainTaskState =真正的,但这不能正常工作。
我的系统是Galaxy S的I9000,我也测试这对其它手机,但它工作得很好。
有没有人知道为什么吗?
这里是我的code

 私人无效startTakePhoto(){
    。App.fileNameWithPath = Environment.getExternalStorageDirectory()getAbsolutePath()+文件分割符+ System.currentTimeMillis的()+JPG;
    档案文件=新的文件(App.fileNameWithPath);
    乌里输出= Uri.fromFile(文件);
    意向意图=新意图(MediaStore.ACTION_IM​​AGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT,输出);
    布尔标志= BaseUtil.hasImageCaptureBug();
    的System.out.println(标志);
    //intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(新文件(fileNameWithPath)));
    //BaseUtil.saveImagePath(App.fileNameWithPath,这一点);
    startActivityForResult(意向,REQUEST_TAKE_PHOTO);
}


它是这样的:
我要的是
1.启动B(堆栈:A,B)
2. b启动摄像头活动并等待结果(堆栈:A,B,摄像头)
3.保存图片,返回B的活性(堆栈:A,B)但在第3步,就不会回到B,但是A.
这似乎是B通过该系统,为什么完了?


解决方案

HTTP: //developer.android.com/reference/android/app/Activity.html
究其原因是因为Android的内存menagement。因为我知道你的手机拥有约100MB可用内存手术,如果你的活动是不是在前台也可以被破坏。所以这就是为什么你应该实现你一些方法活动启动它的onPause,的onDestroy和恢复方法。只需保存你所有的信息捆绑和propelly开始活动。

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?

解决方案

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.

这篇关于活动就会被杀死从相机后返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆