Thanks, Boston, that's a good idea. I'll try to split my custom View
to smaller pieces, isolating the View-independent parts.

@Romain: thanks, we'll keep that in mind.

On Jun 27, 12:26 am, Streets Of Boston <flyingdutc...@gmail.com>
wrote:
> I would still advise against it, because you don't have control of the code
> after you call the constructor of the View.
>
> Creating a View should never be that expensive (i.e. time consuming) that
> it could not be done on the UI thread.
> If the creation of the View needs other pieces of data that are expensive
> to compute, just compute those pieces of data in the background thread and
> create the View in the UI thread after that, giving it the earlier computed
> data.
>
>
>
>
>
>
>
> On Tuesday, June 26, 2012 6:04:44 PM UTC-4, Tamás Kovács wrote:
>
> > OK I made additional research and source code exploring:
>
> > only *ViewGroup* and its descendants check the Thread, the *View*
> > class does not. It does not even STORE the thread which created it.
>
> > Based on this, it should be safe to create Views (but never
> > Viewgroups) in different threads. It would be nice if Dianne or Romain
> > could confirm this.
>
> > On Jun 26, 10:53 pm, Justin Anderson <magouyaw...@gmail.com> wrote:
> > > I'm not sure, but I doubt it...  Have you tried it? Did it work?
>
> > > Thanks,
> > > Justin Anderson
> > > MagouyaWare Developerhttp://sites.google.com/site/magouyaware
>
> > > On Tue, Jun 26, 2012 at 2:27 PM, Tamás Kovács
> > > <falcon.firebre...@gmail.com>wrote:
>
> > > > I know that the UI elements (View hierarchy) may only be manipulated
> > > > from the UI thread. For a background operation, the AsyncTask can be
> > > > used, which offers event handers to reach the UI thread.
>
> > > > To be brief, is it allowed to instantiate a View (tied to
> > > > getApplicationContext()) in a non-UI thread? This custom View
> > > > descendant -- once instantiated -- is added to the view hierarchy from
> > > > the UI thread. So only the constructor call is done inside an
> > > > Asynctask.doInBackground; its attaching (addView(...))to the
> > > > Activity's root layout hierarchy is still done in the UI thread.
>
> > > > (I pre-instantiate the View in an asynctask because when it's needed
> > > > in an Activity, it must be instantly displayed.)
>
> > > > --
> > > > 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+unsubscr...@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to