탭에서 다른 탭으로 전환 할 때 Toast
을 "제거"하려고하므로 포커스가있는 탭 작업이 일시 중지되었다고 가정합니다. 기본적으로 취소 메서드를 단일 Toast
개체에 적용하거나 null에 할당 할 수 있습니다. 이 작동합니다.스레드 토스트 메시지 삭제
요점은 TextView를 사용하고 토스트를 스레드 할 때 스레드를 멈추더라도 토스트가 계속 표시된다는 것입니다. 나는 this point에서 시작하여 토스트를 실을 때 this one에 따라 멈추려고합니다.
스레드를 중지하고 시스템 대기열에서 토스트를 제거하는 방법 또는 그 목표를 달성하는 더 좋은 해결책이 있습니까 (예 : 단일 활동의 여러 토스트, 활동에서 다른 토큰으로 교환 할 때 토스트 표시 중지)? 축배를 (이 괜찮습니다)를 호출
:
private void showSingleToast(String toastText, int color, long duration_ms) {
if (mySingleToast instanceof Toast) {
mySingleToast.setText(toastText);
if (null != toastView)
if (toastView instanceof TextView)
toastView.setTextColor(color);
ToastExpander.showFor(mySingleToast, duration_ms);
}
}
토스트를 "제거"하기 위해 노력 Toast.show()
public class ToastExpander extends Thread {
public static final String TAG = "ToastExpander";
static Thread t;// = null;
// Must be volatile:
static volatile boolean stopFlag = false;
static long scan_freq = 300;
public static void showFor(final Toast aToast, final long durationInMilliseconds) {
aToast.setDuration(Toast.LENGTH_SHORT);
t = new Thread() {
long timeElapsed = 0l;
public void run() {
try {
while (timeElapsed <= durationInMilliseconds || !stopFlag) {
long start = System.currentTimeMillis();
aToast.show();
sleep(scan_freq);
timeElapsed += System.currentTimeMillis() - start;
}
// doesn't work: aToast.cancel();
} catch (InterruptedException e) {
Log.e(TAG, e.toString());
}
} /* end of "run" */
}; /* end of Thread */
t.start();
} /* end showFor */
public static void cancel() {
stopFlag = true;
}
}
스레딩 (작동하지 않음)
private void hideSingleToast() {
//hideTextView(toastView);
toastView = null;
ToastExpander.cancel();
mySingleToast.cancel();
//mySingleToast= null;
}
mySingleToast가 onCreate에서 만들어 졌는지 확인합니다. – hornetbzz