【发布时间】:2014-08-21 19:45:19
【问题描述】:
我有一个问题,一旦我进入应用程序并按下手机上的“后退按钮”,然后再次进入应用程序,我的应用程序就会不断崩溃。我想我正在处理某种状态或错误:
package com.animeus;
import com.animeus.Factories.CameraDialogsFactory;
import com.animeus.Factories.CameraFactory;
import com.animeus.Services.CameraService;
import android.app.Activity;
import android.hardware.Camera;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
public class LightBulbActivity extends Activity {
/** Called when the activity is first created. */
Camera c;
//Application starts here
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
loadComponentsToUse();
setComponentEvents();
if (c == null)
CameraDialogsFactory.GetNoCameraFoundDialog(this).show();
else
setComponentEvents();
}
//Sets all the components events
private void setComponentEvents() {
View v = (View)findViewById(R.id.LightBulbView);
v.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
triggerLightEvent(event.getAction());
return false;
}
});
}
//Turns the led on or off
private void triggerLightEvent(int currentevent) {
if (currentevent == MotionEvent.ACTION_DOWN)
CameraService.turnLedLightOn(c);
else if (currentevent == MotionEvent.ACTION_UP)
{
CameraService.turnLedLightOff(c);
}
}
//Loads the "global" components we are supposed to use
private void loadComponentsToUse() {
c = CameraFactory.getCamera();
}
//Called once the activity ain't visible for the user anymore
@Override
public void onStop() {
super.onStop();
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onResume() {
super.onResume();
}
}
有什么想法吗? 我还尝试在“onPause”和“onStop”上释放相机,然后重新创建相机“onResume”,但这也会导致应用崩溃......
是的,我知道.. 这不是完整的代码.. 但如果您需要更多代码,请告诉我
提前致谢!
【问题讨论】:
-
不完全确定,但我见过人们在 onPause 事件中丢弃相机。这取决于你弄清楚android是如何处理未处理的东西的:p
-
你有堆栈跟踪或一些日志吗?
标签: android crash android-camera