android programming: how to deal with multiple strings.xml in android studio(error:duplicate resources!) -


this question has answer here:

well problem want create 2 strings.xml each contaniing different text , want read these texts different activities getting 1 error(help me please).by way tried create new resourse file named strings2.xml...here error:

error:execution failed task ':app:mergedebugresources'.

[string/action_settings] c:\users\dell\androidstudioprojects\testscrollview\app\src\main\res\values\strings.xml [string/action_settings] c:\users\dell\androidstudioprojects\testscrollview\app\src\main\res\values\strings2.xml: error: duplicate resources [string/app_name] c:\users\dell\androidstudioprojects\testscrollview\app\src\main\res\values\strings.xml [string/app_name] c:\users\dell\androidstudioprojects\testscrollview\app\src\main\res\values\strings2.xml: error: duplicate resources

if says action_settings or app_name defined in both, pretty sure is. :-) why need 2 string xmls in first place? no matter activity call them from, strings can go one. if want differentiate strings (not compiler yourself), use different something_ prefixes.

to put perspective, activity more or less window in other operating systems. have one application can have several pages or windows or activities, whichever name it. resources (strings, layouts, drawables, menus, etc) belong application, not 1 of activities. so, activity in application, refer same strings, same resources. inside activity there helper function allows string directly, without calling through getresources() because it's such needed operation program same in both cases:

getresources().getstring(r.string.xxx) getstring(r.string.xxx) getresources().getdrawable(r.drawable.xxx) 

so, if have string called actions_settings:

<resources xmlns:tools="http://schemas.android.com/tools">   ...   <string name="actions_settings">...........</string>   ... </resources> 

you refer with:

getstring(r.string.actions_settings) 

no matter of app's activities you're in.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -