Everything I do more than once I try to automate. For example creating a static variable TAG in a class for logging. In Android Studio/Intellij you can create a live template to make this quicker. Go to Settings > Live templates > Add
, enter tag
in the abbreviation, a suitable description and
private static final String TAG = $CLASS_NAME$.class.getSimpleName();
as template text. Furthermore you have to define the variable $CLASS_NAME$
. For this open the edit variables dialog, choose className()
as expression and check "Skip if defined". Also, define the context to be Java.
If you know enter tag
and press Tab in a class it should autocomplete to something like:
private static final String TAG = MainActivity.class.getSimpleName();