Google Developers
Published in

Google Developers

Writing More Code by Writing Less Code with Android Studio Live Templates

An Android Tool Time Pro Tip

Toast.makeText(MainActivity.this, "This will not be displayed");

What is this magic I speak of? Live Templates!

Live template to (correctly) create and display a new Toast

Android Studio Live Templates: A Handy Reference

IntelliJ includes over dozens of Live Templates, and Android Studio features another 48 specific for Android development. Here’s a few of my favorites for easy reference

A small sampling of Android Studio Live Templates
public static void start(android.content.Context context) {    
android.content.Intent starter = new Intent(context, $ACT$.class);
starter.putExtra($CURSOR$);
context.startActivity(starter);
}

Create Your Own Live Templates

android.content.SharedPreferences sharedPreferences =     
getPreferences(Context.MODE_PRIVATE);
android.content.SharedPreferences.Editor editor =
sharedPreferences.edit();
editor.putBoolean(getString(R.string.$stringVal$), $spVal$);
editor.apply();

--

--

Engineering and technology articles for developers, written and curated by Googlers. The views expressed are those of the authors and don't necessarily reflect those of Google.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Reto Meier

Developer Advocate @ Google, software engineer, and author of “Professional Android” series from Wrox. All opinions are my own.