我已經創建了一個圖像編輯應用程序..它由兩個活動組成,主要活動導致下一個活動。一切工作正常。問題是,當我在第二個活動中按HOME鍵時,它現在跳到主屏幕,當我再次運行應用程序時,它會生成一個錯誤以強制關閉。這在第一次活動期間沒有發生。我無法找到確切的問題.. 有什麼辦法,如果用戶按HOME鍵,我可以殺死該活動?按Home鍵觸發錯誤
下面是surfaceview我使用的代碼......它也使用線程...我想逸也正是DIS prblem正在興起... u能請您檢查出DIS
public DrawingSurface(Context context, AttributeSet attrs) {
super(context, attrs);
getHolder().addCallback(this);
commandManager = new CommandManager();
da=new DrawingActivity();
thread = new DrawThread(getHolder());
}
class DrawThread extends Thread{
private SurfaceHolder mSurfaceHolder;
public DrawThread(SurfaceHolder surfaceHolder){
mSurfaceHolder = surfaceHolder;
}
public void setRunning(boolean run) {
_run = run;
}
@Override
public void run() {
Canvas canvas = null;
b=da.getpic();
while (_run){
try{
canvas = mSurfaceHolder.lockCanvas(null);
if(mBitmap == null){
mBitmap = Bitmap.createBitmap (1, 1, Bitmap.Config.ARGB_8888);;
}
final Canvas c = new Canvas (mBitmap);
c.drawBitmap(b, 0, 0, null);
commandManager.executeAll(c);
canvas.drawBitmap (mBitmap, 0, 0,null); //first block
} finally {
mSurfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
public void addDrawingPath (DrawingPath drawingPath){
commandManager.addCommand(drawingPath);
}
public boolean hasMoreRedo(){
return commandManager.hasMoreRedo();
}
public void redo(){
commandManager.redo();
}
public void undo(){
commandManager.undo();
}
public boolean hasMoreUndo(){
return commandManager.hasMoreRedo();
}
public Bitmap getBitmap(){
return mBitmap;
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
mBitmap = Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888);
}
public void surfaceCreated(SurfaceHolder holder) {
thread.setRunning(true);
thread.start();
}
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
thread.setRunning(false);
while (retry) {
try {
thread.join();
retry = false;
} catch (InterruptedException e) {
}
}
}
這可能有這麼多的具體原因,所以你應該張貼的例外是拋出和一些代碼。從那個描述中不可能回答它。 – Chris 2011-03-11 13:41:17