1 00:00:00,540 --> 00:00:03,820 On Android it's common that during rotations we need to release 2 00:00:03,820 --> 00:00:08,250 any resources we have, and allow our activity to be rebuilt by the system. 3 00:00:08,250 --> 00:00:11,650 This means we need to unsubscribe to all these subscriptions that we've set up. 4 00:00:12,840 --> 00:00:16,140 So here we have our combined latest subscription, and 5 00:00:16,140 --> 00:00:20,730 we also had our clicks for adding new items both of those subscriptions. 6 00:00:20,730 --> 00:00:24,840 We need to unsubscribe to those during on destroy, and 7 00:00:24,840 --> 00:00:29,390 there's a common pattern for doing this, and it's called composite subscription. 8 00:00:29,390 --> 00:00:34,796 So let's go ahead and go up to the top here, and what we're going 9 00:00:34,796 --> 00:00:40,920 to do is we're going to add in a new type called composite subscription. 10 00:00:44,220 --> 00:00:49,061 We're gonna call it subscriptions and create a new composite subscription. 11 00:00:52,520 --> 00:00:57,575 So what this is gonna do is this is going to allow us to merge together or 12 00:00:57,575 --> 00:01:02,600 handle and keep track of all our subscriptions in a single place. 13 00:01:02,600 --> 00:01:07,730 So it's just delegates to all subscriptions we add to it. 14 00:01:07,730 --> 00:01:13,130 So we're gonna do now is add to our current subscriptions to this 15 00:01:13,130 --> 00:01:14,820 composite subscription. 16 00:01:14,820 --> 00:01:19,730 So let's go down here, and where we did our combine latest. 17 00:01:21,680 --> 00:01:24,890 Let's go ahead and do, subscriptions.add, 18 00:01:24,890 --> 00:01:30,270 and add in this entire subscription. 19 00:01:33,830 --> 00:01:37,992 And let's go ahead and 20 00:01:37,992 --> 00:01:43,249 go back up to our clicks, and 21 00:01:43,249 --> 00:01:49,393 go ahead and add this one as well. 22 00:02:01,550 --> 00:02:05,257 Okay, so what we can see is that we added our subscriptions for 23 00:02:05,257 --> 00:02:09,270 our observables to this composite subscription, here and here. 24 00:02:10,360 --> 00:02:14,090 And then what we're gonna do is down and on destroy, 25 00:02:14,090 --> 00:02:19,260 we'll be able to actually unsubscribe to these all together at the same time. 26 00:02:19,260 --> 00:02:20,510 So it's really easy. 27 00:02:20,510 --> 00:02:25,611 We just go down here, and we say subscriptions.unsubscribe. 28 00:02:25,611 --> 00:02:27,191 And that's it.