如何robospice管理活动的生命周期? [英] How does robospice manage activity lifecycle?

查看:124
本文介绍了如何robospice管理活动的生命周期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个技术性的答复如何在Android robospice库管理活动的生命周期。从入门页面:

I'm looking for a technical answer to how the android robospice library manages activity lifecycle. From the getting started page:

<一个href="https://github.com/octo-online/robospice/wiki/Starter-Guide">https://github.com/octo-online/robospice/wiki/Starter-Guide

作为一个内部类的活动(或其他方面),加RequestlListener,将更新的用户界面。不用担心内存泄漏,RoboSpice管理您的活动的生命周期。

"As an inner class of your Activity (or other context), add a RequestlListener that will update your UI. Don't worry about memory leaks, RoboSpice manages your activity's life cycle."

我的问题是如何robospice自动更新请求听众,使其仍然能够经过旋转和活动已经破坏并重新创建一个新的实例后,调用正确的监听器与正确的上下文?

My question is how does robospice automatically update the request listeners so that it still is able to call the correct listener with the correct context after a rotation and after the activity has been destroyed and recreated as a new instance?

我一直在试图扭转工程师源$ C ​​$ C,但还没有找到一个答案了:

I've been trying to reverse engineer the source code but haven't found an answer yet:

https://github.com/octo-online/robospice

推荐答案

@Take机会让茶。你说的话就是完全正确的。 RS的设计与此前preSS需要记住:管理网络请求和活动的生命周期

@Take Chances Make Cha. What you are saying is just completely right. RS has been designed with this express need in mind : managing network requests and activities' life cycles.

@ craigrs84。基本上,会发生什么用RS是,当一个请求正在处理,它的听众将被调用的只要相关联的活动还活着的。如果活动不活了,所有的听众都来自RS​​拔出,他们将不会收到通知。

@craigrs84. Basically, what happens with RS is that when a request is being processed, its listeners will be invoked as long as the associated activity is alive. If the activity is not alive anymore, all of its listeners are unplugged from RS, and they will not be notified.

RS的主要目的是确保没有内存泄漏:你的行为,如果它已经不行了,会死和被垃圾收集,RS不持有任何硬引用它,将prevent垃圾收集。这是真正的背后RoboSpice的核心思想。

The main purpose of RS is to make sure that there is no memory leak : your activity, if it has to die, will die and be garbage collected, RS doesn't hold any hard reference to it that would prevent garbage collection. That's really the core idea behind RoboSpice.

如果你希望你的活动的一个新的实例被重新插入到未决请求(比如你执行一个请求,然后旋转设备,然后让你的活动的一个新实例,并希望新的实例来接收结果由previous实例执行的要求)的,这是可能的RS。

If you want a new instance of your activity to be replugged to a pending request (for instance you execute a request, then rotate the device and then get a new instance of your activity, and want that new instance to receive the result of the request executed by the previous instance), that's possible with RS.

在这种情况下,使用方法 spiceManager.addListenerIfPending 在启动,调用spiceManager.start(..)之后。这将不执行新的请求,但重新插拔了新的监听器,一个挂起的请求。如果没有请求被挂起,那么它不会做任何事情。

In such a case, use the method spiceManager.addListenerIfPending in on start, right after the call to spiceManager.start(..). This will not execute a new request, but re-plug a new listener to a pending request. If no request is pending, then it will do nothing.

这篇关于如何robospice管理活动的生命周期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆