为什么我的android活动被停止? [英] Why is my android activity being stopped?

查看:139
本文介绍了为什么我的android活动被停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承的,我需要修改(呸)的应用程序的一些code。有关活动实施SurfaceHolder.Callback和SensorEventListener。这项活动是一个自定义相机。

I have inherited some code from an application that I need to modify (yuck). The activity in question implements SurfaceHolder.Callback and SensorEventListener. This activity is for a custom Camera.

在code工作正常进行自动对焦,并拍照。一旦拍摄照片后,我开始另一个活动的结果来裁剪图像。由于作为活动开始不久,SurfaceHolder.Callback为surfaceDestroyed被调用(如预期)。在这一点上,现有的申请释放相机(如预期)。然而,当新榨季的活动推出后,原来的摄像头的活动已停止。(堆栈跟踪:Instrumentation.callActivityOnStop-> Activity.performStop)

The code works fine to autofocus, and take a picture. Once the picture is taken, I start another activity for result to crop the image. As soon as that activity is started, the SurfaceHolder.Callback for surfaceDestroyed is called (as expected). At this point the existing application releases the camera (as expected). However, when the new crop activity is launched, the original camera activity is stopped (stack trace: Instrumentation.callActivityOnStop->Activity.performStop).

编辑:当我的活动的onStop被称为完整的堆栈跟踪:

Complete stack trace when the onStop of my activity is called:

CameraActivity.onStop() line: 784      
Instrumentation.callActivityOnStop(Activity) line: 1219
CameraActivity(Activity).performStop() line: 5186      
ActivityThread.performStopActivityInner(ActivityThread$ActivityClientRecord, ActivityThread$StopInfo, boolean, boolean) line: 3003     
ActivityThread.handleStopActivity(IBinder, boolean, int) line: 3052    
ActivityThread.access$1000(ActivityThread, IBinder, boolean, int) line: 139    
ActivityThread$H.handleMessage(Message) line: 1251     
ActivityThread$H(Handler).dispatchMessage(Message) line: 99    
Looper.loop() line: 137
ActivityThread.main(String[]) line: 4918       
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] 
Method.invoke(Object, Object...) line: 511     
ZygoteInit$MethodAndArgsCaller.run() line: 1004
ZygoteInit.main(String[]) line: 771    
NativeStart.main(String[]) line: not available [native method] 

由于该相机活性不再活动,并且它不接收来自作物的活性的结果。

Because of this the camera activity is no longer active, and it doesn't receive the result from the crop activity.

为什么破坏表面/释放相机会导致相机活动停止?我必须在这里失去了一些东西......

Why does destroying the surface/releasing the camera cause the Camera Activity to stop? I must be missing something here...

推荐答案

所以,我做了我通常做在这样的情况下,并试图简化问题。我创建了一个全新的项目,下面就以Android开发者网站上的指南:的 http://developer.android.com/guide/topics/media/camera.html#custom-camera

So, I did what I normally do in situations like this, and tried to simplify the problem. I created an entirely new project, following the guide on the android developer site: http://developer.android.com/guide/topics/media/camera.html#custom-camera

一旦我得到了我的新的简单的应用程序来拍照,我修改它来调用作物的活动,它的工作没有问题。

Once I got my new simple application to take a picture, I modified it to call the crop activity, and it worked without an issue.

最大的不同示例应用程序之间的是它使用一个单独的摄像头preVIEW类来实现SurfaceHolder.Callback,在我的应用程序中的活动来实现该接口直接。我不知道这是否是真正的问题,但一旦我改变了code要做到这一点,它似乎工作。

The biggest different between the example application was that it used a separate CameraPreview class to implement the SurfaceHolder.Callback, where as my application implemented that interface directly in the Activity. I do not know if that was the true issue, but once I changed the code to do that, it seemed to work.

所以,除非有人能够更好的给我解释一下,解决方法是在你的活动不实行SurfaceHolder.Callback。

So unless someone can explain it better to me, the fix is to not implement SurfaceHolder.Callback in your activity.

这篇关于为什么我的android活动被停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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