Learn how to handle toast on Android apps

Asked 2 years ago, Updated 2 years ago, 435 views

I'm making an application on Android Studio, but what should I do if I want the toast to show "Stop processing" (remove processing while processing stops) and then change the toast to "Cancel processing" after the stop time?

I'm worried about what to do if it disappears after a few seconds of displaying it in the normal way of using toast.
I would like your advice.

ThreadSample.java

class ThreadSample extensions Thread {
    public void run() {

        try{
            Thread.sleep (10000L); // Stops threads for 10 seconds (10000ms)
        } catch(InterruptedExceptione) {

        }

    }
}

ThreadExecutor.java

class ThreadExecutor{
    public static void main(String[]args) {
        Threadt=new ThreadSample();
        t.start();
    }
}

java android

2022-09-30 21:54

1 Answers

It may be possible if you keep forcing it to be displayed, but it is not realistic to keep showing toast.
For example, a similar question has been asked.
https://stackoverflow.com/questions/2220560/can-an-android-toast-be-longer-than-toast-length-long

If you want to keep users informed when the app is in the foreground, consider snackbars specifications.
https://material.io/components/snackbars/android

If you still need notification after the application transitions to the background, consider notification in the status bar.
https://developer.android.com/guide/topics/ui/notifiers/notifications.html


2022-09-30 21:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.