In a background thread's constructor, retrieve the global context
using getApplicationContext().   Then you can use that to look up
resources, it works, I do it all over.

On Jan 26, 12:49 am, elDoudou <the.edouard.merc...@gmail.com> wrote:
> Thank you Kostya.
>
> Yes, my intent is to invoke those methods from a worker background
> thread.
>
> You assume that I want to get i18n string to update the UI, but this
> is not my exact use case. I need to get an i18n string, because I want
> to prepare the computation of a string (imagine that the string
> computation takes a lot of time, it may make sense, for instance),
> which will eventually be used on a UI thread to update the display,
> which is slightly different.
>
> Your phone settings changes while the background thread is still
> running example is a very well chosen use case, and I do not see how
> the AsyncTask enables that properly neither.
>
> Not to mention the fact that there is no synchronization mechanism
> around the "Fragment.getActivity()": if I test its nullity, nothing
> prevents it from being null in the if statement body. I cannot figure
> out why the "Fragment.getText()/getString()/getResources()" methods
> correct execution may need to depend on the fragment state. At least,
> the "Fragment.getActivity()" method should throw an
> "IllegalStateException" instead of "null" when the fragment has been
> detached, or even better, a dedicated exception also used for the
> previous methods.
>
> I'm still investigating, on how to handle that properly...
> Regards,
> Édouard

-- 
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