0

As per requirement, now all the values of my String.xml file come from the server.
And i need to handle the same in the application and these values are dynamic. what is recommended way to do this.
As per design i save these values in database and on application launch i cache the data in the hashmap and i use the map throughout the application. I have made a service that update the database in the background.

Is there any better way than this?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user3586231
  • 391
  • 4
  • 21
  • which kind of dynamic string values will come from server? – Jay Shah Aug 19 '16 at 11:40
  • shared preferneces is may useful.Update shared preferences values when you get data from server and use the values from shared preferences – Narender Reddy Aug 19 '16 at 11:43
  • i dont think you can do that. Those are hard coded and cannot be changed dynamically – Tasos Aug 19 '16 at 11:47
  • That's why i save the data from the server into database and then use hashmap..but my concern is that there may be possible that, i call tell the system to pick the values from x file and then at run time when i need, i will change that file – user3586231 Aug 19 '16 at 11:49
  • Use an array to store the data instead – Tasos Aug 19 '16 at 11:50
  • You solution is fine, why do you want to improve it? Is there a performance issue? – r3flss ExlUtr Aug 19 '16 at 12:06
  • Actually in ios they directly replace there string bundle file or they can refer string from a separate file and at run time they directly replace that file. so for them there is no change in the code. but for me, i need to shift setText code from xml to java code that is the problem for me – user3586231 Aug 19 '16 at 12:12

2 Answers2

2

Solution to your problem is make use of either Shared Preferences or Local Database.

Updating String.xml is not an good programming practice.

Shared Preferences is best solution to your problem and it is easy to use.

Shared Preferences Example

Community
  • 1
  • 1
Dnyanesh
  • 331
  • 3
  • 12
0

I think you are implementing right way except using hashmap. If data is large or grow in future it will slow down your app. You can use array and get string by directly accessing its index. Thanks.

Ramit
  • 416
  • 3
  • 8
  • But, searching in hash-map is faster than Array-list. – user3586231 Aug 19 '16 at 12:16
  • Please share some link. In array you can directly access element by using index, but not in hash-map. – Ramit Aug 19 '16 at 12:20
  • Ok, let me explain. Its your array so you do not need to search. you know index so can directly access element by its position and use it. I mean by using this approach you will improve performance for long time. Hope I explained. – Ramit Aug 19 '16 at 12:22
  • We do not know the index of item, because data is in from of key-value pair. – user3586231 Aug 19 '16 at 12:26
  • Then its fine, but think about this solution. It will improve performance it you can get indexed based data. In my app I used this approach earlier. – Ramit Aug 19 '16 at 12:30