I’m writing a Monodroid app that has a main “dashboard” screen and several other “child” screens. Here is how I wire up a button to start up one of the “children” screens:
Note that the static “ClassName” property is just a string, and my lame attempt at not repeating magic strings. The value is “monoStockPortfolio.AddPortfolioActivity”, which can be found in your AndroidManifest.xml.
The “intent” object can be used to pass information to the child screen, which I’ll show in a later post. By using “StartActivityForResult”, the user can click the “back” button found on all Android devices to leave the child screen (with the correct transition). Alternatively, here is how the user can get back without using the back button (i.e. they complete some task on the child screen):
Here I’m saving a new portfolio with a repository, but the key part is the last 3 lines. I’m creating another Intent object, but I’m using it to set a “result” (recall that I used StartActivityForResult to get here). And then I’m calling “Finish” to end the activity.
You can check out the full source code of this project as I go along at GitHub.
Hello mgroves
I’ve downloaded this code for studying and incorporating this child activity start in my project . The code successfully gets compiled and deployed to emulator but when the app gets started after splash screen showing the NULL Reference exception occurs at MainActivity.Cs==>OnCreate()==> _presenter.Initialize().
Can you just see if you are able to run in monoandroid 4.0.1 which is a recent update for Monodroid.
Thanks
It’s probably because _presenter is null. I use the [IoC] attribute, which is a PostSharp aspect that lazily instantiates the field at runtime. If you aren’t using PostSharp, and/or you removed that [IoC] attribute, then you’ll have to new-up _presenter some other way, like a service locator, or even worse, a plain old “new”. Here’s some examples: https://gist.github.com/1510659 – You could also try property injection, available with some IoC tools, and use a “BuildUp” (or similar) in the same way that you would with WebForms/WinForms.
Or you could just try installing PostSharp, which is free, but isn’t officially supported on Mono: http://mgroves.com/monodroid-with-postsharp/