@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
time=Long.parseLong(intent.getStringExtra("time"));
Toast.makeText(this, ""+time, Toast.LENGTH_LONG).show();
timer=new Timer();
TimerTask timerTask=new TimerTask() {
@Override
public void run() {
Calendar c = Calendar.getInstance();
int minute = c.get(Calendar.MINUTE);
if(minute==time) {
Log.d("AlarmService", "timer");
Toast.makeText(getApplicationContext(),"ringing",Toast.LENGTH_SHORT);
}
}
};
timer.scheduleAtFixedRate(timerTask, 0, 1000*2);
return super.onStartCommand(intent, flags, startId);
}
答案 0 :(得分:0)
如何在timerTask run.Exception中进行吐司是未被捕获的处理程序
因为在非ui线程上执行的TimerTask
的run方法显示Toast。
为了解决问题,请使用Handler
或runOnUiThread
来显示来自run
方法的Toast
答案 1 :(得分:0)
你还没有用过
HTML
<div id="slider">
<img id="1" src="Images/IMG_2615.png" style="hight:1048px; width:1571px;" alt="" />
<img id="2" src="Images/IMG_2616.png" style="hight:1048px; width:1571px;" alt="" />
<img id="3" src="Images/IMG_2619.png" "hight:1048px; width:1571px;" alt="" />
<iframe id="4" width="100%" height="100%" src="http://www.youtube.com/embed/KVwSP51KVO8?wmode=opaque" frameborder="0" class="youtube-video" allowfullscreen></iframe>
<img id="5" src="Images/IMG_2620.png" "hight:1048px; width:1571px;" alt="" />
<img id="6" src="Images/IMG_4189.JPG" "hight:1048px; width:1571px;" alt="" />
<img id="7" src="Images/IMG_4245.JPG" "hight:1048px; width:1571px;" alt="" />
<img id="8" src="Images/IMG_4283.JPG" "hight:1048px; width:1571px;" alt="" />
</div>
<!-- Background Slideshow -->`
CSS
#slider {
overflow: hidden;
/* Set rules to fill background */
min-height: 100%;
min-width: 100%;
/* Set up proportionate scaling */
width: 100%;
height: auto;
/* Set up positioning */
position: fixed;
top: 0;
left: 0;
z-index: -1;}
#slider > img {
float: left;
display: none;
//height: 1048px;
//width: 1571px;}
#slider iframe {
float: left;
//display: none;}
JS
sliderInt = 1;
sliderNext = 2;
$(document).ready(function(){
$('#slider>Img#1').fadeIn(1000);
startSlider();
});
function startSlider() {
count = $('#slider>Img').size();
loop = setInterval(function () {
if(sliderNext > count) {
sliderNext = 1;
sliderInt = 1;
}
$('#slider>Img').fadeOut(1000);
$('#slider>Img#'+ sliderNext).fadeIn(1000);
sliderInt = sliderNext;
sliderNext = sliderNext + 1;
}, 7000)
在你的祝酒词中。
这应该是
.show();
而不是
Toast.makeText(getApplicationContext(),"ringing",Toast.LENGTH_SHORT).show();