0

Is it a bad idea to create a public class Strings in Android app that only hosts all the strings needed (instead of using the Android built in strings.xml)?

i.e.

public class Strings {
    public static final String RESOURCE_ONE = "hello";
    public static final String RESOURCE_TWO = "world";
}

so then from anywhere in the Android app I can just do

args.putString(Strings.RESOURCE_ONE, "resource");

instead of the default

args.putString(getString(R.string.resource_one), "resource");

I'm thinking of this approach so then I don't need to use Context all the time, which is useful when I need a string in a static function. However, I'm not sure if declaring an entire class to store every single String will be memory intensive and waste memory in the app.

Any ideas?

bycfly
  • 341
  • 3
  • 13

1 Answers1

4

Yes,it's a bad practice to store strings like that.However some strings you have to put in strings.xml like app_name etc. If you store everything in class than you will not have the options to easily provide different translations for your strings. You can store some strings that are constant throughout the app in a class like that ,say a class AppConstant that contains all the strings that are used by every class for different purposes. For more https://developer.android.com/guide/topics/resources/string-resource.html

himel
  • 500
  • 5
  • 14