Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know where a string in strings.xml is used

As a user of Android Studio, I'd like to know where a string in strings.xml is used because I want to remove the strings which aren't in use.

like image 405
ryo Avatar asked Mar 04 '15 01:03

ryo


People also ask

Is a resource file used to hold name value pairs of strings?

xml is a resource file used to hold name/value pairs of strings.

How do you get string resources?

android:text="@string/hello" /> String string = getString (R. string. hello); You can use either getString(int) or getText(int) to retrieve a string.

Why should you use string resources instead of hard coded strings in your apps?

It allows you to easily locate text in your app and later have it translated. Strings can be internationalized easily, allowing your application to support multiple languages with a single application package file (APK).


2 Answers

rightclick Right click on a string in your strings.xml-> click "Find Usages" to see where it's used.

no usages

If it's not used anywhere then a little dialog will pop up in the corner saying so.

like image 68
Matter Cat Avatar answered Oct 09 '22 18:10

Matter Cat


Easier way to find unused strings in Strings.xml is to launch an inspection code from top menu of Android Studio (Analyse/Inspect code) on whole project.

In the inspection window, go to "Android Lint/Unused ressources", there you will find all the unused strings.

It will avoid you to make "find Usages" for lot of strings !

like image 37
Christian Avatar answered Oct 09 '22 18:10

Christian