[mono-android] Threading with Rotation

Sayed Arian Kooshesh kooshesh at gmail.com
Tue Dec 13 23:46:33 EST 2011


please stop using threads. pleas learn backgroundworker. or i will
find you. I will cut you open. I will eat your innards. is that threat
enough to make you write GOOD code? or are you forever doomed to bitch
on lists like this because you have problems. the problems being
shitty code and the solution being you STOP being a fucking
programmer.

On Tue, Dec 13, 2011 at 9:31 PM, Jonathan Pryor <jonp at xamarin.com> wrote:
> On Nov 16, 2011, at 1:10 PM, emalamisura wrote:
>> A common issue with maintaining state is handling Rotation with multiple
>> threads in Android.  For instance if you start a thread, and then rotate the
>> phone before the thread is done with its work Android destroys the previous
>> Activity and generates a new one.  Any references you had to your previous
>> activity will cause a reference exception.
>
> Right. Don't do that. :-)
>
> I'm also not sure what scenario you're thinking of. Activities are tied to their Main thread -- it isn't safe to interact with them except via the main thread or Activity.RunOnUiThread() -- and anything associated with the Activity follows the same rules as well. This would include the LastNonConfigurationInstance value, as used at:
>
>        http://stackoverflow.com/a/8331994/83444
>
> So the primary question is this: why are multiple threads using an Activity instance? If it's to use Activity.RunOnUiThread(), use an alternative, such as a Handler instance over the MainLooper:
>
>        http://support.xamarin.com/customer/portal/questions/34836-toast-in-service
>
>> This becomes even more difficult
>> to handle in MonoDroid because alot of the semantics used in Java such as
>> using an internal static class inside your activity can't easily be
>> reproduced in C#
>
> I also don't understand this. Java's `static` nested classes are ~identical to C# nested types; it's non-`static` nested classes which differ.
>
> Thanks,
>  - Jon
>
> _______________________________________________
> Monodroid mailing list
> Monodroid at lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid



-- 
Extreme Knowledge is not something for which he programs a computer
but for which his computer is programming him.

-Wozniak


More information about the Monodroid mailing list