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
From the course: Android Studio Essential Training 2020
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
-
-
-
-
-
-
-
-
(Locked)
Create new Kotlin and Java code files3m
-
(Locked)
Edit code files in the editor window3m 15s
-
(Locked)
Useful code editing shortcuts4m 49s
-
(Locked)
Refactor and inspect code3m 6s
-
(Locked)
Create and use live templates3m 32s
-
Edit layouts with design and text mode3m 36s
-
(Locked)
Add MotionLayout to an XML layout file2m 2s
-
(Locked)
Animate views in the Motion Editor4m 56s
-
(Locked)
Challenge: Extract code to a new class1m 8s
-
(Locked)
Solution: Extract code to a new class2m 12s
-
(Locked)
-
-
-
-