设备屏幕旋转时是否有任何方法被调用? Android中的数据是否被删除和恢复?Windows 10手机旋转屏幕/屏幕方向
当屏幕旋转时,Android应用程序被销毁并重新启动。要在旋转过程中保持其地位,你需要调用:
onSaveInstanceState()
onRestoreInstanceState()
在Windows 10通用的应用设备旋转过程中有一个存储会话状态?
设备屏幕旋转时是否有任何方法被调用? Android中的数据是否被删除和恢复?Windows 10手机旋转屏幕/屏幕方向
当屏幕旋转时,Android应用程序被销毁并重新启动。要在旋转过程中保持其地位,你需要调用:
onSaveInstanceState()
onRestoreInstanceState()
在Windows 10通用的应用设备旋转过程中有一个存储会话状态?
我知道这是旧的,你可能已经搬到了别的东西上。对于遇到这个问题的其他人(比如我),答案是:是的,有一种方法。是的,它看起来就像数据被存储和检索一样,系统会为你处理你的'Bundle'。
在你App.xaml.cs文件中,有一个方法:
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
这会保存状态为您服务。这是有道理的,我的Windows手机将返回按钮到上次我点击主屏幕时。如果我从应用程序转到应用程序,后退按钮会通过每个应用程序返回,保持我离开的地方。
当我在窗口上放置一个TextBlock并使用按钮更改文本时,文本在旋转后保持不变。在我退出应用程序的“返回按钮”或“主页”后,它实际上保持不变。保持状态似乎不成问题,失去它可能是。 (从现在起,我会记得放置一个“重置”按钮或方法!)
OnSuspending()
定义在sealed partial class App : Application
中,密封意味着您不能扩展它,因此您也不能覆盖OnSuspending()
。
您可以使用SizeChanged事件。比较高度和宽度值以确定横向和纵向模式。保持一个变量来知道当前的模式。使用这些可以确定屏幕旋转。 –
我只想知道当屏幕旋转时,数据字段存储在某处并重新输入,或者除了方向改变之外什么都没有发生,在Windows 10手机/移动设备中发生了什么? – Icero
我想只有布局中的元素再次呈现。破坏和重新启动没有任何反应。 –