Chris,

Thanks for the input and suggestions.  I'm trying to get enough understanding 
on this so I can start writing some blog entries on "mono for CF developers" 
and "sharing code across platforms, including mono". Any little bit of info or 
"this is what we've done" bit helps.

-Chris


From: monodroid-boun...@lists.ximian.com 
[mailto:monodroid-boun...@lists.ximian.com] On Behalf Of Tossing, Chris
Sent: Friday, March 30, 2012 9:47 AM
To: Discussions related to Mono for Android
Subject: Re: [mono-android] Services, Activities, Contexts and separation of 
concerns

Chris,

I come from a similar background as yours - Windows Mobile 6.5.  I have relied 
on your work and posts fairly heavily, so thank you.  I hope I can return 
something back.

We are actually sharing, I would estimate, about 80-90% of our code across 
Windows Mobile 6.5, Android, and iPhone using MonoTouch and Mono for Android.  
We are using an MVC/MVP pattern very successfully across those three platforms, 
able to implement new screens fairly rapidly.

We have a number of classes like you describe that require a context to 
operate.  Basically, we have implemented a way to always know what the current 
context is by having a base Activity class which updates the current Activity 
in a globally accessible place.  Our Android-specific implementation of the 
interface in question, would simply use the current Activity as it's context 
for every call.

I could go into more details, but that's the basic premise.  I hope that helps.

Thank you,

Chris Tossing
Software Engineer
G4S Technology Software Solutions LLC
Direct Dial:      +1 (781) 457-0779
Cell:                +1 (847) 942-0359
chris.toss...@usa.g4s.com<mailto:chris.toss...@usa.g4s.com>
www.1f.com<http://www.1f.com/>
21 North Avenue, Burlington, Massachusetts 01803 USA

P Please consider the environment before printing this email

From: monodroid-boun...@lists.ximian.com 
[mailto:monodroid-boun...@lists.ximian.com] On Behalf Of Chris Tacke
Sent: Thursday, March 29, 2012 10:57 AM
To: Discussions related to Mono for Android
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


________________________________
The details of this company are as follows:
G4S Technology Limited, Registered Office: Challenge House, International 
Drive, Tewkesbury, Gloucestershire GL20 8UQ, Registered in England No. 2382338.

This communication may contain information which is confidential, personal 
and/or privileged.

It is for the exclusive use of the intended recipient(s).
If you are not the intended recipient(s), please note that any distribution, 
forwarding, copying or use of this communication or the information in it is 
strictly prohibited.

Any personal views expressed in this e-mail are those of the individual sender 
and the company does not endorse or accept responsibility for them.

Prior to taking any action based upon this e-mail message, you should seek 
appropriate confirmation of its authenticity.

This e-mail has been scanned for all viruses by MessageLabs.
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

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

Reply via email to