2011-01-21 80 views
1

在我寫的Android應用程序中,我希望我的活動顯示我公司的徽標,然後在三秒鐘後啓動一項新活動。我已經完成了佈局和圖形,但我不知道如何製作計時器。在Android中製作三秒鐘定時器的最簡單方法是什麼?

創建三秒定時器的最簡單,最簡單的方法是什麼?

非常感謝您提前收到我收到的所有回覆。

回答

2

勞倫斯道森的答案是好的,但(1)直接進入處理程序部分,(2)爲您的應用程序你想要postDelayed而不是postAtTime

其實是有nearby answer very close to what you're looking for,但不是調用start,要實例化一個處理程序,並使用postDelayed後安排您的Runnable 3秒。

+2

你甚至不需要`Handler`。 `View`的任何子類都可以使用`postDelayed()`,例如用於徽標的`ImageView`。 – CommonsWare 2011-01-21 15:55:34

0

這裏你去...只是tru線程..線程會讓一些時間後你的活動睡覺,然後開始一個intent ..和你必須完成()活動,當它處於暫停模式:D看到這個

 Thread t = new Thread() 
    { 
     public void run() 
     { 
      try{ 
       sleep(3000); 
      }catch(InterruptedException ie) 
      { 
       ie.printStackTrace(); 
      }finally 
      { 
     Intent i = new Intent(getApplicationContext(), login.class);       
       startActivity(i); 
      } 
     } 
    }; t.start(); 
} 
public void onPause() 
{ 
    super.onPause(); 
    finish(); 
} 
相關問題