Android:Field can be converted to a local varible.

background

It’s been a while since Android studio was used to develop Android. Occasionally, as has a yellow highlight on some private variables field can be converted to a local variable . I still don’t want to see this yellow highlight for some obsessive-compulsive disorder. Baidu did not find any useful information, or Google search to find some answers.

analysis

The complete description of field can be converted to a local variable is (hand play only): field can be converted to a local variable :

This inspection searches for redundant class fields that can be replaced with local variables,if all local usages of a field are preceded by assignments to that field,the field can be removed and its usages replaced with local variables.

This means that it is detected that this variable can be replaced by a local variable. It is recommended to delete it and write it as a local variable.

Solution

Delete the sentence private XXX; and declare and instantiate it directly where it is used.
In Android studio for Mac , you can use the shortcut key Alt + enter to quickly convert local variables.

PS: you still need better English. In fact, you can understand it by reading the instructions. You don’t need to search in this way.

Read More: