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

Lost background tasks example

In a very similar way, as we've just explored with Memory Leaks, it is possible to lose control (and related resources) of Threads and Background Threads.

Let's update the code for MockActivity to have an Observable.interval():

@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);    setContentView(R.layout.activity_mock);    Observable.interval(0, 2, TimeUnit.SECONDS)            .subscribe(i -> Log.i("APP", "Instance " + this.toString()             + " reporting"));    Log.i("APP", "Activity Created");}

Now, let's start the Activity a few times. We will promptly see that there are a lot of messages in the logs, as shown:

APP: Instance packt.reactivestocks.MockActivity@3c57ddae reportingAPP: Instance ...

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