1

I have a certain use-case problem that I am looking solution for.

Say in a text view I am displaying text like "Welcome Adam!". In general we store this text in strings.xml file. Now I want to update what is shown in the text view from the server without needing to update the entire app.

Ex, "Welcome Adam!" to "Hello Adam!".

What should be my approach in designing a solution?

Adam Young
  • 11
  • 2
  • 2
    rather than storing that string values in strings.xml, get value from web services and display response on textview. – Learn Pain Less Feb 23 '17 at 07:31
  • http://stackoverflow.com/questions/37496454/is-it-possible-to-update-string-xml-file-at-run-time-in-android – Uriel Zilberberg Feb 23 '17 at 07:32
  • 1
    You can have a look at Firebase RemoteConfig – sachinsharma Feb 23 '17 at 07:32
  • That text can be a large string, like a paragraph. Also that will not change very frequently. Using web service to load it every time will cause the entire paragraph to load every time. Can I go with push messaging and store the text somewhere? – Adam Young Feb 23 '17 at 07:37
  • you should create Database Table to keep all your strings with keys and its Language fire query with keys and language . – Chetan Joshi Feb 23 '17 at 07:39
  • How will I incorporate dynamic values in that? Like showing the user's name in place of a placeholder? – Adam Young Feb 23 '17 at 07:40
  • @LearnPainLess That way I'll have to download entire paragraph every time. The paragraph will not be changed frequently. Also how will I add localisation support? – Adam Young Feb 23 '17 at 07:47

3 Answers3

0
  • One url provided by EndPoint.
  • Fetch this url and read its response while app launching.
  • Set string in response to screen.
grantonzhuang
  • 557
  • 4
  • 6
  • That way I'll have to download entire paragraph every time. The paragraph will not be changed frequently. Also how will I add localisation support? – Adam Young Feb 23 '17 at 07:43
0

You cant change string, color, dimen etc xml file during runtime. I think what you are looking for is explained here

Community
  • 1
  • 1
Ashik
  • 1,035
  • 12
  • 15
0

You can implement it by "formatted string".For example , store "%1$s Adam!" in strings.xml, and write code like String welcome=context.getString(R.string.welcome,"Welcome").You can replace the first string with specified word if you want. For more information ,refer to AndroidDev

王佳斌
  • 1
  • 1
  • If you don't want to adopt the API approach - This can be one of your options. You can update the new string from your server using Firebase Remote Config. https://firebase.google.com/docs/remote-config/android – Bhargav Feb 23 '17 at 08:22