2012-04-10 66 views
0

創建一個線程我有以下代碼:在toat消息

String state= bundle.getString(TelephonyManager.EXTRA_STATE); 
if (state.equalsIgnoreCase(TelephonyManager.EXTRA_INCOMING_NUMBER) 
{ 
Toast toast= new Toast(context); 
toast.setGravity(Gravity.TOP,0,0); 
toast.setDuration(Toast.Length_LONG); 
toast.makeText(..).show(); 
toast.show(); 
} 

我需要保持敬酒,直到有人應答的電話。怎麼做? 我知道我必須創建並開始一個線程,當我有來電號碼,並在該人回答時停止線程。如何做到這一點?

THX

回答

0

嘗試這樣的..

Toast.Length_LONG gives toast for only 3.5 seconds.. 

所以..創造3.5秒的countdowntimer像this..in您的活動的onCreate

String state= bundle.getString(TelephonyManager.EXTRA_STATE); 
MyCount counter; 
counter=new MyCount(3500,1000); 
counter.start(); 

mycount的類..

public class MyCount extends CountDownTimer{ 
public MyCount(long millisInFuture, long countDownInterval) { 
super(millisInFuture, countDownInterval); 
} 
@Override 
public void onFinish() { 
if (state.equalsIgnoreCase(TelephonyManager.EXTRA_INCOMING_NUMBER){ 
    Toast toast= new Toast(youractivity.this); 
toast.setGravity(Gravity.TOP,0,0); 
toast.setDuration(Toast.Length_LONG); 
toast.makeText(..).show(); 
toast.show(); 
    counter= new MyCount(3500,1000); 
counter.start(); 
    } 

} 
@Override 
public void onTick(long millisUntilFinished) { 
    } 
} 
} 

這不斷顯示烤麪包,直到你接聽電話..或你的來電因超時而結束。

+0

我要在哪裏啓動櫃檯?如果條件? – user1222905 2012-04-10 16:09:41

+0

我有錯誤:在新班級中無法識別州。我的基類叫做IncommingCalls.java – user1222905 2012-04-10 16:14:42

+0

我應該填充什麼? – user1222905 2012-04-10 16:22:56