[{"data":1,"prerenderedAt":1097},["ShallowReactive",2],{"article-xamarin-player-failed-to-initialize-device-nexus4":3},{"article":4,"tags":206,"previous":221,"next":521},{"id":5,"title":6,"author":7,"body":8,"createdAt":195,"description":196,"extension":197,"img":28,"meta":198,"navigation":199,"path":200,"seo":201,"stem":202,"tags":203,"updatedAt":195,"__hash__":205},"articles\u002Farticles\u002Fxamarin-player-failed-to-initialize-device-nexus4.md","Xamarin Player Failed to initialize device Nexus4","[object Object]",{"type":9,"value":10,"toc":191},"minimark",[11,15,18,33,40,55,59,62,79,82,107,110,119,131,134,143,146,158,170,179,182],[12,13,14],"p",{},"What’s going on?  I want to run my Android emulator (XAP – Xamarin Android Player) and I get the following issue.",[12,16,17],{},"“Failed to initialize device”, “VboxMessage command failed: See log for further details”",[12,19,20],{},[21,22,24],"a",{"href":23},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_2.png",[25,26],"img",{"style":27,"src":28,"border":29,"alt":30,"title":30,"width":31,"height":32},"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;","\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb.png",0,"image",240,133,[12,34,35,36],{},"Ok, what’s going on today with my Xamarin Player.  A bit of Google-ing came up with the following information announced at the 2016 Evolve conference. \u003C\n",[37,38,39],"strong",{},"New Mac OS X Universal Installer",[12,41,42,43,46,47,50,51,54],{},"To streamline development setup on Mac OS X, we have introduced a brand ",[37,44,45],{},"new universal installer",". This will not only handle updating to the latest version of Xamarin, but also will ",[37,48,49],{},"setup the new and improved Android Emulators from Google",", based on x86 HAXM, that are now ",[37,52,53],{},"10 times faster then before!"," If you are on Windows using Visual Studio be sure to checkout the Hyper-V enabled",[21,56,58],{"href":57},"https:\u002F\u002Fwww.visualstudio.com\u002Fen-us\u002Ffeatures\u002Fmsft-android-emulator-vs.aspx","\nVisual Studio Emulators for Android",[37,60,61],{},"Xamarin Android Player is now officially deprecated",[12,63,64,65,68,69,72,73],{},"Wow - ",[37,66,67],{},"Xamarin Android Player is now officially deprecated – ","This honestly was a surprise as it had worked so well for me in the past.",[70,71],"br",{},"\nSo as instructed checking out the Hyper-V enabled ",[21,74,76],{"href":57,"target":75},"_blank",[37,77,78],{},"Visual Studio Emulators for Android",[12,80,81],{},"I downloaded, installed the emulator promising “The x86 emulator boots and runs at nearly the speed of a physical device, making debugging a breeze on graphics-intensive, processor-hungry apps.”",[12,83,84,85,92,94,95,97,98,100],{}," ",[21,86,88],{"href":87},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image7.png",[25,89],{"style":27,"src":90,"border":29,"alt":30,"title":30,"width":91,"height":31},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image7_thumb.png",171,[70,93],{},"\n \n \nAfter the installation, I was required to restart.  I opened my Android-Xamarin app thinking I would find this emulator choice in the Visual Studio Device drop down.  Nope.  I found ‘Visual Studio Emulator for Android’ as a recently installed application.  I soon made that attached to my task bar for ease of finding next time.  Starting it, I was challenged with the next hurdle. “You do not have permission to modify internal Hyper-V network adapter settings, which are required to run the emulator” – I hit ‘Retry’ and it appears to be running with the",[70,96],{},"\n ",[70,99],{},[21,101,103],{"href":102},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_4.png",[25,104],{"style":27,"src":105,"border":29,"alt":30,"title":30,"width":31,"height":106},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_1.png",142,[12,108,109],{},"I hit ‘Retry’ and it appears to be running with the following notification.  Still preparing, I am starting to wonder if anything is going on. ",[12,111,112],{},[21,113,115],{"href":114},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_8.png",[25,116],{"style":27,"src":117,"border":29,"alt":30,"title":30,"width":31,"height":118},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_3.png",37,[12,120,121,122,124],{},"Bang – I am starting to see something with “OS – Starting” and I now see the emulator.  Whew.",[70,123],{},[21,125,127],{"href":126},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_10.png",[25,128],{"style":27,"src":129,"border":29,"alt":30,"title":30,"width":130,"height":31},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_4.png",134,[12,132,133],{},"Checking things out, clicking around I try the web browser, and given another test of my competence.  So the problem is, I cannot browse to the internet via the Android Emulator default browser.",[12,135,136],{},[21,137,139],{"href":138},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_12.png",[25,140],{"style":27,"src":141,"border":29,"alt":30,"title":30,"width":31,"height":142},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_5.png",89,[12,144,145],{},"I uninstalled Xamarin Android Player – figuring I didn’t need this any more ..moment of silence please.",[12,147,148,149,151],{},"Ok, so using a few of my Sherlock skills I opened up Hyper-V Manager (found via start search).  Select the emulator then the settings option for that emulator.",[70,150],{},[21,152,154],{"href":153},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_14.png",[25,155],{"style":27,"src":156,"border":29,"alt":30,"title":30,"width":31,"height":157},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_6.png",126,[12,159,160,161,163],{},"I then selected the ‘Emulator External Network Adaptor” and chose my physical network adapter, closed\u002Fshutdown the emulator and restarted.  Great- challenge completed and all seems to be working.",[70,162],{},[21,164,166],{"href":165},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_16.png",[25,167],{"style":27,"src":168,"border":29,"alt":30,"title":30,"width":31,"height":169},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_7.png",225,[12,171,172],{},[21,173,175],{"href":174},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_18.png",[25,176],{"style":27,"src":177,"border":29,"alt":30,"title":30,"width":178,"height":31},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_8.png",172,[12,180,181],{},"Circling back to my Visual Studio – I am not able to use the Visual Studio Android emulator by selecting the appropriate device.  I have successfully removed the Xamarin Android Player, installed the new\u002Fimproved Visual Studio Emulator and made modifications via Hyper-V Manager to set the network connection of the device to my local hardware on my pc.",[12,183,184],{},[21,185,187],{"href":186},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_20.png",[25,188],{"style":27,"src":189,"border":29,"alt":30,"title":30,"width":31,"height":190},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_9.png",38,{"title":192,"searchDepth":193,"depth":193,"links":194},"",2,[],"2016-06-12T06:39:07.8500000-04:00","Failed to initialize...","md",{},true,"\u002Farticles\u002Fxamarin-player-failed-to-initialize-device-nexus4",{"title":6,"description":196},"articles\u002Fxamarin-player-failed-to-initialize-device-nexus4",[204],"xamarin","-lzYhCSoLfeLoNk6Ny6UBEB46Y35mtv4t2kMDAnjhGE",[207],{"id":208,"title":209,"body":210,"description":214,"extension":197,"img":215,"meta":216,"name":204,"navigation":199,"path":217,"seo":218,"stem":219,"__hash__":220},"tags\u002Ftags\u002Fxamarin.md","Xamarin",{"type":9,"value":211,"toc":212},[],{"title":192,"searchDepth":193,"depth":193,"links":213},[],"Xamarin is an open-source platform for building modern and performant applications for iOS, Android, and Windows with . NET. Xamarin is an abstraction layer that manages communication of shared code with underlying platform code.","https:\u002F\u002Fimages.unsplash.com\u002Fphoto-1598313183973-4effcded8d5e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80",{},"\u002Ftags\u002Fxamarin",{"description":214},"tags\u002Fxamarin","deVB66I7cJMtWvqybFh5POf9LBCBwHNe-5ZGMOzV5G4",{"id":222,"title":223,"author":7,"body":224,"createdAt":513,"description":514,"extension":197,"img":504,"meta":515,"navigation":199,"path":516,"seo":517,"stem":518,"tags":519,"updatedAt":513,"__hash__":520},"articles\u002Farticles\u002Fc-6-0-new-features.md","C# 6.0 New Features",{"type":9,"value":225,"toc":511},[226,229,235,257,272,283,340,345,354,357,372,386,411,417,426,429,444,450,460,465,495,507],[12,227,228],{},"The following features require the C# 6.0 compiler which is included in Visual Studio 2015.  Remarkably however C# 6 new features does not require and updated version of Microsoft .NET Framework (i.e. as long as you compile with VS.NET 2015 the features still work against .NET Framework 4).  This is possible as the features are implemented in the compiler itself and do not have dependencies on the .NET Framework.",[12,230,231,232,234],{},"1.) Using Static",[70,233],{},"\nUsing static directives for System.ConsoleColor looks like (as well as System.IO.Directory)",[236,237,241],"pre",{"className":238,"code":239,"language":240,"meta":192,"style":192},"language-csharp shiki shiki-themes github-light github-dark","using static System.ConsoleColor;  \nusing static System.IO.Directory;  \n","csharp",[242,243,244,252],"code",{"__ignoreMap":192},[245,246,249],"span",{"class":247,"line":248},"line",1,[245,250,251],{},"using static System.ConsoleColor;  \n",[245,253,254],{"class":247,"line":193},[245,255,256],{},"using static System.IO.Directory;\n",[236,258,260],{"className":238,"code":259,"language":240,"meta":192,"style":192},"ForegroundColor = Yellow;  \nstring[] files = GetFiles(directoryPath, searchPattern, System.IO.SearchOption.AllDirectories);  \n",[242,261,262,267],{"__ignoreMap":192},[245,263,264],{"class":247,"line":248},[245,265,266],{},"ForegroundColor = Yellow;  \n",[245,268,269],{"class":247,"line":193},[245,270,271],{},"string[] files = GetFiles(directoryPath, searchPattern, System.IO.SearchOption.AllDirectories);\n",[12,273,274,275,97,277,279,280,282],{},"These enable the invocation of numerous methods, properties and enums directly.  In each case, this eliminates the need to qualify the static member with its type.",[70,276],{},[70,278],{},"\n2.) The nameof operator",[70,281],{},"\nThis is a new contextual keyword to identify a string literal that extracts a constant for (at compile time) the unqualified name of whatever identifier is specified as an argument.  The nameof(filename) returns “filename,” the name of the Encrypt method’s parameter.  However, nameof works with any programmatic identifier.  By leveraging the nameof operator, it’s possible to eliminate the vast majority of “magic” strings that refer to code identifiers as long as they’re in scope. This not only eliminates runtime errors due to misspellings within the magic strings, which are never verified by the complier, but also enables refactoring tools like Rename to update all references to the name change identifier.",[236,284,286],{"className":238,"code":285,"language":240,"meta":192,"style":192},"private static void Encrypt(string filename)  \n  {  \n    if (!Exists(filename)) \u002F\u002F LOGIC ERROR: Using Directory rather than File  \n    {  \n      throw new ArgumentException(\"The file does not exist.\",   \n        nameof(filename));  \n    }  \n    \u002F\u002F ...  \n  }\n",[242,287,288,293,298,304,310,316,322,328,334],{"__ignoreMap":192},[245,289,290],{"class":247,"line":248},[245,291,292],{},"private static void Encrypt(string filename)  \n",[245,294,295],{"class":247,"line":193},[245,296,297],{},"  {  \n",[245,299,301],{"class":247,"line":300},3,[245,302,303],{},"    if (!Exists(filename)) \u002F\u002F LOGIC ERROR: Using Directory rather than File  \n",[245,305,307],{"class":247,"line":306},4,[245,308,309],{},"    {  \n",[245,311,313],{"class":247,"line":312},5,[245,314,315],{},"      throw new ArgumentException(\"The file does not exist.\",   \n",[245,317,319],{"class":247,"line":318},6,[245,320,321],{},"        nameof(filename));  \n",[245,323,325],{"class":247,"line":324},7,[245,326,327],{},"    }  \n",[245,329,331],{"class":247,"line":330},8,[245,332,333],{},"    \u002F\u002F ...  \n",[245,335,337],{"class":247,"line":336},9,[245,338,339],{},"  }\n",[12,341,84,342,344],{},[70,343],{},"\n3.) String Interpolation – this is an easier one to grasp.  This is the before syntax…",[236,346,348],{"className":238,"code":347,"language":240,"meta":192,"style":192},"string.Format(\"Hello!  My name is {0} {1} and I am {2} years old.\", person.FirstName, person.LastName, person.Age);\n",[242,349,350],{"__ignoreMap":192},[245,351,352],{"class":247,"line":248},[245,353,347],{},[12,355,356],{},"after…",[236,358,360],{"className":238,"code":359,"language":240,"meta":192,"style":192},"$\"Hello!  My name is {person.FirstName} {person.LastName} \n            and I am {person.Age} years old.\";\n",[242,361,362,367],{"__ignoreMap":192},[245,363,364],{"class":247,"line":248},[245,365,366],{},"$\"Hello!  My name is {person.FirstName} {person.LastName} \n",[245,368,369],{"class":247,"line":193},[245,370,371],{},"            and I am {person.Age} years old.\";\n",[12,373,374,375,97,377,379,380,382,383,385],{},"The string interpolation syntax reduces errors caused by arguments following the format string that are in improper order, or missing altogether and causing an exception.",[70,376],{},[70,378],{},"\n4.) Null-Conditional Operator",[70,381],{},"\nC# 6.0 introduces the “?.” operator known as the null-conditional operator.  The null-conditional operator translates to checking whether the operand is null prior to invoking the method or property.  What makes the null-conditional operator especially convenient is that it can be chained. If, for example, you invoke string",[245,384],{}," names = person?.Name?.Split(' '), Split will only be invoked if both person and person.Name are not null. When chained, if the first operand is null, the expression evaluation is short-circuited, and no further invocation within the expression call chain will occur.",[236,387,389],{"className":238,"code":388,"language":240,"meta":192,"style":192},"\u002F\u002Fafter  \nswitch (args?.Length) {}  \n\u002F\u002Fbefore  \n(args != null) ? (int?)args.Length : null  \n",[242,390,391,396,401,406],{"__ignoreMap":192},[245,392,393],{"class":247,"line":248},[245,394,395],{},"\u002F\u002Fafter  \n",[245,397,398],{"class":247,"line":193},[245,399,400],{},"switch (args?.Length) {}  \n",[245,402,403],{"class":247,"line":300},[245,404,405],{},"\u002F\u002Fbefore  \n",[245,407,408],{"class":247,"line":306},[245,409,410],{},"(args != null) ? (int?)args.Length : null\n",[12,412,413,414,416],{},"5.) Auto-Property Improvements",[70,415],{},"\nGetter-only auto-properties are a C# 6.0 feature for declaring read-only properties that are backed (internally) by a read-only field. As such, these properties can only be modified from within the constructor.  Rather than the six or so lines needed to declare a read-only property and initialize it prior to C# 6.0, now a single-line declaration and the assignment from within the constructor are all that’s needed.",[236,418,420],{"className":238,"code":419,"language":240,"meta":192,"style":192},"public ConsoleColor ForegroundColorVerbose { get; }\n",[242,421,422],{"__ignoreMap":192},[245,423,424],{"class":247,"line":248},[245,425,419],{},[12,427,428],{},"A second auto-property feature introduced in C# 6.0 is support for initializers.",[236,430,432],{"className":238,"code":431,"language":240,"meta":192,"style":192},"static private Lazy\u003CConsoleConfiguration>\nDefaultConfig{ get; } = new Lazy\u003CConsoleConfiguration>(() => new ConsoleConfiguration());\n",[242,433,434,439],{"__ignoreMap":192},[245,435,436],{"class":247,"line":248},[245,437,438],{},"static private Lazy\u003CConsoleConfiguration>\n",[245,440,441],{"class":247,"line":193},[245,442,443],{},"DefaultConfig{ get; } = new Lazy\u003CConsoleConfiguration>(() => new ConsoleConfiguration());\n",[12,445,446,447,449],{},"6.) Expression Bodied Methods and Auto-Properties",[70,448],{},"\nThis feature exists for both properties and methods and allows the use of the arrow operator (=>) to assign an expression to either a property or method in place of a statement body.",[236,451,453],{"className":238,"code":452,"language":240,"meta":192,"style":192},"static public ConsoleConfiguration GetDefault() => DefaultConfig.Value;  \n",[242,454,455],{"__ignoreMap":192},[245,456,457],{"class":247,"line":248},[245,458,459],{},"static public ConsoleConfiguration GetDefault() => DefaultConfig.Value;\n",[12,461,84,462,464],{},[70,463],{},"\n6.) Exception Improvements – ability to use a when clause to do additional filtering when an exception is thrown",[236,466,468],{"className":238,"code":467,"language":240,"meta":192,"style":192},"try { \n        \u002F\u002F Do stuff\n    } catch (Exception e) when ((DateTime.Now.DayOfWeek == DayOfWeek.Saturday) {\n        \u002F\u002F Swallow \n    }\n",[242,469,470,475,480,485,490],{"__ignoreMap":192},[245,471,472],{"class":247,"line":248},[245,473,474],{},"try { \n",[245,476,477],{"class":247,"line":193},[245,478,479],{},"        \u002F\u002F Do stuff\n",[245,481,482],{"class":247,"line":300},[245,483,484],{},"    } catch (Exception e) when ((DateTime.Now.DayOfWeek == DayOfWeek.Saturday) {\n",[245,486,487],{"class":247,"line":306},[245,488,489],{},"        \u002F\u002F Swallow \n",[245,491,492],{"class":247,"line":312},[245,493,494],{},"    }\n",[12,496,84,497,499],{},[70,498],{},[21,500,502],{"href":501},"\u002Farticles\u002Fimages\u002Fopen-live-writer-c-60-new-features_12307-c6_2.jpg",[25,503],{"style":27,"src":504,"border":29,"alt":505,"title":505,"width":31,"height":506},"\u002Farticles\u002Fimages\u002Fopen-live-writer-c-60-new-features_12307-c6_thumb.jpg","c6",135,[508,509,510],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":192,"searchDepth":193,"depth":193,"links":512},[],"2016-11-09T14:21:45.8700000-05:00",null,{},"\u002Farticles\u002Fc-6-0-new-features",{"title":223,"description":514},"articles\u002Fc-6-0-new-features",[240],"uMgZQ3TZwQfUVBOXbej-F7xUUHGEeZcIbN5MlW-pDw4",{"id":522,"title":523,"author":7,"body":524,"createdAt":1090,"description":528,"extension":197,"img":1084,"meta":1091,"navigation":199,"path":1092,"seo":1093,"stem":1094,"tags":1095,"updatedAt":1090,"__hash__":1096},"articles\u002Farticles\u002Fxamarin-android-fragments-and-orientations-rotation.md","Xamarin Android - Fragments and Orientations\u002FRotation",{"type":9,"value":525,"toc":1088},[526,529,532,535,544,547,577,580,698,701,757,760,1062,1086],[12,527,528],{},"When you rotate\u002Fchange the orientation of your Android application the Activity will be destroyed and recreated.  What this means is that any variables, fragments will be destroyed when the user changes the orientation of their device (say going from portrait to landscape).  Your users will hate you.  For example, If they are filling out a form and by accident the orientation changes all fields entered will be lost.",[12,530,531],{},"How can we avoid this bad experience? There are a few ways.",[12,533,534],{},"Within the OnCreate of the Activity you can force the orientation to one or the other.  A user can rotate the device however the user interface does not change orientation.",[236,536,538],{"className":238,"code":537,"language":240,"meta":192,"style":192},"RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;\n",[242,539,540],{"__ignoreMap":192},[245,541,542],{"class":247,"line":248},[245,543,537],{},[12,545,546],{},"Using an attribute on the class will lock the orientation.  The following ignores the orientation and the screen size changes.  This is easy however the difficulty is that your application will not be responsive to size\u002Forientation changes.  Your application will respond to different screen sizes or orientation.  This too can be less than optimum.",[236,548,550],{"className":238,"code":549,"language":240,"meta":192,"style":192},"[Activity(Label = \"AppDave\", MainLauncher = true, Icon = \"@drawable\u002Ficon\", \nTheme = \"@style\u002FMyTheme\", ConfigurationChanges = Android.Content.PM.ConfigChanges.ScreenSize | Android.Content.PM.ConfigChanges.Orientation)]  \npublic class MainActivity : AppCompatActivity  \n{  \n}\n",[242,551,552,557,562,567,572],{"__ignoreMap":192},[245,553,554],{"class":247,"line":248},[245,555,556],{},"[Activity(Label = \"AppDave\", MainLauncher = true, Icon = \"@drawable\u002Ficon\", \n",[245,558,559],{"class":247,"line":193},[245,560,561],{},"Theme = \"@style\u002FMyTheme\", ConfigurationChanges = Android.Content.PM.ConfigChanges.ScreenSize | Android.Content.PM.ConfigChanges.Orientation)]  \n",[245,563,564],{"class":247,"line":300},[245,565,566],{},"public class MainActivity : AppCompatActivity  \n",[245,568,569],{"class":247,"line":306},[245,570,571],{},"{  \n",[245,573,574],{"class":247,"line":312},[245,575,576],{},"}\n",[12,578,579],{},"In the following example I have an application with three fragments.   The first fragment with tag “Fragment1” gets set when the application loads.  I will use this tag as the test to see if the activity has started at least one time.  Within the OnCreate method I check to see if the Activity has run by checking SupportFragmentManager.FindFragmentByTag(“Fragment1”).",[236,581,583],{"className":238,"code":582,"language":240,"meta":192,"style":192},"if (SupportFragmentManager.FindFragmentByTag(\"Fragment1\") != null)  \n{  \n    if (SupportFragmentManager.FindFragmentByTag(\"Fragment1\") != null)  \n        _fragment1 = SupportFragmentManager.FindFragmentByTag(\"Fragment1\") as Fragment1;  \n  \n    if (SupportFragmentManager.FindFragmentByTag(\"Fragment2\") != null)  \n        _fragment2 = SupportFragmentManager.FindFragmentByTag(\"Fragment2\") as Fragment2;  \n  \n    if (SupportFragmentManager.FindFragmentByTag(\"Fragment3\") != null)  \n        _fragment3 = SupportFragmentManager.FindFragmentByTag(\"Fragment3\") as Fragment3;  \n}  \nelse  \n{  \n    \u002F\u002Fno fragments in the container  \n    _fragment1 = new Fragment1();  \n      \n    var trans = SupportFragmentManager.BeginTransaction();  \n    trans.Add(Resource.Id.fragmentContainer, _fragment1, \"Fragment1\");                  \n    trans.Commit();  \n    _currentFragment = _fragment1;  \n}\n",[242,584,585,590,594,599,604,609,614,619,623,628,634,640,646,651,657,663,669,675,681,687,693],{"__ignoreMap":192},[245,586,587],{"class":247,"line":248},[245,588,589],{},"if (SupportFragmentManager.FindFragmentByTag(\"Fragment1\") != null)  \n",[245,591,592],{"class":247,"line":193},[245,593,571],{},[245,595,596],{"class":247,"line":300},[245,597,598],{},"    if (SupportFragmentManager.FindFragmentByTag(\"Fragment1\") != null)  \n",[245,600,601],{"class":247,"line":306},[245,602,603],{},"        _fragment1 = SupportFragmentManager.FindFragmentByTag(\"Fragment1\") as Fragment1;  \n",[245,605,606],{"class":247,"line":312},[245,607,608],{},"  \n",[245,610,611],{"class":247,"line":318},[245,612,613],{},"    if (SupportFragmentManager.FindFragmentByTag(\"Fragment2\") != null)  \n",[245,615,616],{"class":247,"line":324},[245,617,618],{},"        _fragment2 = SupportFragmentManager.FindFragmentByTag(\"Fragment2\") as Fragment2;  \n",[245,620,621],{"class":247,"line":330},[245,622,608],{},[245,624,625],{"class":247,"line":336},[245,626,627],{},"    if (SupportFragmentManager.FindFragmentByTag(\"Fragment3\") != null)  \n",[245,629,631],{"class":247,"line":630},10,[245,632,633],{},"        _fragment3 = SupportFragmentManager.FindFragmentByTag(\"Fragment3\") as Fragment3;  \n",[245,635,637],{"class":247,"line":636},11,[245,638,639],{},"}  \n",[245,641,643],{"class":247,"line":642},12,[245,644,645],{},"else  \n",[245,647,649],{"class":247,"line":648},13,[245,650,571],{},[245,652,654],{"class":247,"line":653},14,[245,655,656],{},"    \u002F\u002Fno fragments in the container  \n",[245,658,660],{"class":247,"line":659},15,[245,661,662],{},"    _fragment1 = new Fragment1();  \n",[245,664,666],{"class":247,"line":665},16,[245,667,668],{},"      \n",[245,670,672],{"class":247,"line":671},17,[245,673,674],{},"    var trans = SupportFragmentManager.BeginTransaction();  \n",[245,676,678],{"class":247,"line":677},18,[245,679,680],{},"    trans.Add(Resource.Id.fragmentContainer, _fragment1, \"Fragment1\");                  \n",[245,682,684],{"class":247,"line":683},19,[245,685,686],{},"    trans.Commit();  \n",[245,688,690],{"class":247,"line":689},20,[245,691,692],{},"    _currentFragment = _fragment1;  \n",[245,694,696],{"class":247,"line":695},21,[245,697,576],{},[12,699,700],{},"I am going through this backwards but this is the method that I am using to replace the current fragment with a new one.  Notice however that I am adding it with a specified tag so that we can recover it later",[236,702,704],{"className":238,"code":703,"language":240,"meta":192,"style":192},"private void ReplaceFragment(SupportFragment fragment, string tag)  \n{  \n    if (fragment.IsVisible)  \n        return;  \n  \n    var trans = SupportFragmentManager.BeginTransaction();             \n    trans.Replace(Resource.Id.fragmentContainer, fragment, tag);  \n    trans.AddToBackStack(null);  \n    trans.Commit();  \n    _currentFragment = fragment;  \n}\n",[242,705,706,711,715,720,725,729,734,739,744,748,753],{"__ignoreMap":192},[245,707,708],{"class":247,"line":248},[245,709,710],{},"private void ReplaceFragment(SupportFragment fragment, string tag)  \n",[245,712,713],{"class":247,"line":193},[245,714,571],{},[245,716,717],{"class":247,"line":300},[245,718,719],{},"    if (fragment.IsVisible)  \n",[245,721,722],{"class":247,"line":306},[245,723,724],{},"        return;  \n",[245,726,727],{"class":247,"line":312},[245,728,608],{},[245,730,731],{"class":247,"line":318},[245,732,733],{},"    var trans = SupportFragmentManager.BeginTransaction();             \n",[245,735,736],{"class":247,"line":324},[245,737,738],{},"    trans.Replace(Resource.Id.fragmentContainer, fragment, tag);  \n",[245,740,741],{"class":247,"line":330},[245,742,743],{},"    trans.AddToBackStack(null);  \n",[245,745,746],{"class":247,"line":336},[245,747,686],{},[245,749,750],{"class":247,"line":630},[245,751,752],{},"    _currentFragment = fragment;  \n",[245,754,755],{"class":247,"line":636},[245,756,576],{},[12,758,759],{},"And finally I will show the method that responds to a menu selection which calls the ReplaceFragment method",[236,761,763],{"className":238,"code":762,"language":240,"meta":192,"style":192},"public override bool OnOptionsItemSelected(IMenuItem item)  \n{      \n    switch (item.ItemId)  \n    {                  \n        case Android.Resource.Id.Home:  \n            \u002F\u002FThe hamburger icon was clicked which means the drawer toggle will handle the event  \n            \u002F\u002Fall we need to do is ensure the right drawer is closed so the don't overlap  \n            _drawerLayout.CloseDrawer(_rightDrawer);  \n            _drawerToggle.OnOptionsItemSelected(item);  \n            return true;  \n  \n        \u002F\u002Fcase Resource.Id.action_refresh:  \n        \u002F\u002F    \u002F\u002FRefresh  \n        \u002F\u002F    return true;  \n  \n        case Resource.Id.action_fragment1:  \n            \u002F\u002FShowFragment(_fragment1);  \n  \n            if (_fragment1 == null)                      \n                _fragment1 = new Fragment1();            \n                  \n                ReplaceFragment(_fragment1, \"Fragment1\");  \n            return true;  \n        case Resource.Id.action_fragment2:  \n            \u002F\u002FShowFragment(_fragment2);  \n            if (_fragment2 == null)   \n                _fragment2 = new Fragment2();  \n                  \n            ReplaceFragment(_fragment2, \"Fragment2\");  \n            return true;  \n        case Resource.Id.action_fragment3:  \n            \u002F\u002FShowFragment(_fragment3);  \n              \n            if (_fragment3 == null)                      \n                _fragment3 = new Fragment3();  \n  \n            ReplaceFragment(_fragment3, \"Fragment3\");  \n            return true;  \n        case Resource.Id.action_help:  \n            if (_drawerLayout.IsDrawerOpen(_rightDrawer))  \n            {  \n                \u002F\u002FRight Drawer is already open, close it  \n                _drawerLayout.CloseDrawer(_rightDrawer);  \n            }  \n            else  \n            {  \n                \u002F\u002FRight Drawer is closed, open it and just in case close left drawer  \n                _drawerLayout.OpenDrawer(_rightDrawer);  \n                _drawerLayout.CloseDrawer(_leftDrawer);  \n            }  \n            return true;  \n        default:  \n            return base.OnOptionsItemSelected(item);  \n    }  \n}\n",[242,764,765,770,775,780,785,790,795,800,805,810,815,819,824,832,837,841,846,851,855,860,865,870,876,881,887,893,899,905,910,916,921,927,933,939,945,951,956,961,965,971,977,983,989,995,1001,1007,1012,1018,1024,1030,1035,1040,1046,1052,1057],{"__ignoreMap":192},[245,766,767],{"class":247,"line":248},[245,768,769],{},"public override bool OnOptionsItemSelected(IMenuItem item)  \n",[245,771,772],{"class":247,"line":193},[245,773,774],{},"{      \n",[245,776,777],{"class":247,"line":300},[245,778,779],{},"    switch (item.ItemId)  \n",[245,781,782],{"class":247,"line":306},[245,783,784],{},"    {                  \n",[245,786,787],{"class":247,"line":312},[245,788,789],{},"        case Android.Resource.Id.Home:  \n",[245,791,792],{"class":247,"line":318},[245,793,794],{},"            \u002F\u002FThe hamburger icon was clicked which means the drawer toggle will handle the event  \n",[245,796,797],{"class":247,"line":324},[245,798,799],{},"            \u002F\u002Fall we need to do is ensure the right drawer is closed so the don't overlap  \n",[245,801,802],{"class":247,"line":330},[245,803,804],{},"            _drawerLayout.CloseDrawer(_rightDrawer);  \n",[245,806,807],{"class":247,"line":336},[245,808,809],{},"            _drawerToggle.OnOptionsItemSelected(item);  \n",[245,811,812],{"class":247,"line":630},[245,813,814],{},"            return true;  \n",[245,816,817],{"class":247,"line":636},[245,818,608],{},[245,820,821],{"class":247,"line":642},[245,822,823],{},"        \u002F\u002Fcase Resource.Id.action_refresh:  \n",[245,825,826,829],{"class":247,"line":648},[245,827,828],{},"        \u002F\u002F",[245,830,831],{},"    \u002F\u002FRefresh  \n",[245,833,834],{"class":247,"line":653},[245,835,836],{},"        \u002F\u002F    return true;  \n",[245,838,839],{"class":247,"line":659},[245,840,608],{},[245,842,843],{"class":247,"line":665},[245,844,845],{},"        case Resource.Id.action_fragment1:  \n",[245,847,848],{"class":247,"line":671},[245,849,850],{},"            \u002F\u002FShowFragment(_fragment1);  \n",[245,852,853],{"class":247,"line":677},[245,854,608],{},[245,856,857],{"class":247,"line":683},[245,858,859],{},"            if (_fragment1 == null)                      \n",[245,861,862],{"class":247,"line":689},[245,863,864],{},"                _fragment1 = new Fragment1();            \n",[245,866,867],{"class":247,"line":695},[245,868,869],{},"                  \n",[245,871,873],{"class":247,"line":872},22,[245,874,875],{},"                ReplaceFragment(_fragment1, \"Fragment1\");  \n",[245,877,879],{"class":247,"line":878},23,[245,880,814],{},[245,882,884],{"class":247,"line":883},24,[245,885,886],{},"        case Resource.Id.action_fragment2:  \n",[245,888,890],{"class":247,"line":889},25,[245,891,892],{},"            \u002F\u002FShowFragment(_fragment2);  \n",[245,894,896],{"class":247,"line":895},26,[245,897,898],{},"            if (_fragment2 == null)   \n",[245,900,902],{"class":247,"line":901},27,[245,903,904],{},"                _fragment2 = new Fragment2();  \n",[245,906,908],{"class":247,"line":907},28,[245,909,869],{},[245,911,913],{"class":247,"line":912},29,[245,914,915],{},"            ReplaceFragment(_fragment2, \"Fragment2\");  \n",[245,917,919],{"class":247,"line":918},30,[245,920,814],{},[245,922,924],{"class":247,"line":923},31,[245,925,926],{},"        case Resource.Id.action_fragment3:  \n",[245,928,930],{"class":247,"line":929},32,[245,931,932],{},"            \u002F\u002FShowFragment(_fragment3);  \n",[245,934,936],{"class":247,"line":935},33,[245,937,938],{},"              \n",[245,940,942],{"class":247,"line":941},34,[245,943,944],{},"            if (_fragment3 == null)                      \n",[245,946,948],{"class":247,"line":947},35,[245,949,950],{},"                _fragment3 = new Fragment3();  \n",[245,952,954],{"class":247,"line":953},36,[245,955,608],{},[245,957,958],{"class":247,"line":118},[245,959,960],{},"            ReplaceFragment(_fragment3, \"Fragment3\");  \n",[245,962,963],{"class":247,"line":190},[245,964,814],{},[245,966,968],{"class":247,"line":967},39,[245,969,970],{},"        case Resource.Id.action_help:  \n",[245,972,974],{"class":247,"line":973},40,[245,975,976],{},"            if (_drawerLayout.IsDrawerOpen(_rightDrawer))  \n",[245,978,980],{"class":247,"line":979},41,[245,981,982],{},"            {  \n",[245,984,986],{"class":247,"line":985},42,[245,987,988],{},"                \u002F\u002FRight Drawer is already open, close it  \n",[245,990,992],{"class":247,"line":991},43,[245,993,994],{},"                _drawerLayout.CloseDrawer(_rightDrawer);  \n",[245,996,998],{"class":247,"line":997},44,[245,999,1000],{},"            }  \n",[245,1002,1004],{"class":247,"line":1003},45,[245,1005,1006],{},"            else  \n",[245,1008,1010],{"class":247,"line":1009},46,[245,1011,982],{},[245,1013,1015],{"class":247,"line":1014},47,[245,1016,1017],{},"                \u002F\u002FRight Drawer is closed, open it and just in case close left drawer  \n",[245,1019,1021],{"class":247,"line":1020},48,[245,1022,1023],{},"                _drawerLayout.OpenDrawer(_rightDrawer);  \n",[245,1025,1027],{"class":247,"line":1026},49,[245,1028,1029],{},"                _drawerLayout.CloseDrawer(_leftDrawer);  \n",[245,1031,1033],{"class":247,"line":1032},50,[245,1034,1000],{},[245,1036,1038],{"class":247,"line":1037},51,[245,1039,814],{},[245,1041,1043],{"class":247,"line":1042},52,[245,1044,1045],{},"        default:  \n",[245,1047,1049],{"class":247,"line":1048},53,[245,1050,1051],{},"            return base.OnOptionsItemSelected(item);  \n",[245,1053,1055],{"class":247,"line":1054},54,[245,1056,327],{},[245,1058,1060],{"class":247,"line":1059},55,[245,1061,576],{},[12,1063,1064,1065,97,1067,1069,1070,1073,1077,1079],{},"So finally, why are we using the transaction manager to replace fragments instead of showing and hiding them?  If we load up all fragments upon start up and show\u002Fhide they all are residing in memory which can be problematic if the fragments are large or you have many of them in your application.  Using the replace approach optimizes memory to only work with active fragments.  While a fragment is not in the current layout it is ‘paused’ and the memory footprint is much less.",[70,1066],{},[70,1068],{},"\nReference: ",[21,1071],{"href":1072,"title":1072},"http:\u002F\u002Fdeveloper.android.com\u002Fguide\u002Fcomponents\u002Ffragments.html",[21,1074,1072],{"href":1072,"rel":1075},[1076],"nofollow",[70,1078],{},[21,1080,1082],{"href":1081},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-android-fragments-and-orientat_957a-image_2.png",[25,1083],{"style":27,"src":1084,"border":29,"alt":30,"title":30,"width":1085,"height":31},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-android-fragments-and-orientat_957a-image_thumb.png",228,[508,1087,510],{},{"title":192,"searchDepth":193,"depth":193,"links":1089},[],"2016-02-14T04:36:35.5200000-05:00",{},"\u002Farticles\u002Fxamarin-android-fragments-and-orientations-rotation",{"title":523,"description":528},"articles\u002Fxamarin-android-fragments-and-orientations-rotation",[204],"ptH_PqAAUCLJDvJogWefd7tmS1dafuuixCi8v4M0HA8",1781574770777]