当设备旋转时调用 onDestroy 时线程会发生什么
我想知道由活动创建的线程和设备旋转会发生什么。我观察到发生这种情况时会调用 onDestroy 方法。线程也会被杀死吗?
如果线程没有被终止,当轮换时创建活动的新实例时,如何将线程与活动重新关联。
谢谢,
拉克什米
I would like to know as to what will happen to the thread which has been created by an activity and the device is rotated. I have observed that the onDestroy method is called when this happens. Will the thread be killed too?
If the thread is not killed, how can I reassociate the thread with the activity as a new instance of the activity is created on rotation.
Thanks,
Lakshmie
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
线程没有被杀死。您可以通过覆盖 < 来保留对线程的引用code>onRetainNonConfigurationInstance() 保存线程对象,然后
getLastNonConfigurationInstance()
将其取回。The thread is not killed. You can keep a reference to your thread by overriding
onRetainNonConfigurationInstance()
to save the thread object and thengetLastNonConfigurationInstance()
to get it back.