- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
想象一下这个场景:我在 Pager
中有一个 Fragment
。我尝试切换到其他应用程序,以便拥有我的寻呼机(和我的 fragment )的 Activity
最终将停止并暂时销毁。
所以,当我回到我的 Activity 时,会调用 Fragment
的回调 onCreate
、oncreateview
等等。但是之前没有调用 Fragment 的 onDestroy
回调!似乎在“onStop”之后 fragment 立即被销毁。这是正常行为吗?是不是因为 Activity
没有调用它的 onDestroy
就被销毁了?
最佳答案
看看这个问题:Why implement onDestroy() if it is not guaranteed to be called?
基本上,onDestroy() 只有在你调用 finish() 时才会被保证被调用。否则,在系统认为有必要之前,可能不会调用 onDestroy()。您可能希望将“关闭”逻辑放在 onPause() 或 onStop() 中。
关于android - fragment 生命周期 : when "ondestroy" and "ondestroyview" are not called?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17195641/
我创建了一个窗口,并在某个时候调用了 OnDestroy(),而用户从未单击关闭窗口的“关闭”或“X”按钮。 还有哪些其他操作/ Action /事物可能导致调用此函数,为什么? Microsoft
这是我的部分代码: package com.admobsdk_dfp_handler; import com.google.ads.*; import com.google.ads.doublecli
覆盖 Activity 的 ondestroy 时,我应该在 super.onDestroy() 之前或之后放置命令吗? protected void onDestroy() { //opti
我用 onDestroy()方法,我的代码没有完成: @Override public void onDestroy() { super.onDestroy();
我的代码:(用于耳机控制和更改音量) @Override public void onResume() { headSetConn=new HeadSetBCast(); regist
我正在阅读 Activity 生命周期,并阅读有关启动和销毁 Activity 的文档,链接如下: http://developer.android.com/training/basics/activ
我目前正在构建一个 Android 应用程序,它将用作防盗类应用程序。基本上,一旦警报发出,应用程序将监控加速度计以检测运动。如果是,用户将有 15 秒的时间输入设置的密码来停用警报,否则:BIIII
我在检测应用程序何时完成时遇到了一些问题。我需要在 Destroy 上执行一些操作,例如将参数保存到数据库中并最终连接到服务器。 问题是,如果我将代码放在 onDestroy 中,例如,当方向发生变化
我知道在 Android 中,您不会得到有保证的 Activity 的 onDestroy() 调用。我的问题是在哪些情况下不调用 onDestroy()? 最佳答案 假设有两个 Activity A
当我的 Activity 由于内存而被操作系统破坏时(例如,当一个电话打断它时),然后当我的 Activity 试图再次启动时,它不会返回任何预期的回调,除了 onDestroy(),我怎样才能再次恢
我无法理解 onDestroy() 的行为。我的问题是:是否有可能在不杀死 hole 应用程序的情况下不调用 onDestroy() 就杀死一个 Activity ?我的意思是,我会不会回到我的应用程
我希望当我点击手机上的后退按钮时关闭当前 Activity 并返回菜单并停止媒体播放器 但我收到错误消息:不幸的是武器已停止!单击后退按钮 那么如何解决呢? public class pushke e
我开始在我看过的两个视频类(class)中学习 android 开发,我读过的一本书说 onDestroy() 是操作系统在感觉释放内存时调用的。甚至没有人提到它会在用户关闭应用程序时被调用。这让我怀
我已经学会了如何发送推送通知,效果很好,但即使在应用程序关闭后我也需要向用户发送通知。到目前为止,我知道如何在应用程序运行时发送它。在 Android 上,当应用程序处于后台或什至关闭时,您如何发送通
为什么后桶会在父级上调用 onDestroy()? 我有以下场景: Activity A 通过 intent 打开 Activity B Intent intent = new Intent(pare
我试图在我的 OnDestroy () 中调用一个服务,但是日志都不起作用,有人知道为什么吗? @Override protected void onDestroy() { Log.e("on
嗨,这是我的代码,我试图做的是在我触摸开始出现的屏幕可绘制对象后,首先在背景 (touch2) 中出现一张图片。那么问题出在哪里呢? 问题是在我触摸屏幕之前,当我看到 touch2 图像时,如果我按下
每当我的 Activity 被终止时,我都会尝试执行一些代码,但是当它只是简单地移到后台时不会(所以只在 onPause() 中调用它不是解决方案),并且我了解不能保证调用 onDestory()。我
我要打电话 onDestroy() android 中的服务方法。 我已经在互联网上搜索了很多,很多答案都是 if 服务强制停止或以某种方式它的 onDestroy() 永远不会调用。 但我真的需要知
我正在阅读“开始 Android 4 开发”这本书,并且我正在使用按钮中的以下功能控制服务: public void startService(View view) { startServic
我是一名优秀的程序员,十分优秀!