• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps TextView Slow what's the solution?

Sy Roz

Newbie
Hello to everyone...

So what's the issue I have is that the TextView become slow after a wile when its buffer gets full with information... You see it's reprints evry time entire buffer if it wold just append like it sounds that would not be happening. The speed of incoming information is 100ms.. So the textView gets freeze pretty fast.. .If Im delitting part of information it's become fast againt.. But I need to save it...
What I need is the solution Im pretty sure already exists in many different ways... Is that the textView reads the info to print from something like external buffer (String) just partly. Lets says its showing just a hundred last lines and if i scroll up it's downloads from that buffer what before that 100s? So how to that? It should called like textView control can't find really any info close to what I need.


Code:
  case ListPaireeDeviceActivity.MESSAGE_READ:

                    final String readMessage = (String) msg.obj;


                                   if(readMessage.contains(">")){
                                       textView_terminal.append(readMessage  +"\n" );

                                   }else {
                                       textView_terminal.append(readMessage );
                                   }
                       // textView_terminal.setText(readMessage);

                    }
                    break;
 
Just a suggestion but if the frequency of incoming messages is so rapid, why don't you batch them up and only write to the TextView when you receive, say 10 or 20 messages? That would give a 1 or 2 second update frequency.

Also what piece of code is receiving these messages? Reason for asking that is if you have this going in your main UI thread, it may cause performance problems. Normally you will get runtime warning messages if you are doing too much work on the main thread.
 
No it's over bluetooth "Connected" thread.. So nothing to do with main... And no this is not a solution getting 10 massages and print them as bunch.. Im trying to builled a terminal... if hardware can why the soft won't? But thanks for respond.
So seems like it's got to be like that.... The all incoming readMessage should be buffered in String or something maybe arrays and the only part of that should be shown in the TextView... Like last a 100 lines. And also nothing losted and I have access to it at my convenience.
Im sure theres a solution out there. just what's name of it?

Code:
 public void run() {

            Log.d(TAG2, "run start");
            byte[] buffer = new byte[512];  // buffer store for the stream
            int intBytes; // bytes returned from read()

            // Keep listening to the InputStream until an exception occurs
            StringBuilder readMessage = new StringBuilder();


            while (true) {
                try {

                    intBytes = mmInStream.read(buffer);
                    String readed = new String(buffer, 0, intBytes);
                    readMessage.append(readed);

                //    if (readed.contains("\n") || readed.contains(">")) {
                                                                               // readMessage.toString() активити.
                        mHandler.obtainMessage(MESSAGE_READ, intBytes, -1, readMessage.toString()).sendToTarget();

                        readMessage.setLength(0); //

                  //  }
 
Last edited:
Back
Top Bottom