I’m new to Android & Java programming but have been programming in .NET for many years. We’ve recently developed an android app and it’s now in the final stage to be prepped for the customer (not via the market/google play btw). At any rate, while cleaning up the code. I’ve noticed we use a TON of strings and I’d like to cut down on this if possible. I’ve read a few articles and took the suggestion that anything the end-user may see, I put it in the strings.xml (for better localization, not too sure what they mean by that) but we also use SQLite table names, column names, etc. and I’d like to know the best way to construct a class (or set of classes) that allows us (my developers and I) to access them with ease.
This is how I started to construct it but wanted some opinions as to if there’s a better way (design, performance issues, etc.)
public class Constants {
static enum SQLiteTableNames { Issues, Activities }
static class SQLiteTables {
static class Issues {
static class ColumnNames {
static String ID = "_id";
static String DateReceived = "DateReceived";
}
}
static class IssueActivites {
static class ColumnNames {
static String ID = "_id";
static String IssueID = "IssueID";
static String ActivityDate = "ActivityDate";
static String ActivityType = "ActivityType";
static String FullName = "FullName";
static String Notes = "Notes";
}
}
}
}
This allows us to reference column names like so:
Constants.SQLiteTables.IssueActivites.ColumnNames.ActivityDate;
Should I use final static on the properties instead of just static?
Constants should be
static final. This does have a performance benefit, as it allows the value to be compiled in. It’s also just good style.By the way, the convention is to put constant names in
ALL_CAPS.