gpt4 book ai didi

java - 由于 onStop() 强制关闭

转载 作者:行者123 更新时间:2023-12-01 05:55:07 26 4
gpt4 key购买 nike

我终于完成了应用程序中的所有内容,但现在每当我使用除“主页”按钮之外的任何操作退出它时,它都会闪烁强制关闭屏幕,然后它就会消失。我知道这没什么大不了的,但我真的希望这种情况停止发生,我终于得到了一个 logcat,它说没有 super.onStop(),所以我添加了这一点,然后它再次强制关闭给我一个空指针,

我正在使用 moveTaskToBack(true) 关闭应用程序,每当我使用它时,它都会在 onDraw 方法中给我一个空指针。我不确定还需要什么其他信息,所以请告诉我,提前感谢您的帮助

public void onDraw(Canvas canvas){
if(checkState == -9){
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(bG, 0, 0, paint);
canvas.drawBitmap(title, display.getWidth()/2 - title.getWidth()/2, 10, paint);
canvas.drawBitmap(start, display.getWidth()/2 - start.getWidth()/2, 40 + title.getHeight(), paint);
canvas.drawBitmap(instructions, display.getWidth()/2 - instructions.getWidth()/2, 80 + title.getHeight() + start.getHeight(), paint);
canvas.drawBitmap(exit, display.getWidth()/2 - exit.getWidth()/2, 120 + title.getHeight() + start.getHeight() + exit.getHeight(), paint);
canvas.drawBitmap(highScore, 0, display.getHeight() - highScore.getHeight(), paint);
String high = highLevel + "";
for(int i = 0; i < high.length(); i++){
levelOnMenu = high.charAt(i) + "";
levelPiece = Integer.parseInt(levelOnMenu);
int placeX = highScore.getWidth() + levelNumber.getWidth()/2 ;
if(high.length() == 1){

}
else if(high.length() == 2){
if(i == 0){

}
else{
placeX = placeX + levelNumber.getWidth();
}
}

它告诉我 onDraw 的第一部分是 null,drawColor...这对我来说没有多大意义

这是我使用 moveTaskToBack() 的地方

if(checkState == -11){
if(event.getAction() == MotionEvent.ACTION_UP){
if(x >= display.getWidth()/2 - pauseMenu.getWidth()/2 && x <= display.getWidth()/2 + pauseMenu.getWidth()/2 && y >= display.getHeight()/2 - pauseMenu.getHeight()/2 && y <= display.getHeight()/2 - pauseMenu.getHeight()/2 + pauseMenu.getHeight()/3){
checkState = previousState;
}
if(x >= display.getWidth()/2 - pauseMenu.getWidth()/2 && x <= display.getWidth()/2 + pauseMenu.getWidth()/2 && y >= display.getHeight()/2 - pauseMenu.getHeight()/2 + pauseMenu.getHeight()/3 && y <= display.getHeight()/2 - pauseMenu.getHeight()/2 + 2*(pauseMenu.getHeight()/3)){
if(sound){
sound = false;
}
else{
sound = true;
}
}
if(x >= display.getWidth()/2 - pauseMenu.getWidth()/2 && x <= display.getWidth()/2 + pauseMenu.getWidth()/2 && y >= display.getHeight()/2 - pauseMenu.getHeight()/2 + 2*(pauseMenu.getHeight()/3) && y <= display.getHeight()/2 - pauseMenu.getHeight()/2 + pauseMenu.getHeight()){

moveTaskToBack(true);
}

}
}

最佳答案

您不应该使用 Activity.finish() 函数来关闭您的应用程序吗?

关于java - 由于 onStop() 强制关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3268649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com