在执行相机意图活动就会被杀死 [英] Activity gets killed while executing the camera intent

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

问题描述

在我的应用我调用系统相机拍照,然后处理结果 onActivityResult 。要知道,一般的。它用来工作,但现在当我拍照我呼吁活动就会被杀死。具体而言,的onDestroy()叫上我的活动之后我preSS相机快门。照片确实被拍摄和放大器;保存(我已经检查过该文件被写在SD卡上)。之后我接受,而不是返回到调用活动,并调用 onActivityResult 的照片,在活动堆栈中的previous活动被​​调用。我看到在logcat中概莫能外。我的自定义异常处理程序不会被调用。如果它很重要,我的应用程序还包括听GPS的更新服务,但我在注销的onPause所有的接收器()

In my app I call the system camera to take a picture, and then handle the result in onActivityResult. You know, the usual. It used to work, but now my calling activity gets killed while I'm taking the picture. Specifically, onDestroy() is called on my activity right after I press the camera shutter. The photo does get taken & saved (I've checked that the file gets written on the SD card). After I accept the photo, instead of returning to the calling activity and invoking onActivityResult, the previous activity in the activity stack gets called. I see no exceptions in the logcat. My custom exception handler doesn't get called. If it matters, my app also includes a service that listens to GPS updates, but I unregister all the receivers in onPause().

下面是 MyCallingActivity.onDestroy调用堆栈()

Thread [<1> main] (Suspended (breakpoint at line 303 in NewPlaceDetailsActivity))   
    NewPlaceDetailsActivity.onDestroy() line: 303   
    ActivityThread.performDestroyActivity(IBinder, boolean, int, boolean) line: 2663    
    ActivityThread.handleDestroyActivity(IBinder, boolean, int, boolean) line: 2694 
    ActivityThread.access$2100(ActivityThread, IBinder, boolean, int, boolean) line: 117    
    BinderProxy(ActivityThread$H).handleMessage(Message) line: 968  
    ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 130 
    ActivityThread.main(String[]) line: 3687    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 507  
    ZygoteInit$MethodAndArgsCaller.run() line: 842  
    ZygoteInit.main(String[]) line: 600 
    NativeStart.main(String[]) line: not available [native method]  

这是我怎么启动摄像头的活动,如果你想知道:

This is how I start the camera activity, in case you're wondering:

protected void startCamera() {
    createPhotoDirsIfNeeded();

    String fileName = "temp.jpg";  
    ContentValues values = new ContentValues();  
    values.put(MediaStore.Images.Media.TITLE, fileName);  
    m_capturedImageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);  

    m_photoFileName = APP_PHOTO_PATH + "/" + DateFormat.format(DATE_FORMAT, Calendar.getInstance().getTime()) + ".jpg";
    File picFile = new File(m_photoFileName);
    if(picFile.exists()) {
        picFile.delete();
    }

    // start the camera activity
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT,  Uri.fromFile(picFile));
    startActivityForResult(intent, IntentHelper.REQUEST_TAKE_PHOTO);
}

我如何能找出为什么我的活动被杀死,并从堆栈中,而不是再次被创造去掉?

How can I find out why does my activity get killed, AND removed from the stack instead of being created again?

推荐答案

OK,我发现这个问题。问题是没有这么多的活动是被杀害的,但它没有被恢复。我意识到,当你的活动清单中声明与这可能发生的android:noHistory =真正的。因此,活动从堆栈中移除时被杀害,和previous活动被​​证明代替。

OK, I found the problem. The issue was not so much that the activity was being killed, but that it was not being restored. I realized that this can happen when your activity is declared in the manifest with android:noHistory="true". So the activity was removed from the stack upon being killed, and the previous activity was shown instead.

在我删除了 noHistory 参数,该活动开始使用相机后再次出现。

After I removed the noHistory parameter, the activity started appearing again after using the camera.

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

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