我正在开发一个每1分钟显示一次AddScreen的应用程序,用于TimerTask()概念,
问题是每1分钟就会显示一次AddScreen,即使该应用程序当前未打开已退出
AdSplashScheduleTime.java
public class AdSplashScheduleTime{
Activity activity;
public AdSplashScheduleTime(Activity a){
this.activity=a;
Timer myTimer = new Timer();
myTimer.schedule(new TimerTask() {
@Override
public void run() {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Intent viewTargetActivity = new Intent(activity.getApplicationContext(), AdSplashCopy.class);
activity.startActivity(viewTargetActivity);
}
});
}
},60000, 60000);// 5 minutes
}
}
DiamondWorldMenus.java //主屏幕
public class DiamondWorldMenus extends TabActivity implements OnClickListener {
AdSplashScheduleTime scheduleTime;
onCreate(......){
scheduleTime=new AdSplashScheduleTime(this);
}
}
答案 0 :(得分:0)
取消你的时间任务
if(myTimer != null) {
myTimer.cancel();
myTimer.purge()
myTimer = null;
}