[Monodroid] How to load Assets outside of an Activity?

Amir Waldman amirw2k at gmail.com
Tue Mar 1 10:43:46 EST 2011


With OnPause/OnResume you're asked to save your app's state somewhere and
resume it later, and while doing that you can re-cache the global reference
to the main activity. 
The app's state can be worked out if it is possible to save and restore .NET
objects. I'm still not sure how well it's going to work...

As for your question, I have no direct access to a View either. Currently
I'm caching a reference to the main activity in a global static variable
located in a class library. This allows other parts of the code to load
assets without having to know about Android.
I'm still playing with it, looking for better ways though.	


Regards,
Amir



-----Original Message-----
From: monodroid-bounces at lists.ximian.com
[mailto:monodroid-bounces at lists.ximian.com] On Behalf Of Mike Kestner
Sent: Tuesday, March 01, 2011 5:25 PM
To: monodroid at lists.ximian.com
Subject: Re: [Monodroid] How to load Assets outside of an Activity?

On Tue, 2011-03-01 at 17:11 +0200, Amir Waldman wrote:
> That can't be good... What if you were in the middle of editing data? The
> main activity (marked with: MainLauncher = true) holds the entire state of
> the application. How can it kill and recreate itself?

OnPause/OnResume.  Your activity needs to know how to reload itself.
This includes the user jumping to other apps and potentially coming back
to your activity at a later time.  You activity can get blown away at
any time for resource issues, etc...

You many want to take a look at:

http://developer.android.com/guide/topics/fundamentals/activities.html

There's a fairly extension discussion of lifecycle on that page.

> Is there an easier way to instantly get a reference to Context? All I want
> is to load an Asset using external code without worrying about it too
much.

Where are you doing this?  "External code" is a bit vague.  If it's in a
view in response to an event or listener callback, View.Context will
give you the current context.  

Mike

_______________________________________________
Monodroid mailing list
Monodroid at lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid



More information about the Monodroid mailing list