Chris,
I think you are running into many of the same issues that I did with Android.  
The problem isn't MfA.  The problem is how the Android group at google has 
implemented their APIs.  MfA is a layer ontop of android, not an implementation 
of windows over android.  I have some concerns with Google's examples as well.  
At the same time, trying to span concepts across platforms doesn't feel right 
either.  
On to the issue...............First off, are you in a Service or an Activity?  
The title says one thing and the email seems to say something else.
It sounds like you have implemented ILocationListener in an Activity.  If your 
listener is set to null, have you assigned the activity to listen to the 
location manager for updates?
I would think that you could do something like what is done in iOS for many of 
its callbacks.  You could create a class that implements the necessary 
interface, create an instance of the interface, and then assign the class as a 
listener.  I haven't tried it that way, but I would think it would work.
Wally

From: cta...@opennetcf.com
To: monodroid@lists.ximian.com
Date: Thu, 29 Mar 2012 10:57:11 -0400
Subject: [mono-android] Services, Activities,   Contexts and separation of 
concerns



I’m having trouble wrapping my head around what seems to be a fairly 
fundamental requirement in Mono (or M4A anyway), and I’m looking for guidance. 
My experience in software development leads me to want to do separation of 
concerns and push toward patterns like MVC/MVP, but Mono seems to push back.  
Loads of things seem to require a Context or an Activity, which makes it 
challenging to separate out single services and work units. As a concrete 
example, I’m trying to create a Presenter that provides location information.  
I don’t want to just use the LocationManager as-is because architecturally it’s 
not right (in my mind anyway), plus I often will be getting location data from 
elsewhere.  So in my LocationPresenter, I want to encapsulate a 
LocationManager.  To do that I need to call GetSystemService on a Context.  So 
here’s my first need – a Context.  For now I usd IoC and just injected the 
MainLauncher Activity as a context and use that.  It feels a bit dirty but 
works. Then I said, “hey, I’d like to get location change notifications”, so I 
implemented ILocationListener in my Presenter.  Bear in mind it derives from no 
other classes.  First, it made me implement a Handle property.  That can’t be 
good – I don’t know where those come from or what it’s going to be tied to.  
When I run the app, no surprisingly it crashes with a 
“Java.Lang.RuntimeException: listener==null”, I assume because I don’t have the 
infrastructure in my Presenter that the LocationManager wants.  It doesn’t 
appear to be calling for the Handle (not hitting the break point) but it’s 
failing.  Maybe I’m on the wrong thread – but RunFromUiThread is again part of 
an Activity , which I’m not.  All examples have the listener as an Activity, 
which I assume will work, but it’s not what I want. So the question here, I 
guess, is how are other people handling this? Should I just resign myself to 
everything needing to be an Activity?  I hit similar issues when I was doing 
mapping.  I hit similar issue when I want to have a “common object resource” 
class.  Does M4A require me to alter some of my fundamental architecture 
thinking, or am I just missing something? -Chris 
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid                              
          
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

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

Reply via email to