一次又一次的服务呼叫
我有一个非常简单的问题。我创建了一个活动,在其中我在 oncreate 方法中调用了一个服务。每次我改变设备的方向时,我的服务都会再次被调用。似乎它杀死了该活动,并且每次都会创建一个新活动。
请帮助我如何防止我的活动被杀死和重新创建。这对我所有的申请都会有帮助。
提前致谢
i am having a very simple problem. I have created an activity in which i have called a service in the oncreate method. every time i change the orientation of the device, my service gets called again. Seems like it kills the activity and a new activity is created everytime.
Please help me on how will i prevent my activity to get killed and recreated. That will be helpful in all my applications.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是标准行为,如果您不希望这样,最好将数据保存到您
可以在 onPause 中执行此操作:
当状态返回时,您可以调用 onResume 并恢复数据
This is standard behavior, if you dont want this you better save your data into the
You can do this in the onPause:
When the state returns you can call onResume and restore your data
我猜你需要先了解这一点 http://developer.android.com/参考/android/app/Activity.html#ConfigurationChanges
自己处理配置更改
Guess you need to understand this first http://developer.android.com/reference/android/app/Activity.html#ConfigurationChanges
Handle on Configuration change urself
只需在您的
activity
元素中的AndroidManifest.xml
中添加以下代码,这不会重新创建您的
activity
Just add the following code in ur
AndroidManifest.xml
in uractivity
elementthis will not recreate ur
activity