Is RoboSpice shouldStop () required?

I wonder if the shouldStop () SpiceManager method is needed at all .. I got the idea that it should untie possible listeners from the activity / fragment, but if the activity is killed in any case, is it all? The garbage collector will still clear the activity / fragment, and the background services will still be separated from each other. Or am I wrong here? Does Android really leak when you forget some link in the background thread?

There are several (erroneous) comments in the source code : for shouldStop () , it says that it will disconnect asynchronously, and for shouldStopandJoin () synchronously. But shouldStop calls shouldStopAndJoin, and the shouldStopAndJoin comment says that it is basically a testing method. So, do we really need to call shouldStop in the onStop () activity of the callback?

I ask about this because I would like to have an instance of spicemanager in the context of an application that does not have a special way to deal with cleaning or stopping. Therefore, I want to be sure that there is no leak or something like that. To be clear, it’s not really in the context of the application, but a custom “controller” that runs from the application context and controls all background materials, such as robospice requests or location material. I am trying to emulate an MVC pattern where all the logic is really independent of the actions and fragments that only @Subscribe methods have to change the user interface.

EDIT: Actually, if I call this from the application context, then this is a different case than Activity or Fragment. Even if the actions or fragments were leaking, the application should not, right?

Thanks for any comments.

+4
source share
1 answer

Does Android really flow when you forget some kind of link in the background thread?

Yes Yes. This is a very good way to create leaks.

So, do we really need to call shouldStop in the onStop () activity of the callback?

Yes, you do this in the order 1) to prevent leaks, 2) to prevent your callbacks from being triggered after the death of the launching context, which can lead to a crash. But you're right, javadocs can be confusing. ShouldStopAndJoin is called for testing (see Its as private + tests) and shouldStop is public.

Even if the actions or fragments were leaking, the application should not, right?

Right. , , , Java. , shouldStop .

+5

Source: https://habr.com/ru/post/1544019/


All Articles