In my application, the next toast appears again and again when the application goes into the background, so I did the following to solve the problem.
Add code to detect when the application goes into the background. One way to register a lifecycle handler. Read more ... ref
registerActivityLifecycleCallbacks(new MyLifecycleHandler());
App.inBackground = true; when the app goes into the background and shows a toast using the SmartToast class
public class SmartToast { static ArrayList<WeakReference<Toast>> toasts = new ArrayList<>(); public static void showToast(@NonNull Context context,@NonNull String message){
call the SmartToast.cancelAll(); method SmartToast.cancelAll(); when the app goes into the background to hide the current and all pending toasts. Code is fun. Enjoy it!
Qamar
source share