Sitemap

Android Studio Tip #1— Scratch Files

3 min readJun 5, 2023
Press enter or click to view image in full size
Photo by ThisisEngineering RAEng on Unsplash

👋🏻 Introduction

Android Studio is a powerful development environment that offers numerous features to streamline the app development process. This is the first article in Android Studio Tips Series and we’ll be covering one feature that can significantly enhance productivity which is Scratch Files.

In this article, we will explore Scratch Files in Android Studio and delve into their benefits and effective usage. Whether you’re a beginner or an experienced developer, understanding and utilizing Scratch Files can save you time and make your coding experience more efficient.

⁉️ What are Scratch Files?

Scratch Files in Android Studio are temporary files that allow developers to write and test code snippets without creating or modifying new files. These files are stored in memory and provide a quick and convenient way to experiment, prototype, and validate ideas without the overhead of project setup.

🤔 How to Create a Scratch File?

There are 3 ways to create Scratch Files

  1. File -> New -> Scratch file
  2. Right-click on your App module -> New -> Scratch File
  3. ⇧⌘N on Mac OS

Then you’ll be asked to select your file extension, and here you go 🚀 you’ve created your first Scratch file

Press enter or click to view image in full size

👨🏻‍💻 Writing and Executing Code

Discover how to leverage Scratch Files to write and execute code efficiently. It's very simple all you need is to start writing the function as an example a method that adds to numbers and returns the result. You’ll find the result auto-printed in the right console.

Press enter or click to view image in full size
  • The interactive mode option auto-compiles this snippet and shows the result immediately in the right console, if you want to turn it off, uncheck the box.
  • Also, you could use Classes from other modules by opening the <no module> drop-down and selecting the module that contains the classes that you want to run in this scratch file.
  • To Locate scratch files you’ll always find them under Project -> Scratches and Consoles -> Scratches

This feature will help you to keep your project files clean and speed up your productivity and saves lots of wasted time in building the whole project.

If you liked this tip please 👏 and follow for more tips. Thanks!

--

--

Mohamed Zakaria (Zak)
Mohamed Zakaria (Zak)

Written by Mohamed Zakaria (Zak)

Engineering Manager | Photographer | Writer | Learner

No responses yet