question: public String popAndEncodeAsJs ( ) { synchronized ( this ) { int length = queue . size ( ) ; if ( length == 0 ) { return null ; } int totalPayloadLen = 0 ; int numMessagesToSend = 0 ; for ( JsMessage message : queue ) { int messageSize = message . calculateEncodedLength ( ) + 50 ; if ( numMessagesToSend > 0 && totalPayloadLen + messageSize > MAX_PAYLOAD_SIZE && MAX_PAYLOAD_SIZE > 0 ) { break ; } totalPayloadLen += messageSize ; numMessagesToSend += 1 ; } boolean willSendAllMessages = numMessagesToSend == queue . size ( ) ; StringBuilder sb = new StringBuilder ( totalPayloadLen + ( willSendAllMessages ? 0 : 100 ) ) ; for ( int i = 0 ; i < numMessagesToSend ; ++ i ) { JsMessage message = queue . removeFirst ( ) ; if ( willSendAllMessages && ( i + 1 == numMessagesToSend ) ) { message . encodeAsJsMessage ( sb ) ; } else { sb . append ( "try{" ) ; message . encodeAsJsMessage ( sb ) ; sb . append ( "}finally{" ) ; } } if ( ! willSendAllMessages ) { sb . append ( "window.setTimeout(function(){cordova.require('cordova/plugin/android/polling').pollOnce();},0);" ) ; } for ( int i = willSendAllMessages ? 1 : 0 ; i < numMessagesToSend ; ++ i ) { sb . append ( '}' ) ; } String ret = sb . toString ( ) ; return ret ; } }
target:  Same as popAndEncode(), except encodes in a form that can be executed as JS.