java - Android Activity takes too long to show content -
first of help!!!
i have next problem.
my activity in oncreate() performs long computations take time.
in same oncreate() phone call setcontentview() set appearance of activity.
the point that, since takes while performs above mentioned computations screen of activity loads after long time.
please, suggestion on how avoid this?
i have tried phone call setcontentview() in oncreate() , start computations in onresume(), 1 time again activity screen loaded @ end.
thanks lot suggestion!
there no other way utilize e.g. asynctask. reason actual rendering not take place asynchronously; in other words, setcontentview set info nil displayed @ point in time.
asynctask, however, not meant "long" computations. if app relies on result, , no other computations take place in parallel, may still simplest way accomplish want. if not, may have utilize thread even.
update since keeps bombarding original poster more use asynctask answers of various quality, i'd stress 1 more time asynctask intended short operations (to quote reference: a few seconds @ most) while op has given no indication on how long computations take. also, asynctask one-shot-only object can run once.
one more of import point consider following. android assigns asynctask background task priority. means that, besides lower scheduling priority, computations in asynctask take 10 times long if performed in foreground, because android runs tasks have background priority artificial limit of 10% cpu cycles. however, asynctasks can lifted out of grouping raising priority "just little bit". asynctask, done so:
public r doinbackground(i... is) { process.setthreadpriority(process.thread_priority_background + process.thread_priority_more_favorable); ... }
java android android-activity
No comments:
Post a Comment