Note that there are some explanatory texts on larger screens.

plurals
  1. POString processing very slow in new Android version(4.3)
    primarykey
    data
    text
    <p>I am trying to break a String into multiple pages. The string contains a story(hence a bit long one) and I need to load this into an ArrayList of Strings which will be displayed as various pages. </p> <p>Below is the method in my code which takes in the long string and breaks it into pages and loads the ArrayList of Strings. My problem is that this works pretty fast in Android 3.2. But in my another phone which is 4.3, it loads very slow(say it takes about 10 seconds for what works in 2 seconds in 3.2 one). Below is my code. Can anyone of you please suggest any improvements here in the code which can make it work faster in the new version. Not sure why should new version process slower than the old one. </p> <pre><code>TextView contentTextView = (TextView)findViewById(R.id.textViewStory1); String contentString; TextPaint tp = contentTextView.getPaint(); String[] pages; int totalPages=0; ArrayList&lt;String&gt; pagesArray = new ArrayList&lt;String&gt;(); public void loadStory(String storyName){ //initialize variables numCharsLine=0; contentString = getStringFromTxtFile(storyName); int linesInOnePage = getLinesInPage();//get how many lines will be displayed in one page //load story into arraylist pagesArray while (contentString != null &amp;&amp; contentString.length() != 0) { totalPages ++; int numChars = 0; int lineCount = 0; while ((lineCount &lt; linesInOnePage) &amp;&amp; (numChars &lt; contentString.length())) { numCharsLine = tp.breakText(contentString.substring(numChars), true, pageWidth, null); numChars = numChars + numCharsLine; lineCount ++; } // retrieve the String to be displayed in pagesArray String toBeDisplayed = contentString.substring(0, numChars); contentString = contentString.substring(numChars); pagesArray.add(toBeDisplayed); numChars = 0; lineCount = 0; } //get the pagecount and reset pageNumber to current page totalPages=pagesArray.size(); pages = new String[pagesArray.size()]; pages = pagesArray.toArray(pages); } </code></pre> <p>Also below is the method for loading the contents of text file into the string</p> <pre><code> public String getStringFromTxtFile(String fileName) { try { InputStream is = getAssets().open(fileName+".txt"); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); return new String(buffer); } catch (IOException e) { throw new RuntimeException(e); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload