2012-12-01 61 views
1

我正在制作一个游戏,当你触摸图像的任何地方时,弹出一个a秒1000毫秒。但这是问题如果我关闭了活动,它会崩溃,所以我添加了一个时间处理程序来关闭活动。但是那又产生了另一个问题看起来新的活动正在被调用,但te处理程序不会关闭活动。为什么我的应用程序不能关闭时间处理程序?

我附加问题出现的lvl1的活动。 (我使用不同颜色的背景不可见图像来设置可触摸区域,例如,背景颜色为白色时返回弹出窗口,当它为黄色时,它会调用另一个活动,等等。 'T似乎摩托罗拉说不上为什么工作。))

这是弹出

else if (ct.closeMatch (Color.WHITE, touchColor, tolerance)) // con esto evito poing & click muy seguidos 
{   
    Random r = new Random(); 
    int txt= r.nextInt(6-0) + 0; 
    if(txt==0){ variables.pointtxt = "Nothing interesting"; } 
    else if (txt==1){ variables.pointtxt = "There´s nothing there"; } 
    else if (txt==2){ variables.pointtxt = "I can´t do nothing with that"; } 
    else if (txt==3){ variables.pointtxt = "Wait... nop nothing"; } 
    else if (txt==4){ variables.pointtxt = "Nothing"; } 
    else if (txt==5){ variables.pointtxt = "More nothing"; } 

LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

View popupView = layoutInflater.inflate(R.layout.popup, null); 
final PopupWindow popupWindow = new PopupWindow(
    popupView, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); 
TextView text = (TextView) popupView.findViewById(R.id.popuptxt); 
text.setText(variables.pointtxt); 

popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 250); 

new Handler().postDelayed(new Runnable() { 
     public void run() {  
     if (popupWindow.isShowing()== true) 
      popupWindow.dismiss(); 
     } 
    }, 1100 
);   
} 

handledHere = true; 
break; 

default: 
    handledHere = false; 
} // end switch 

的处理器和我这是怎么收的活动,并呼吁新的活动

else if (ct.closeMatch (Color.YELLOW, touchColor, tolerance)) { 
    Intent game = new Intent(lvl1.this, lvl1_0.class); startActivity(game); 
    Handler mHandler1 = new Handler(); 
    { 
    Runnable mLaunchTask3 = null; 
    mHandler1.postDelayed(mLaunchTask3,1100); 
    } 

    //will launch the activity 
    Runnable mLaunchTask3 = new Runnable() { 
    public void run() { 
     lvl1.this.finish(); 
    } 
    }; 
} 

回答

0

关闭活动时使用此代码删除处理程序:

mHandler1.removeCallbacksAndMessages(null); 

,因为当你开始新的处理程序,处理程序之前不会删除,它会continute在后台运行

+0

非常感谢! 它的工作!我想我必须提供服务来管理这些应用,但这样做会更好。 – Rodrigofantino

相关问题