Wally,

The problem is in my semantics.  I tend to call classes that I have back in the 
model that provide specific functionality "Services" (and the get added into my 
IoC framework's Services collection).  It's not a Proper Android Service.  It's 
actually just a plain old class that I inherited ILocationListener with.  
Turned out it needed to also be a Java.Lang.Object inheritor (this is what was 
killing me this time) - this gives me some heartburn as now that service code 
is not cross-platform compatible.  I'll likely create either some new base 
class that will be a java Object under Mono and strip that out under other 
platforms, or I'll create a stub replacement for Java.Lang.Object for the 
desktop and Compact Frameworks so the code will compile there.

Our code base *has* to run on all of these platforms (and MonoTouch as well), 
and do so without platform-specific maintenance.  It makes things like this a 
bit of a challenge.

-Chris


From: monodroid-boun...@lists.ximian.com 
[mailto:monodroid-boun...@lists.ximian.com] On Behalf Of Wally McClure
Sent: Friday, March 30, 2012 9:45 AM
To: monodroid@lists.ximian.com
Subject: Re: [mono-android] Services, Activities, Contexts and separation of 
concerns

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.  [https://gfx5.hotmail.com/mail/w4/pr04/ltr/emo/smile.gif]

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