On Jul 22, 9:24 am, Micah <[email protected]> wrote:
> If the code you are running takes long enough to noticeably block the
> UI (ie: more than 200ms) then you should do it in another thread.
> Allowing the user to see the UI but not interact with it (because your
> app is doing some heavy lifting in the main thread) is just as bad of
> a user experience as having to wait a long time for the app to load.
> The only exception is if you put up a loading screen that says
> something along the lines of "please wait" but that's still not nearly
> as user friendly as doing the heavy lifting in another thread.

Well, there are a couple of different issues here.  Clearly you
shouldn't block the UI thread too long for obvious reasons.  "Too
long" is something you have to decide for yourself, but the ANR
timeout is certainly an upper bound on it.

So if you have expensive stuff you need to do at activity init time
there aren't too many options.  All other things being equal, you
should push whatever you can to a background thread so that you don't
block whatever UI activity is happening (even if it's just updating a
progress spinner).

That's all a given.  What I was asking about was how to
deterministically run a chunk of code immediately after the activity
becomes visible, and that's what pskink answered.  In my particular
case my init code needs to first run on the UI thread, and then I
background an expensive process and call back to the UI thread when
it's done, but that's beside the point.

I'm not sure I understand your dichotomy between either putting up a
"please wait" notice *or* doing stuff in a background thread.  If you
aren't ready for user interaction until the background stuff is done
then you need to do both.  If you can let the user do something useful
while the background stuff is going on then all the better (but that's
not my case at the moment).

So I think we mostly agree but are having two different
conversations. :-)

-- Peter

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to