Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 装载机的生命周期是什么? 背景_Android_Android Asynctask_Loader_Asynctaskloader - Fatal编程技术网

Android 装载机的生命周期是什么? 背景

Android 装载机的生命周期是什么? 背景,android,android-asynctask,loader,asynctaskloader,Android,Android Asynctask,Loader,Asynctaskloader,我正致力于通过支持应用程序的横向模式来改进应用程序。我经常使用的一件事是,或者更具体地说 使用加载程序允许您继续执行后台任务,即使活动由于方向更改而被重新创建,而不是 问题 我想问一下装载机的生命周期: 他们什么时候被解雇?我是否必须跟踪它们,如果其中有位图,我是否应该尽快放弃它?他们是否只有在活动真正被破坏之后(而不是因为配置更改)才会得到GC ed 我注意到它们有停止的状态。这能让我暂停吗 如果#2为真,我将如何实现一个可以在自身某些点上暂停的加载程序 碎片也可以有装载机吗?正如我所注意到的

我正致力于通过支持应用程序的横向模式来改进应用程序。我经常使用的一件事是,或者更具体地说

使用加载程序允许您继续执行后台任务,即使活动由于方向更改而被重新创建,而不是

问题 我想问一下装载机的生命周期:

  • 他们什么时候被解雇?我是否必须跟踪它们,如果其中有位图,我是否应该尽快放弃它?他们是否只有在活动真正被破坏之后(而不是因为配置更改)才会得到GC ed
  • 我注意到它们有停止的状态。这能让我暂停吗
  • 如果#2为真,我将如何实现一个可以在自身某些点上暂停的加载程序
  • 碎片也可以有装载机吗?正如我所注意到的,它只用于活动
  • 如果#4为false,那么在导航抽屉的设计模式中使用装载机替换容器中的碎片的建议方法是什么
  • AsyncTaskLoader可以像AsyncTask(或线程)一样被中断吗?我看过它的代码和API,但找不到它。我也试图找到解决办法,但没有成功
  • 如果#6为假,还有其他选择吗?例如,如果我知道加载程序不需要加载某些内容,我可以立即停止它。我能想到的一种方法是设置一个标志(可能是原子布尔,以防万一),它会告诉它停止,并有时在内部检查这个值。问题是,我甚至需要在它使用的函数中添加它,而更简单的方法是调用“Thread.sleep(0)”或类似的东西
  • 是否有关于装载机生命周期的解释
  • AsyncTaskLoader是同时工作的,还是像AsyncTask的默认、当前行为一样,只在单个线程上运行
  • 由于
    加载程序生命周期
    与活动/片段生命周期相关联,因此可以安全地假设垃圾收集几乎同时发生。请看#8,了解装载机的生命周期。可能会给你一些想法

    2.I've noticed they have states of being stopped. Does this somehow allow me to pause them?
    
    不,据我所知,加载器没有一个
    onPause()

    3.If #2 is true, How would I implement a loader that can be paused on some points of itself?
    
    我真的没有答案。我想知道解决这个问题的办法

    4.Can fragments also have Loaders? As I've noticed, it's only for activities.
    
    当然,片段可以有加载器。只需在
    onActivityCreated()
    方法中初始化
    loaderManager

    5.if #4 is false, what is the recommended way to use loaders in the design pattern of navigation-drawer that replaces fragments in the container?
    
    4是真的。所以我想这个问题无关紧要

    6.Can AsyncTaskLoader be interrupted like AsyncTask (or threads)? I've looked at its code and at the API, but I can't find it. I've also tried to find a workaround, but I didn't succeed.
    
    我不知道你打断装载机是什么意思。但是如果您的意思是拥有类似于
    isCancelled()
    方法的东西,那么在
    AsyncTaskLoader
    上有一个名为
    canceload()
    的方法。完整的流程就像
    cancelLoad()
    ->
    cancel()
    ->
    onCancelled()

    7.If #6 is false, is there an alternative? For example, if I know that the loader doesn't need to load something, I could just stop it right away. One way I can think of is to set a flag (maybe AtomicBoolean, just in case) that will tell it to stop, and check this value sometimes within. Problem is that I will need to add it even inside functions that it uses, while an easier way would be to call "Thread.sleep(0)" or something like that.
    
    又不相干了

    9.Do AsyncTaskLoaders work together, at the same time, or are they like the default, current behavior of AsyncTask, which runs only on a single thread ?
    
    在单个线程上运行

    8.Is there somewhere an explanation of the lifecycle of Loaders?
    
    据我所知:

    • 创建活动/片段时,加载程序启动->
      onStartLoading()

    • 当活动不可见或片段分离时,加载程序停止->
      onStopLoading()

    • 重新创建活动或片段时没有回调。
      LoaderManager
      将结果存储在本地缓存中

    • 当活动/片段被销毁时->
      restartLoader()
      destroiloader()
      被调用,并且加载程序重置

    我希望这有帮助。有些答案我可能有点不对劲。我自己也在不断地学习新事物。
    干杯。

    4。但这意味着加载程序实际上是由活动而不是片段创建的(并绑定到该活动),这意味着5需要一个答案:)。6.对于AsyncTask,您可以调用cancel(true),它除了设置标志外,还将中断AsyncTask的线程。加载完成后是否会调用onCancelled?如果是的话,这不是和“放弃”差不多吗?7.为什么?8.我认为当活动本身被破坏(而不是片段)时,它就会被破坏,并且只有当它不是因为方向改变时才会被破坏。其他配置的变化呢?还有,2。这只是猜测。我想其中一个州会指出这一点,因为有“onStopLoading”
    8.Is there somewhere an explanation of the lifecycle of Loaders?