如何在纵向模式下保存所有状态 Android

How to save all states in portrait mode Android

我想知道如果 Android OS 在不使用 "OnSavedInstance" 的情况下如何提供存储状态? 例如,我有 main activity 和一些控件(文本框),出于某种原因,用户按下主页按钮,在这种情况下,我想存储引入该控件的所有数据。 这可能不是 destroy/recreate Activity,而是仅存储到 phone(RAM) 的内存中吗?

i want to know how if Android OS provide to store states without using "OnSavedInstance" Yes,Android OS provide this.
It's pretty simple,what we need to do is :

[Activity(Label = "YourActivityName",Icon = "@drawable/icon",ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait, ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize )]

这正是您所需要的。
魔法就在这里:

ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait, ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize )

现在当您旋转您的phone或按下主屏幕按钮时,activity将是NOT destroyed(也就是说,OnCreate()方法不会被一次又一次调用重新创建activity)。 享受吧!