[{"data":1,"prerenderedAt":959},["ShallowReactive",2],{"article-xamarin-android-fragments-and-orientations-rotation":3},{"article":4,"tags":615,"previous":630,"next":814},{"id":5,"title":6,"author":7,"body":8,"createdAt":605,"description":14,"extension":606,"img":594,"meta":607,"navigation":608,"path":609,"seo":610,"stem":611,"tags":612,"updatedAt":605,"__hash__":614},"articles\u002Farticles\u002Fxamarin-android-fragments-and-orientations-rotation.md","Xamarin Android - Fragments and Orientations\u002FRotation","[object Object]",{"type":9,"value":10,"toc":603},"minimark",[11,15,18,21,38,41,75,78,200,203,259,262,567,599],[12,13,14],"p",{},"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,16,17],{},"How can we avoid this bad experience? There are a few ways.",[12,19,20],{},"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.",[22,23,28],"pre",{"className":24,"code":25,"language":26,"meta":27,"style":27},"language-csharp shiki shiki-themes github-light github-dark","RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;\n","csharp","",[29,30,31],"code",{"__ignoreMap":27},[32,33,36],"span",{"class":34,"line":35},"line",1,[32,37,25],{},[12,39,40],{},"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.",[22,42,44],{"className":24,"code":43,"language":26,"meta":27,"style":27},"[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",[29,45,46,51,57,63,69],{"__ignoreMap":27},[32,47,48],{"class":34,"line":35},[32,49,50],{},"[Activity(Label = \"AppDave\", MainLauncher = true, Icon = \"@drawable\u002Ficon\", \n",[32,52,54],{"class":34,"line":53},2,[32,55,56],{},"Theme = \"@style\u002FMyTheme\", ConfigurationChanges = Android.Content.PM.ConfigChanges.ScreenSize | Android.Content.PM.ConfigChanges.Orientation)]  \n",[32,58,60],{"class":34,"line":59},3,[32,61,62],{},"public class MainActivity : AppCompatActivity  \n",[32,64,66],{"class":34,"line":65},4,[32,67,68],{},"{  \n",[32,70,72],{"class":34,"line":71},5,[32,73,74],{},"}\n",[12,76,77],{},"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”).",[22,79,81],{"className":24,"code":80,"language":26,"meta":27,"style":27},"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",[29,82,83,88,92,97,102,107,113,119,124,130,136,142,148,153,159,165,171,177,183,189,195],{"__ignoreMap":27},[32,84,85],{"class":34,"line":35},[32,86,87],{},"if (SupportFragmentManager.FindFragmentByTag(\"Fragment1\") != null)  \n",[32,89,90],{"class":34,"line":53},[32,91,68],{},[32,93,94],{"class":34,"line":59},[32,95,96],{},"    if (SupportFragmentManager.FindFragmentByTag(\"Fragment1\") != null)  \n",[32,98,99],{"class":34,"line":65},[32,100,101],{},"        _fragment1 = SupportFragmentManager.FindFragmentByTag(\"Fragment1\") as Fragment1;  \n",[32,103,104],{"class":34,"line":71},[32,105,106],{},"  \n",[32,108,110],{"class":34,"line":109},6,[32,111,112],{},"    if (SupportFragmentManager.FindFragmentByTag(\"Fragment2\") != null)  \n",[32,114,116],{"class":34,"line":115},7,[32,117,118],{},"        _fragment2 = SupportFragmentManager.FindFragmentByTag(\"Fragment2\") as Fragment2;  \n",[32,120,122],{"class":34,"line":121},8,[32,123,106],{},[32,125,127],{"class":34,"line":126},9,[32,128,129],{},"    if (SupportFragmentManager.FindFragmentByTag(\"Fragment3\") != null)  \n",[32,131,133],{"class":34,"line":132},10,[32,134,135],{},"        _fragment3 = SupportFragmentManager.FindFragmentByTag(\"Fragment3\") as Fragment3;  \n",[32,137,139],{"class":34,"line":138},11,[32,140,141],{},"}  \n",[32,143,145],{"class":34,"line":144},12,[32,146,147],{},"else  \n",[32,149,151],{"class":34,"line":150},13,[32,152,68],{},[32,154,156],{"class":34,"line":155},14,[32,157,158],{},"    \u002F\u002Fno fragments in the container  \n",[32,160,162],{"class":34,"line":161},15,[32,163,164],{},"    _fragment1 = new Fragment1();  \n",[32,166,168],{"class":34,"line":167},16,[32,169,170],{},"      \n",[32,172,174],{"class":34,"line":173},17,[32,175,176],{},"    var trans = SupportFragmentManager.BeginTransaction();  \n",[32,178,180],{"class":34,"line":179},18,[32,181,182],{},"    trans.Add(Resource.Id.fragmentContainer, _fragment1, \"Fragment1\");                  \n",[32,184,186],{"class":34,"line":185},19,[32,187,188],{},"    trans.Commit();  \n",[32,190,192],{"class":34,"line":191},20,[32,193,194],{},"    _currentFragment = _fragment1;  \n",[32,196,198],{"class":34,"line":197},21,[32,199,74],{},[12,201,202],{},"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",[22,204,206],{"className":24,"code":205,"language":26,"meta":27,"style":27},"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",[29,207,208,213,217,222,227,231,236,241,246,250,255],{"__ignoreMap":27},[32,209,210],{"class":34,"line":35},[32,211,212],{},"private void ReplaceFragment(SupportFragment fragment, string tag)  \n",[32,214,215],{"class":34,"line":53},[32,216,68],{},[32,218,219],{"class":34,"line":59},[32,220,221],{},"    if (fragment.IsVisible)  \n",[32,223,224],{"class":34,"line":65},[32,225,226],{},"        return;  \n",[32,228,229],{"class":34,"line":71},[32,230,106],{},[32,232,233],{"class":34,"line":109},[32,234,235],{},"    var trans = SupportFragmentManager.BeginTransaction();             \n",[32,237,238],{"class":34,"line":115},[32,239,240],{},"    trans.Replace(Resource.Id.fragmentContainer, fragment, tag);  \n",[32,242,243],{"class":34,"line":121},[32,244,245],{},"    trans.AddToBackStack(null);  \n",[32,247,248],{"class":34,"line":126},[32,249,188],{},[32,251,252],{"class":34,"line":132},[32,253,254],{},"    _currentFragment = fragment;  \n",[32,256,257],{"class":34,"line":138},[32,258,74],{},[12,260,261],{},"And finally I will show the method that responds to a menu selection which calls the ReplaceFragment method",[22,263,265],{"className":24,"code":264,"language":26,"meta":27,"style":27},"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",[29,266,267,272,277,282,287,292,297,302,307,312,317,321,326,334,339,343,348,353,357,362,367,372,378,383,389,395,401,407,412,418,423,429,435,441,447,453,458,464,469,475,481,487,493,499,505,511,516,522,528,534,539,544,550,556,562],{"__ignoreMap":27},[32,268,269],{"class":34,"line":35},[32,270,271],{},"public override bool OnOptionsItemSelected(IMenuItem item)  \n",[32,273,274],{"class":34,"line":53},[32,275,276],{},"{      \n",[32,278,279],{"class":34,"line":59},[32,280,281],{},"    switch (item.ItemId)  \n",[32,283,284],{"class":34,"line":65},[32,285,286],{},"    {                  \n",[32,288,289],{"class":34,"line":71},[32,290,291],{},"        case Android.Resource.Id.Home:  \n",[32,293,294],{"class":34,"line":109},[32,295,296],{},"            \u002F\u002FThe hamburger icon was clicked which means the drawer toggle will handle the event  \n",[32,298,299],{"class":34,"line":115},[32,300,301],{},"            \u002F\u002Fall we need to do is ensure the right drawer is closed so the don't overlap  \n",[32,303,304],{"class":34,"line":121},[32,305,306],{},"            _drawerLayout.CloseDrawer(_rightDrawer);  \n",[32,308,309],{"class":34,"line":126},[32,310,311],{},"            _drawerToggle.OnOptionsItemSelected(item);  \n",[32,313,314],{"class":34,"line":132},[32,315,316],{},"            return true;  \n",[32,318,319],{"class":34,"line":138},[32,320,106],{},[32,322,323],{"class":34,"line":144},[32,324,325],{},"        \u002F\u002Fcase Resource.Id.action_refresh:  \n",[32,327,328,331],{"class":34,"line":150},[32,329,330],{},"        \u002F\u002F",[32,332,333],{},"    \u002F\u002FRefresh  \n",[32,335,336],{"class":34,"line":155},[32,337,338],{},"        \u002F\u002F    return true;  \n",[32,340,341],{"class":34,"line":161},[32,342,106],{},[32,344,345],{"class":34,"line":167},[32,346,347],{},"        case Resource.Id.action_fragment1:  \n",[32,349,350],{"class":34,"line":173},[32,351,352],{},"            \u002F\u002FShowFragment(_fragment1);  \n",[32,354,355],{"class":34,"line":179},[32,356,106],{},[32,358,359],{"class":34,"line":185},[32,360,361],{},"            if (_fragment1 == null)                      \n",[32,363,364],{"class":34,"line":191},[32,365,366],{},"                _fragment1 = new Fragment1();            \n",[32,368,369],{"class":34,"line":197},[32,370,371],{},"                  \n",[32,373,375],{"class":34,"line":374},22,[32,376,377],{},"                ReplaceFragment(_fragment1, \"Fragment1\");  \n",[32,379,381],{"class":34,"line":380},23,[32,382,316],{},[32,384,386],{"class":34,"line":385},24,[32,387,388],{},"        case Resource.Id.action_fragment2:  \n",[32,390,392],{"class":34,"line":391},25,[32,393,394],{},"            \u002F\u002FShowFragment(_fragment2);  \n",[32,396,398],{"class":34,"line":397},26,[32,399,400],{},"            if (_fragment2 == null)   \n",[32,402,404],{"class":34,"line":403},27,[32,405,406],{},"                _fragment2 = new Fragment2();  \n",[32,408,410],{"class":34,"line":409},28,[32,411,371],{},[32,413,415],{"class":34,"line":414},29,[32,416,417],{},"            ReplaceFragment(_fragment2, \"Fragment2\");  \n",[32,419,421],{"class":34,"line":420},30,[32,422,316],{},[32,424,426],{"class":34,"line":425},31,[32,427,428],{},"        case Resource.Id.action_fragment3:  \n",[32,430,432],{"class":34,"line":431},32,[32,433,434],{},"            \u002F\u002FShowFragment(_fragment3);  \n",[32,436,438],{"class":34,"line":437},33,[32,439,440],{},"              \n",[32,442,444],{"class":34,"line":443},34,[32,445,446],{},"            if (_fragment3 == null)                      \n",[32,448,450],{"class":34,"line":449},35,[32,451,452],{},"                _fragment3 = new Fragment3();  \n",[32,454,456],{"class":34,"line":455},36,[32,457,106],{},[32,459,461],{"class":34,"line":460},37,[32,462,463],{},"            ReplaceFragment(_fragment3, \"Fragment3\");  \n",[32,465,467],{"class":34,"line":466},38,[32,468,316],{},[32,470,472],{"class":34,"line":471},39,[32,473,474],{},"        case Resource.Id.action_help:  \n",[32,476,478],{"class":34,"line":477},40,[32,479,480],{},"            if (_drawerLayout.IsDrawerOpen(_rightDrawer))  \n",[32,482,484],{"class":34,"line":483},41,[32,485,486],{},"            {  \n",[32,488,490],{"class":34,"line":489},42,[32,491,492],{},"                \u002F\u002FRight Drawer is already open, close it  \n",[32,494,496],{"class":34,"line":495},43,[32,497,498],{},"                _drawerLayout.CloseDrawer(_rightDrawer);  \n",[32,500,502],{"class":34,"line":501},44,[32,503,504],{},"            }  \n",[32,506,508],{"class":34,"line":507},45,[32,509,510],{},"            else  \n",[32,512,514],{"class":34,"line":513},46,[32,515,486],{},[32,517,519],{"class":34,"line":518},47,[32,520,521],{},"                \u002F\u002FRight Drawer is closed, open it and just in case close left drawer  \n",[32,523,525],{"class":34,"line":524},48,[32,526,527],{},"                _drawerLayout.OpenDrawer(_rightDrawer);  \n",[32,529,531],{"class":34,"line":530},49,[32,532,533],{},"                _drawerLayout.CloseDrawer(_leftDrawer);  \n",[32,535,537],{"class":34,"line":536},50,[32,538,504],{},[32,540,542],{"class":34,"line":541},51,[32,543,316],{},[32,545,547],{"class":34,"line":546},52,[32,548,549],{},"        default:  \n",[32,551,553],{"class":34,"line":552},53,[32,554,555],{},"            return base.OnOptionsItemSelected(item);  \n",[32,557,559],{"class":34,"line":558},54,[32,560,561],{},"    }  \n",[32,563,565],{"class":34,"line":564},55,[32,566,74],{},[12,568,569,570,573,574,576,577,581,585,587],{},"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.",[571,572],"br",{},"\n ",[571,575],{},"\nReference: ",[578,579],"a",{"href":580,"title":580},"http:\u002F\u002Fdeveloper.android.com\u002Fguide\u002Fcomponents\u002Ffragments.html",[578,582,580],{"href":580,"rel":583},[584],"nofollow",[571,586],{},[578,588,590],{"href":589},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-android-fragments-and-orientat_957a-image_2.png",[591,592],"img",{"style":593,"src":594,"border":595,"alt":596,"title":596,"width":597,"height":598},"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;","\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-android-fragments-and-orientat_957a-image_thumb.png",0,"image",228,240,[600,601,602],"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":27,"searchDepth":53,"depth":53,"links":604},[],"2016-02-14T04:36:35.5200000-05:00","md",{},true,"\u002Farticles\u002Fxamarin-android-fragments-and-orientations-rotation",{"title":6,"description":14},"articles\u002Fxamarin-android-fragments-and-orientations-rotation",[613],"xamarin","ptH_PqAAUCLJDvJogWefd7tmS1dafuuixCi8v4M0HA8",[616],{"id":617,"title":618,"body":619,"description":623,"extension":606,"img":624,"meta":625,"name":613,"navigation":608,"path":626,"seo":627,"stem":628,"__hash__":629},"tags\u002Ftags\u002Fxamarin.md","Xamarin",{"type":9,"value":620,"toc":621},[],{"title":27,"searchDepth":53,"depth":53,"links":622},[],"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":623},"tags\u002Fxamarin","deVB66I7cJMtWvqybFh5POf9LBCBwHNe-5ZGMOzV5G4",{"id":631,"title":632,"author":7,"body":633,"createdAt":806,"description":807,"extension":606,"img":648,"meta":808,"navigation":608,"path":809,"seo":810,"stem":811,"tags":812,"updatedAt":806,"__hash__":813},"articles\u002Farticles\u002Fxamarin-player-failed-to-initialize-device-nexus4.md","Xamarin Player Failed to initialize device Nexus4",{"type":9,"value":634,"toc":804},[635,638,641,650,657,672,676,679,695,698,722,725,733,745,748,757,760,772,784,793,796],[12,636,637],{},"What’s going on?  I want to run my Android emulator (XAP – Xamarin Android Player) and I get the following issue.",[12,639,640],{},"“Failed to initialize device”, “VboxMessage command failed: See log for further details”",[12,642,643],{},[578,644,646],{"href":645},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_2.png",[591,647],{"style":593,"src":648,"border":595,"alt":596,"title":596,"width":598,"height":649},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb.png",133,[12,651,652,653],{},"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",[654,655,656],"strong",{},"New Mac OS X Universal Installer",[12,658,659,660,663,664,667,668,671],{},"To streamline development setup on Mac OS X, we have introduced a brand ",[654,661,662],{},"new universal installer",". This will not only handle updating to the latest version of Xamarin, but also will ",[654,665,666],{},"setup the new and improved Android Emulators from Google",", based on x86 HAXM, that are now ",[654,669,670],{},"10 times faster then before!"," If you are on Windows using Visual Studio be sure to checkout the Hyper-V enabled",[578,673,675],{"href":674},"https:\u002F\u002Fwww.visualstudio.com\u002Fen-us\u002Ffeatures\u002Fmsft-android-emulator-vs.aspx","\nVisual Studio Emulators for Android",[654,677,678],{},"Xamarin Android Player is now officially deprecated",[12,680,681,682,685,686,688,689],{},"Wow - ",[654,683,684],{},"Xamarin Android Player is now officially deprecated – ","This honestly was a surprise as it had worked so well for me in the past.",[571,687],{},"\nSo as instructed checking out the Hyper-V enabled ",[578,690,692],{"href":674,"target":691},"_blank",[654,693,694],{},"Visual Studio Emulators for Android",[12,696,697],{},"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,699,700,701,708,710,711,573,713,715],{}," ",[578,702,704],{"href":703},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image7.png",[591,705],{"style":593,"src":706,"border":595,"alt":596,"title":596,"width":707,"height":598},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image7_thumb.png",171,[571,709],{},"\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",[571,712],{},[571,714],{},[578,716,718],{"href":717},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_4.png",[591,719],{"style":593,"src":720,"border":595,"alt":596,"title":596,"width":598,"height":721},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_1.png",142,[12,723,724],{},"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,726,727],{},[578,728,730],{"href":729},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_8.png",[591,731],{"style":593,"src":732,"border":595,"alt":596,"title":596,"width":598,"height":460},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_3.png",[12,734,735,736,738],{},"Bang – I am starting to see something with “OS – Starting” and I now see the emulator.  Whew.",[571,737],{},[578,739,741],{"href":740},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_10.png",[591,742],{"style":593,"src":743,"border":595,"alt":596,"title":596,"width":744,"height":598},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_4.png",134,[12,746,747],{},"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,749,750],{},[578,751,753],{"href":752},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_12.png",[591,754],{"style":593,"src":755,"border":595,"alt":596,"title":596,"width":598,"height":756},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_5.png",89,[12,758,759],{},"I uninstalled Xamarin Android Player – figuring I didn’t need this any more ..moment of silence please.",[12,761,762,763,765],{},"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.",[571,764],{},[578,766,768],{"href":767},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_14.png",[591,769],{"style":593,"src":770,"border":595,"alt":596,"title":596,"width":598,"height":771},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_6.png",126,[12,773,774,775,777],{},"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.",[571,776],{},[578,778,780],{"href":779},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_16.png",[591,781],{"style":593,"src":782,"border":595,"alt":596,"title":596,"width":598,"height":783},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_7.png",225,[12,785,786],{},[578,787,789],{"href":788},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_18.png",[591,790],{"style":593,"src":791,"border":595,"alt":596,"title":596,"width":792,"height":598},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_8.png",172,[12,794,795],{},"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,797,798],{},[578,799,801],{"href":800},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_20.png",[591,802],{"style":593,"src":803,"border":595,"alt":596,"title":596,"width":598,"height":466},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-player-failed-to-initialize-devi_ae14-image_thumb_9.png",{"title":27,"searchDepth":53,"depth":53,"links":805},[],"2016-06-12T06:39:07.8500000-04:00","Failed to initialize...",{},"\u002Farticles\u002Fxamarin-player-failed-to-initialize-device-nexus4",{"title":632,"description":807},"articles\u002Fxamarin-player-failed-to-initialize-device-nexus4",[613],"-lzYhCSoLfeLoNk6Ny6UBEB46Y35mtv4t2kMDAnjhGE",{"id":815,"title":816,"author":7,"body":817,"createdAt":951,"description":952,"extension":606,"img":835,"meta":953,"navigation":608,"path":954,"seo":955,"stem":956,"tags":957,"updatedAt":951,"__hash__":958},"articles\u002Farticles\u002Fgenerate-insert-update-delete-trigger-for-table-audit.md","Generate Insert, Update, Delete Trigger for Table Audit",{"type":9,"value":818,"toc":949},[819,824,838,841,850,947],[12,820,700,821,823],{},[571,822],{},"\nThe following script will evaluate the table specified @TableName (you provide below), create a new table with {name}_Audit and also create insert, update and delete triggers.  In my example my table was Dave_Test in scheme engis.",[12,825,826,827,829],{},"Here is a screen shot of the end result audit table with the same columns PLUS 2 additional columns to document the action executed against the source table.",[571,828],{},[578,830,832],{"href":831},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-generate-insert-update-delete-trigger-fo_9e1f-image_2.png",[591,833],{"style":834,"src":835,"border":595,"alt":596,"title":596,"width":836,"height":837},"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;","\u002Farticles\u002Fimages\u002Fwindows-live-writer-generate-insert-update-delete-trigger-fo_9e1f-image_thumb.png",521,109,[12,839,840],{},"Here you can see the created _Audit table and newly created _Trigger_Delete, _Trigger_Insert and _Trigger_Update",[12,842,843],{},[578,844,846],{"href":845},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-generate-insert-update-delete-trigger-fo_9e1f-image_6.png",[591,847],{"style":834,"src":848,"border":595,"alt":596,"title":596,"width":598,"height":849},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-generate-insert-update-delete-trigger-fo_9e1f-image_thumb_2.png",183,[22,851,855],{"className":852,"code":853,"language":854,"meta":27,"style":27},"language-sql shiki shiki-themes github-light github-dark","SET ANSI_NULLS ON; GO SET QUOTED_IDENTIFIER ON; GO  \nDECLARE @TableName VARCHAR(200); \nSET @TableName = 'dave_test'; \n-- SET NOCOUNT ON added to prevent extra result sets from \n-- interfering with SELECT statements. \nSET NOCOUNT ON; \n--DECLARE @TABLENAME varchar(100) \nDECLARE @SCHEMA VARCHAR(100); \n--SET @TABLENAME = N'Company' SET @SCHEMA = N'engis';\nDECLARE @Done BIT;\nSET @Done = 0 DECLARE @CRLF CHAR(2);\nSET @CRLF = CHAR(10); DECLARE @SQL VARCHAR(2000); \nSET @SQL = 'IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Audit]'') AND type in (N''U'')) DROP TABLE [' + @SCHEMA + '].[' + @TableName + '_Audit] CREATE TABLE [' + @SCHEMA + '].[' + @TableName + '_Audit] (' + @CRLF; DECLARE @COLUMNID INT; SET @COLUMNID = 0; DECLARE @COLUMNNAME VARCHAR(1000); DECLARE @COLUMNTYPE VARCHAR(100); DECLARE @COLUMNSIZE INT; WHILE @Done = 0 BEGIN SELECT TOP 1 @COLUMNID = clmns.column_id , @COLUMNNAME = clmns.name , @COLUMNTYPE = usrt.name , @COLUMNSIZE = CAST(CASE WHEN baset.name IN ( N'nchar', N'nvarchar' ) AND clmns.max_length &lt;&gt; -1 THEN clmns.max_length \u002F 2 ELSE clmns.max_length END AS INT) FROM sys.tables AS tbl INNER JOIN sys.all_columns AS clmns ON clmns.object_id = tbl.object_id LEFT OUTER JOIN sys.types AS usrt ON usrt.user_type_id = clmns.user_type_id LEFT OUTER JOIN sys.types AS baset ON baset.user_type_id = clmns.system_type_id AND baset.user_type_id = baset.system_type_id WHERE ( tbl.name = @TableName AND SCHEMA_NAME(tbl.schema_id) = @SCHEMA ) AND clmns.column_id &gt; @COLUMNID ORDER BY clmns.column_id ASC; IF @@rowcount = 0 BEGIN SET @Done = 1; END; ELSE BEGIN SET @SQL = @SQL + ' [' + @COLUMNNAME + '] [' + @COLUMNTYPE + '] '; IF ( @COLUMNTYPE = 'nchar' OR @COLUMNTYPE = 'nvarchar' OR @COLUMNTYPE = 'varchar' ) SET @SQL = @SQL + '(' + LTRIM(STR(@COLUMNSIZE)) + ') '; \nSET @SQL = @SQL + 'NULL, ' + @CRLF; END; END; SET @SQL = @SQL + ' [' + @TableName + 'UpdateDate] datetime, [' + @TableName + 'UpdateAction] nvarchar(10) ) '; --print @SQL EXEC (@SQL);\nSET @SQL = ' IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Trigger_Update]'')) DROP TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Update] IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Trigger_Delete]'')) DROP TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Delete] IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Trigger_Insert]'')) DROP TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Insert] '; --print @SQL EXEC(@SQL); SET @SQL = 'CREATE TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Update] ON [' + @SCHEMA + '].[' + @TableName + '] AFTER UPDATE AS BEGIN SET NOCOUNT ON; INSERT INTO ' + @TableName + '_Audit SELECT *,getdate(),''Update'' FROM inserted END '; EXEC (@SQL); --print @SQL SET @SQL = 'CREATE TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Delete] ON [' + @SCHEMA + '].[' + @TableName + '] AFTER DELETE AS BEGIN SET NOCOUNT ON; INSERT INTO ' + @TableName + '_Audit SELECT *,getdate(),''Delete'' FROM deleted END ';\n\nEXEC (@SQL); --print @SQL SET @SQL = 'CREATE TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Insert] ON [' + @SCHEMA + '].[' + @TableName + '] AFTER INSERT AS BEGIN SET NOCOUNT ON; INSERT INTO ' + @TableName + '_Audit SELECT *,getdate(),''Insert'' FROM inserted END '; EXEC (@SQL);\n--print @SQL\n","sql",[29,856,857,862,867,872,877,882,887,892,897,902,907,912,917,922,927,932,937,942],{"__ignoreMap":27},[32,858,859],{"class":34,"line":35},[32,860,861],{},"SET ANSI_NULLS ON; GO SET QUOTED_IDENTIFIER ON; GO  \n",[32,863,864],{"class":34,"line":53},[32,865,866],{},"DECLARE @TableName VARCHAR(200); \n",[32,868,869],{"class":34,"line":59},[32,870,871],{},"SET @TableName = 'dave_test'; \n",[32,873,874],{"class":34,"line":65},[32,875,876],{},"-- SET NOCOUNT ON added to prevent extra result sets from \n",[32,878,879],{"class":34,"line":71},[32,880,881],{},"-- interfering with SELECT statements. \n",[32,883,884],{"class":34,"line":109},[32,885,886],{},"SET NOCOUNT ON; \n",[32,888,889],{"class":34,"line":115},[32,890,891],{},"--DECLARE @TABLENAME varchar(100) \n",[32,893,894],{"class":34,"line":121},[32,895,896],{},"DECLARE @SCHEMA VARCHAR(100); \n",[32,898,899],{"class":34,"line":126},[32,900,901],{},"--SET @TABLENAME = N'Company' SET @SCHEMA = N'engis';\n",[32,903,904],{"class":34,"line":132},[32,905,906],{},"DECLARE @Done BIT;\n",[32,908,909],{"class":34,"line":138},[32,910,911],{},"SET @Done = 0 DECLARE @CRLF CHAR(2);\n",[32,913,914],{"class":34,"line":144},[32,915,916],{},"SET @CRLF = CHAR(10); DECLARE @SQL VARCHAR(2000); \n",[32,918,919],{"class":34,"line":150},[32,920,921],{},"SET @SQL = 'IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Audit]'') AND type in (N''U'')) DROP TABLE [' + @SCHEMA + '].[' + @TableName + '_Audit] CREATE TABLE [' + @SCHEMA + '].[' + @TableName + '_Audit] (' + @CRLF; DECLARE @COLUMNID INT; SET @COLUMNID = 0; DECLARE @COLUMNNAME VARCHAR(1000); DECLARE @COLUMNTYPE VARCHAR(100); DECLARE @COLUMNSIZE INT; WHILE @Done = 0 BEGIN SELECT TOP 1 @COLUMNID = clmns.column_id , @COLUMNNAME = clmns.name , @COLUMNTYPE = usrt.name , @COLUMNSIZE = CAST(CASE WHEN baset.name IN ( N'nchar', N'nvarchar' ) AND clmns.max_length &lt;&gt; -1 THEN clmns.max_length \u002F 2 ELSE clmns.max_length END AS INT) FROM sys.tables AS tbl INNER JOIN sys.all_columns AS clmns ON clmns.object_id = tbl.object_id LEFT OUTER JOIN sys.types AS usrt ON usrt.user_type_id = clmns.user_type_id LEFT OUTER JOIN sys.types AS baset ON baset.user_type_id = clmns.system_type_id AND baset.user_type_id = baset.system_type_id WHERE ( tbl.name = @TableName AND SCHEMA_NAME(tbl.schema_id) = @SCHEMA ) AND clmns.column_id &gt; @COLUMNID ORDER BY clmns.column_id ASC; IF @@rowcount = 0 BEGIN SET @Done = 1; END; ELSE BEGIN SET @SQL = @SQL + ' [' + @COLUMNNAME + '] [' + @COLUMNTYPE + '] '; IF ( @COLUMNTYPE = 'nchar' OR @COLUMNTYPE = 'nvarchar' OR @COLUMNTYPE = 'varchar' ) SET @SQL = @SQL + '(' + LTRIM(STR(@COLUMNSIZE)) + ') '; \n",[32,923,924],{"class":34,"line":155},[32,925,926],{},"SET @SQL = @SQL + 'NULL, ' + @CRLF; END; END; SET @SQL = @SQL + ' [' + @TableName + 'UpdateDate] datetime, [' + @TableName + 'UpdateAction] nvarchar(10) ) '; --print @SQL EXEC (@SQL);\n",[32,928,929],{"class":34,"line":161},[32,930,931],{},"SET @SQL = ' IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Trigger_Update]'')) DROP TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Update] IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Trigger_Delete]'')) DROP TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Delete] IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Trigger_Insert]'')) DROP TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Insert] '; --print @SQL EXEC(@SQL); SET @SQL = 'CREATE TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Update] ON [' + @SCHEMA + '].[' + @TableName + '] AFTER UPDATE AS BEGIN SET NOCOUNT ON; INSERT INTO ' + @TableName + '_Audit SELECT *,getdate(),''Update'' FROM inserted END '; EXEC (@SQL); --print @SQL SET @SQL = 'CREATE TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Delete] ON [' + @SCHEMA + '].[' + @TableName + '] AFTER DELETE AS BEGIN SET NOCOUNT ON; INSERT INTO ' + @TableName + '_Audit SELECT *,getdate(),''Delete'' FROM deleted END ';\n",[32,933,934],{"class":34,"line":167},[32,935,936],{"emptyLinePlaceholder":608},"\n",[32,938,939],{"class":34,"line":173},[32,940,941],{},"EXEC (@SQL); --print @SQL SET @SQL = 'CREATE TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Insert] ON [' + @SCHEMA + '].[' + @TableName + '] AFTER INSERT AS BEGIN SET NOCOUNT ON; INSERT INTO ' + @TableName + '_Audit SELECT *,getdate(),''Insert'' FROM inserted END '; EXEC (@SQL);\n",[32,943,944],{"class":34,"line":179},[32,945,946],{},"--print @SQL\n",[600,948,602],{},{"title":27,"searchDepth":53,"depth":53,"links":950},[],"2016-02-13T07:03:23.3300000-05:00"," \nThe following script will evaluate the table specified @TableName (you provide below), create a new table with {name}_Audit and also create insert, update and delete triggers.  In my example my table was Dave_Test in scheme engis.",{},"\u002Farticles\u002Fgenerate-insert-update-delete-trigger-for-table-audit",{"title":816,"description":952},"articles\u002Fgenerate-insert-update-delete-trigger-for-table-audit",[854],"Dt6NMP0mx0GNm-szVZbRfyE2hv-az2OeYHLGEoaDFqU",1781574770780]