O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Paying special attention to onCreate()

Since we already know that Activities can be torn down and created again when the configuration of the device changes, it basically means that the onCreate() method of the Activity can be called multiples times while not changing (moving away) the Activity itself.

So, consider that there is a call like this in the onCreate() block:

Observable.interval(0, 5, TimeUnit.SECONDS)

It will be executed multiple times. If this isn't cleaned up properly, it will most likely leak the Activity along with its allocated memory and the Observable itself, which will keep running in the background and consuming resources.

More experienced readers will have noted this already, but we have exactly this kind of leak in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required