invokeLongTimeToast()函数关键在于调用initToast()方法。而initToast()又会调用execToast()方法,从而引发递归,cnt是序列号,当cnt等于3时停止递归,用它来调节Toast的显示时间。
/**
* After a time show a <code>Toast</code> again.
*
* @param toast
* <code>Toast</code>
* @param cnt
* Sequence
*/
private void execToast(final Toast toast, final int cnt) {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
initToast(toast, cnt + 1);
}
}, 3000);
}
/**
* Show the <code>Toast</code> and {#execToast}
*
* @param toast
* <code>Toast</code>
* @param cnt
* Sequence
*/
private void initToast(Toast toast, int cnt) {
if (cnt > 2)
return;
toast.show();
execToast(toast, cnt);
}
/**
* Show a <code>Toast</code> much longer than normal.
*
* @param info
* <code>String</code> that wants to show.
*/
public void invokeLongTimeToast(final String info) {
Toast toast = Toast.makeText(sa, info, Toast.LENGTH_LONG);
initToast(toast, 0);
}