Vote count:
0
I'd love to post some code, but there's a lot of code that goes into this, and I have absolutely no idea where the error lies. I've print debugged the whole 600ish lines and come up with virtually nothing useful.
So, the main activity of my apps skips about 200 frames every time it is is resumed, according to LogCat. "Doing too much work on its main thread". So when I start another activity then go back to the main, when I exit the app then return to it, etc. The main activity consists of a scrollview containing a list of items for the user to click on, and a corresponding image icon for each item. These elements are inserted programmatically via an AsyncTask, but the lag happens after they're all displayed on the screen.
The issue is, it's doing virtually nothing on its main thread. I have not overridden onResume, but even during onCreate, the only things that it does that aren't AsyncTasks is this code:
c = this;
hallTexts = (LinearLayout) findViewById(R.id.lister);
hallImages = (LinearLayout) findViewById(R.id.symbol);
hallTexts.removeAllViews();
hallImages.removeAllViews();
final int height = ((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
(float) HEIGHT_OF_LIST_ELEMENT, getResources().getDisplayMetrics()));
final int rulerHeight = ((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
(float) HEIGHT_OF_HORIZONTAL_RULE, getResources().getDisplayMetrics()));
final int rulerMargin = ((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
(float) HORIZONTAL_RULE_MARGIN, getResources().getDisplayMetrics()));
//This grabs the list elements from a Singleton class, creates textviews for them, then puts them into the activity during onPostExecute
AsyncTask1.execute();
//Same thing, but for the icons
AsyncTask2.execute();
But again, the lag happens whenever the app is resumed, and after all the AsyncTasks have finished (I checked, and the skipped frame messages come long after I get the "finished" printout from every thread).
Is there are reason why this may be happening? I'm fairly new to android development, and while I did a quick tutorial course, I'm mostly just learning as I go along, so it's quite possibly I'm making some rookie mistake here.
Android activity skips frames any time it is resumed
Aucun commentaire:
Enregistrer un commentaire