1. Download our Official Android App: Forums for Android!

Apps TextView Slow what's the solution?

Discussion in 'Android Development' started by Sy Roz, Mar 10, 2016.

  1. Sy Roz

    Sy Roz Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    10
    Joined:
    Feb 29, 2016

    Feb 29, 2016
    10
    1
    16
    Male
    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 (Text):
    1.   case ListPaireeDeviceActivity.MESSAGE_READ:
    2.  
    3.                     final String readMessage = (String) msg.obj;
    4.  
    5.  
    6.                                    if(readMessage.contains(">")){
    7.                                        textView_terminal.append(readMessage  +"\n" );
    8.  
    9.                                    }else {
    10.                                        textView_terminal.append(readMessage );
    11.                                    }
    12.                        // textView_terminal.setText(readMessage);
    13.  
    14.                     }
    15.                     break;
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Recognized Developer
    Rank:
     #12
    Points:
    1,988
    Posts:
    9,176
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    9,176
    13,681
    1,988
    Male
    Software developer
    South West of England
    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.
     
  3. Sy Roz

    Sy Roz Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    10
    Joined:
    Feb 29, 2016

    Feb 29, 2016
    10
    1
    16
    Male
    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 (Text):
    1.  public void run() {
    2.  
    3.             Log.d(TAG2, "run start");
    4.             byte[] buffer = new byte[512];  // buffer store for the stream
    5.             int intBytes; // bytes returned from read()
    6.  
    7.             // Keep listening to the InputStream until an exception occurs
    8.             StringBuilder readMessage = new StringBuilder();
    9.  
    10.  
    11.             while (true) {
    12.                 try {
    13.  
    14.                     intBytes = mmInStream.read(buffer);
    15.                     String readed = new String(buffer, 0, intBytes);
    16.                     readMessage.append(readed);
    17.  
    18.                 //    if (readed.contains("\n") || readed.contains(">")) {
    19.                                                                                // readMessage.toString() активити.
    20.                         mHandler.obtainMessage(MESSAGE_READ, intBytes, -1, readMessage.toString()).sendToTarget();
    21.  
    22.                         readMessage.setLength(0); //
    23.  
    24.                   //  }
    25.  
     
    #3 Sy Roz, Mar 10, 2016
    Last edited: Mar 10, 2016

Share This Page

Loading...