Monodroid – starting a new activity
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.