From the course: Android Studio Essential Training 2020

Unlock the full course today

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

Solution: Extract code to a new class

Solution: Extract code to a new class

From the course: Android Studio Essential Training 2020

Start my 1-month free trial

Solution: Extract code to a new class

(upbeat music) - [Narrator] I previously offered a challenge to test your knowledge of Android Studio's refactoring functions. To take some existing code from an activity and to extract that code into a new function. Here is my solution. I'm going to select this code that initializes the user layout for this activity. Then here are a couple of different ways you can get to the extract tool. You could go to refactor, extract, and then function. Or you could select refactor and refactor this and then choose function under the extract section. Either way, you'll get to the extract function dialog and I'll name my new function initlayout. I'll click okay. And that creates the new function and adds a call to the new function in the on create function, where the code used to exist. Android Studios refactoring tools can really help you speed up your coding. Let's take another example. Let's say I wanted to change the…

Contents