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?

7
  • which kind of dynamic string values will come from server? Commented Aug 19, 2016 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 Commented Aug 19, 2016 at 11:43
  • i dont think you can do that. Those are hard coded and cannot be changed dynamically Commented Aug 19, 2016 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 Commented Aug 19, 2016 at 11:49
  • Use an array to store the data instead Commented Aug 19, 2016 at 11:50

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

3 Comments

Updating string.xml is impossible at runtime
But it is ease to update the database instead of share preference..and with the help of query it is easy to update a particular string resource.
you cannot modify R.java File value please read about R.java File
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.

5 Comments

But, searching in hash-map is faster than Array-list.
Please share some link. In array you can directly access element by using index, but not in hash-map.
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.
We do not know the index of item, because data is in from of key-value pair.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.