Friday, August 19, 2011

Re: [android-developers] Re: Updating UI from second thread

Yeah you should redesign your app. Or, come up with some sort of
buffer solution.
Depends on how often your check function runs, and how critical it is
to the UI interaction.
Maybe setup event listeners for every checkbox so that it keeps track
of an internal structure what needs to be checked, and what doesn't.
Then tell your calculation thread to calculate what needs to be checked.
After the calculation is done, the thread tells the ui what to check.

This *might* work. Where you avoid the thread/queue overhead and
manipulate the UI in batches. (and really, you should only be
manipulating what's visible on the screen.)

On Fri, Aug 19, 2011 at 7:55 AM, David Turner <digit@android.com> wrote:
>
>
> On Fri, Aug 19, 2011 at 1:35 PM, Snowak <psnowak@gmail.com> wrote:
>>
>> What a wonderful answer. It's a great idea to answer everything with
>> "you don't know what you're doing" and tell me to do it using worst
>> possible method. Yeah, let's freeze the UI thread. It's gonna be cool.
>>
> You can't do the work on another thread, and the "work" is slow because each
> UI widget is actually a very sophisticated thing due to the way the
> framework works and the number of features it supports (think about layout
> recomputations, focus events, handling right-to-left and left-to-right
> layout, and more, much more things).
> Really, anyone using hundreds of widgets (checkboxes, or whatever) and
> complaining that the UI is too slow should really get a clue-stick and start
> re-designing their code.
>
>>
>> On 17 Sie, 23:17, Mark Murphy <mmur...@commonsware.com> wrote:
>> > On Wed, Aug 17, 2011 at 12:44 PM, Snowak <psno...@gmail.com> wrote:
>> > > I have hundreds of CheckBox widgets in my layout
>> >
>> > That is unlikely to be a good idea.
>> >
>> > > Obviously such heavy work should be done in separate thread,
>> >
>> > Not really.
>> >
>> > > The only thing that this thread actually can do is looping through the
>> > > list and posting the Runnable for every found checkbox. The problem is
>> > > that all those Runnables arrive in the UI thread almost at the same
>> > > time, thus they're all executed at once... The application behaves
>> > > exactly like I would run the above code in the UI thread - everything
>> > > freezes. A possible solution is sleeping for some miliseconds after
>> > > each checkbox so the Runnable can be executed and the UI will have
>> > > time to process the events... but it's more like a hack.
>> >
>> > > How can I solve this problem?
>> >
>> > Redesign your UI to not have "hundreds of CheckBox widgets" at once.
>> > Or, update them on the main application thread and hope for the best.
>> >
>> > --
>> > Mark Murphy (a Commons
>> > Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>> >
>> > _Android Programming Tutorials_ Version 3.9 Available!
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscribe@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

--
~ Jeremiah:9:23-24
Android 2D MMORPG: http://solrpg.com/http://www.youtube.com/user/revoltingx

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

No comments:

Post a Comment