1. Check out our companion app, Forums for Android! Download from Google Play

Flushing Toast/TextView buffer in While loop

Discussion in 'Application Development' started by #iNjection-, Mar 1, 2010.

  1. #iNjection-

    #iNjection- New Member
    Thread Starter

    Mar 1, 2010
    I have a mini app i use to connect to a TCP listener script. The problem i am having is taht when a message is received by the listener script, it will send it to all open sockets currently connected.

    Within the Android app, i have a line where i am doing the following:

    1. while((responseLine = is.readLine()) != null)
    2.             {
    3.                 Toast.makeText(context, responseLine, Toast.LENGTH_LONG).show();
    5.                 if (responseLine.indexOf("Ok") != -1) {
    6.                     break;
    7.                 }
    8.             }
    is.readLine() is the resource returns by DataInputStream. Now, my Listener is set to send a message of Ok if no input has been sent within 30 seconds, so of course, it will break the while. But it is at this point, all messages from the other sockets are displayed via Toast or TextView if I implement that.

    Does anyone know of a way to flush Toast or TextView while inside of an indefinite While loop? I know the incoming messages are being appended to the buffer, but can't output until the while is killed?

    First stab at Java/Android, extremely familiar with PHP though. In PHP you can just call flush() or ob_flush, etc to clear the buffer, but does not appear you can do that with java.



  2. KlaymenDK

    KlaymenDK Well-Known Member

    May 29, 2009
    As I understand it, Toasts are fire-and forget things that you can't subsequently cancel. You can't even get a guarantee they won't be interlaced with Toasts from other apps.

Share This Page