How can I make base url dynamically in Appconstants class

风流意气都作罢 提交于 2019-12-25 17:19:47

问题


I have an existing old project where only one base URL is defined statically in app constant class. Now I need to implement a spinner in login activity which have 3 spinner value and each value carry one base URL statically.So when user select value from spinner it will access base URL and logging accordingly.Now my question is can I change base URL programmatically in App constant class. so that i do not need to change entire code or make a setting class.


回答1:


As per my understanding you need to implement a spinner in an existing project which is having 3 static value and each value carry a different path for logging.

First thing as per my understanding you can't make Base URL dynamically because it's constant class.

Now coming to your point if I understand you correctly, you can get URL on spinner item select in logging activity and if logging result is success then save URL value in Sharedpreference so that you can get this value in all your activity from Sharedpreference.

Remember this will get you only one path.




回答2:


If i undrestand you correctly, you want to modify an existing or add a new variable, that was declared as final static ? With reflection you can modify constants also.



来源:https://stackoverflow.com/questions/53741479/how-can-i-make-base-url-dynamically-in-appconstants-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!