2012-11-05 164 views
0

我有一個顯示逐幀動畫活動的Android應用程序。在動畫結束時,它啓動後臺服務並關閉活動。這裏是代碼:Android應用程序不會再運行

cont = getApplicationContext(); 

    final ImageView img = (ImageView)findViewById(R.id.img); 
    img.setBackgroundResource(R.drawable.intro); 

    img.post(new Runnable() {   
     public void run() { 
      animation = (AnimationDrawable)img.getBackground(); 
      animation.setOneShot(true); 
      animation.start(); 
      timer = new Timer(); 
      timer.schedule(new timer_exp(), 3400); 
     } 
    }); 
} 



class timer_exp extends TimerTask{ 
    @Override 
    public void run() { 
     //start service 
     Intent serviceIntent = new Intent(cont, MainService.class); 
     startService(serviceIntent); 
     //kill activity 
     finish();   
    } 

} 

當我運行應用程序,我可以看到動畫,然後服務啓動。當我再次按下應用程序的圖標時,出現黑屏,應用程序崩潰。

任何想法可能是什麼問題?

感謝, PB

+0

LogCat中的輸出是什麼?提到的任何異常? – RvdK

+0

當我第二次按下圖標時,LogCat上什麼都沒有。 –

+2

如果它崩潰,那麼你會在LogCat中得到一些東西。再看一次 – wnafee

回答

0

經過一番調查,原來該服務是問題。 我在幾個導致UI線程崩潰的地方有一些Thread.sleep()。 爲這些操作添加另一個線程後,問題就解決了。

相關問題