Fixed
Status Update
Comments
uc...@google.com <uc...@google.com> #2
Thank you for suggesting this enhancement. We value the feedback from our community and hope to review your suggestion in an upcoming sprint.
tn...@google.com <tn...@google.com> #3
Good idea!
tn...@google.com <tn...@google.com> #4
Fixed for an upcoming 3.2 canary by Change-Id: I93b86823b3311b2214da50fdcae7deb4fc095729 . Thanks for the suggestion!
Description
This is why the next code can be problematic:
class MainActivity : AppCompatActivity() {
companion object {
val PROBLEMATIC_DESCRIPTION_DATE_FORMAT = SimpleDateFormat("MMM dd", Locale.getDefault())
//same for the single parameter CTOR : SimpleDateFormat("MMM dd")
}
val SAFE_DESCRIPTION_DATE_FORMAT = SimpleDateFormat("MMM dd", Locale.getDefault())
override fun onResume() {
super.onResume()
val today = Calendar.getInstance().time
Log.d("AppLog", "problematic:" + PROBLEMATIC_DESCRIPTION_DATE_FORMAT.format(today))
Log.d("AppLog", "safe:" + SAFE_DESCRIPTION_DATE_FORMAT.format(today))
}
}
If you run the app, then change the locale, and get back to the app, you will see that the problematic formatting of the date stayed the same.
If you'd use it in TextView, for example, you will see the formatting of the previous language you had.
I suggest that whenever you use Locale.getDefault() , directly or not, in the above way (meaning that it's in a static-final variable), it will warn you about it.
There might be other similar cases to that.
Attached sample project and screenshot to show why it's important.