From the course: Android App Development: Design Patterns for Mobile Architecture

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Dependency injection, part 2

Dependency injection, part 2 - Android Tutorial

From the course: Android App Development: Design Patterns for Mobile Architecture

Start my 1-month free trial

Dependency injection, part 2

- [Instructor] We're now implementing the Injection Methods for the activities. In the activities, we have to use Method Injection, instead of Constructor Injection. All that means is we have to have some sort of way for the activity to say hey Dependency Registry inject the things that I need, please. So, we're first going to make our Spy Details Activity. We'll make a method that returns a void. We'll call it inject. In this inject, I'll say I need a Spy Details Activity to set up, and then a bundle to parse. This is going to throw a No Such Element Exception. And, this is because the bundle ID might not have the Spy ID. We always expect that it should, but we're going to say, hey there's an error, if we're not able to get the ID from the bundle. So in here, we're going to say Spy ID is equal to ID from bundle, which is a method that we are going to make up. I'll implement that right now. And, we'll just put this in a region. We'll call it Helper Methods. And, coming into that…

Contents