package com.example.myapplication.Tool;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;

public class BackgroundToast {
    private static Handler handler;
    private static Toast currentToast;

    public static void show(final Context context, final String message) {
        if (handler == null) {
            handler = new Handler(Looper.getMainLooper());
        }

        handler.post(() -> {
            // 取消之前的Toast
            if (currentToast != null) {
                currentToast.cancel();
            }

            // 创建新的Toast
            currentToast = Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_SHORT);
            currentToast.show();
        });
    }
}