Prevent activity from reload after rotation in xamarin, monodroid

前端 未结 3 1855
忘掉有多难
忘掉有多难 2021-01-24 05:18

Ok... So my problem is to prevent from activity to reload after orientation is changed. Basically, what I did is this:

[Activity(Label = \"migs\", ConfigurationC         


        
3条回答
  •  没有蜡笔的小新
    2021-01-24 06:06

    what happen when orientation change (consider you enable rotation in your phone) ?

    Android restart activity onDestroy() is called, followed by onCreate() , you can distinguish between onDestroy() call to kill activity or restart app throw old answer.

    Prevent Activity restart

    just set ConfigurationChanges to both Orientation , ScreenSize

    [Activity (Label = "CodeLayoutActivity", ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
    

    why this may be not working ?

    I dont think this will not working but set RetaintInstance to true read more about RetainInstance

    class myFragment: Fragment
        {
    
            public override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);
                this.RetainInstance = true;
              // this to change screen orientation 
                Activity.RequestedOrientation = ScreenOrientation.Landscape;
    
    
            }
    
           .....
    
    }
    

    hope this help

提交回复
热议问题