0

How do I find out at runtime, which string resource instance has been applied to the application I am writing in Android Studio?

To be more precise: I defined resources for three languages (say German, English, and French).

At runtime, I want to find out the match (to the user's locale), that has actually been applied.

For instance, if the user speaks Canadian French (his phone's locale), then the match will be French, as I learned from the Android studio documentation pages on "Locale".

If the user's locale is Japanese, then the match will be the default one (German in my case).

If the locale changes to Danish, the applied resource still will be the default one (German).

Now in my case, I need to get the resource, out of those I personally defined (which are German, English and French), that has actually been applied to "inflate the layout".

The reason is that I do manual locale changes within the app (and only valid for the app, not for the phone), and that I want to cause a refresh procedure for the activity only if indeed the underlying string-resource source has changed.

Pawandeep
  • 315
  • 1
  • 3
  • 19
Coffee
  • 11
  • 5
  • You can as described here but you should restart your app after you changed the language https://stackoverflow.com/questions/36922040/how-to-change-language-for-a-whole-android-application – Alessandro Verona Aug 22 '17 at 07:05
  • Thank you, but how can I prevent the case that I restart the app, even though the underlying string resource remains the same (as described in my question)? – Coffee Aug 22 '17 at 07:13
  • 1
    Welcome to Stack Overflow. For future reference, please note that it is the consensus here that salutations/thanks etc in a question or answer are noise and should be edited out. Please review [Should 'Hi', 'thanks', taglines, and salutations be removed from posts?](https://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts) and [My opening “Hi everyone” in my question keeps disappearing](https://meta.stackoverflow.com/questions/251077/my-opening-hi-everyone-in-my-question-keeps-disappearing) – FluffyKitten Aug 22 '17 at 07:38
  • Does this bring questions closer to being answered? Have you considered reviewing the consensus before? – Coffee Aug 22 '17 at 07:45
  • 1
    Please read the posted links to understand the reason they are considered noise and unhelpful. It you do not feel the terms of the site are a good fit for you, then maybe the Stack Exchange sites are not for you. – FluffyKitten Aug 22 '17 at 07:46
  • Well, I will agree on this consensus, as soon as my question is answered. Still, looking for something helpful, an answer might be a proper candidate. – Coffee Aug 22 '17 at 07:57
  • Did you just edit your comment after I answered it? – Coffee Aug 22 '17 at 08:16
  • I think my question is kind of a tricky one, and I would very much appreciate anyone knowing an answer to it. – Coffee Aug 22 '17 at 08:17
  • this should help you https://github.com/akexorcist/Android-LocalizationActivity. You can learn from it. – ישו אוהב אותך Aug 22 '17 at 13:25
  • @Coffee I'm afraid this is not my area of expertise so I cannot help; my edit (that you rejected) and comments were made during the quality review process, that all first-time questions and answers go through. And no I didn't edit my comment before you answered - comments can only be edited for 5 minutes after they are added and I was only fixing grammar. – FluffyKitten Aug 22 '17 at 16:33
  • @ישו אוהב אותך: It seems to me that it is not possible to extract an answer to my question from your library. My question is not about -how- to change the language but about how to find out -when- it is necessary to reload the activities' contents. – Coffee Aug 23 '17 at 06:55
  • @Saret: It looks like the posted link's content is not capable of contributing to finding an answer to my question. – Coffee Aug 23 '17 at 06:58
  • @FluffyKitten: You clearly added the second sentence in your edit. You should think about, whether this quality review process needs to be reviewed: For a new user it is hard to understand, how value is created by the deletion of greetings. A new user (like I) can have the impression that (1) people are bored and (2) they look for substitutes in cases when they do not know an answer to a question. I would also suggest a mechanism by self-assessment, that makes people preferentially review questions that belong to their field of expertise, only. You have to try the user's perspective, ... – Coffee Aug 23 '17 at 07:14
  • ... i.e., how your processes are experienced by your "clients". – Coffee Aug 23 '17 at 07:15
  • As I said, comments are locked after 5 minutes so it was *impossible* for me to edit it after your response. As the [initial tour after registration](https://stackoverflow.com/tour) indicates, SO is run by the community i.e. people *just like you*, who have earned enough reputation for privileges such as voting, editing & reviewing, so the entire community is involved in how the site works and have shaped how it works now. Again, if you do not feel the site is a good fit for you, then maybe it just isn't for you. – FluffyKitten Aug 23 '17 at 15:07
  • If I had a solution to my above-described question, then I would consider this site a very good fit for me (of course, given that mentioned solution was indeed posted at this site). – Coffee Aug 24 '17 at 09:33
  • So far I only experienced the deletion of my greetings ;( (and the discussion about it). – Coffee Aug 24 '17 at 09:34
  • And two approaches, but I must say, these do not fit my question, unfortunately. – Coffee Aug 24 '17 at 09:36

0 Answers0