Issue
I had pretty massive string array defined in XML; For example
<string-array name="Descriptions">
<item>A good raiding strategy is to fill your Army Camp with Giants and Archers; together they can easily wipe out a base. Use the Giants to distract all the Defensive Towers while the Archers take everything down.\nAt the beginning of a Raid, send in several Giants closest to the Mortar(s)/Wizard Tower(s). As soon as the Mortar hits the Giants, send in the necessary number of Wall Breakers to help the Giants break through the walls. Once the Mortar(s) and Wizard Tower(s) are destroyed, you can send in swarms of lower hit point Troops such as Goblins and Archers.\nGiants have a lot of health but are slow and have low attack power, so use them in groups.\nGiants are weak against many defenses grouped together.\nYou can use Giants as a cheap meat shield while deploying other, higher damaging troops to destroy buildings.\nAnother strategy is to send many Giants with one or more Healers. Be wary of Air Defenses and other anti-air towers, however, as Healers are very weak and have many vulnerabilities. \nIn general, Giants make better distracting troops than Barbarians due to their much higher health. Because of this they are less vulnerable to Mortar fire and other splash damage, and are much harder to kill.\nGiants ignore defensive troops (Clan Castle Troops, Barbarian King and Archer Queen) while defensive buildings can be targeted. Be sure to eliminate defensive troops to protect Giants.</item>
<item>A good raiding strategy is to fill your Army Camp with Giants and Archers; together they can easily wipe out a base. Use the Giants to distract all the Defensive Towers while the Archers take everything down.\nAt the beginning of a Raid, send in several Giants closest to the Mortar(s)/Wizard Tower(s). As soon as the Mortar hits the Giants, send in the necessary number of Wall Breakers to help the Giants break through the walls. Once the Mortar(s) and Wizard Tower(s) are destroyed, you can send in swarms of lower hit point Troops such as Goblins and Archers.\nGiants have a lot of health but are slow and have low attack power, so use them in groups.\nGiants are weak against many defenses grouped together.\nYou can use Giants as a cheap meat shield while deploying other, higher damaging troops to destroy buildings.\nAnother strategy is to send many Giants with one or more Healers. Be wary of Air Defenses and other anti-air towers, however, as Healers are very weak and have many vulnerabilities. \nIn general, Giants make better distracting troops than Barbarians due to their much higher health. Because of this they are less vulnerable to Mortar fire and other splash damage, and are much harder to kill.\nGiants ignore defensive troops (Clan Castle Troops, Barbarian King and Archer Queen) while defensive buildings can be targeted. Be sure to eliminate defensive troops to protect Giants.</item>
<item>A good raiding strategy is to fill your Army Camp with Giants and Archers; together they can easily wipe out a base. Use the Giants to distract all the Defensive Towers while the Archers take everything down.\nAt the beginning of a Raid, send in several Giants closest to the Mortar(s)/Wizard Tower(s). As soon as the Mortar hits the Giants, send in the necessary number of Wall Breakers to help the Giants break through the walls. Once the Mortar(s) and Wizard Tower(s) are destroyed, you can send in swarms of lower hit point Troops such as Goblins and Archers.\nGiants have a lot of health but are slow and have low attack power, so use them in groups.\nGiants are weak against many defenses grouped together.\nYou can use Giants as a cheap meat shield while deploying other, higher damaging troops to destroy buildings.\nAnother strategy is to send many Giants with one or more Healers. Be wary of Air Defenses and other anti-air towers, however, as Healers are very weak and have many vulnerabilities. \nIn general, Giants make better distracting troops than Barbarians due to their much higher health. Because of this they are less vulnerable to Mortar fire and other splash damage, and are much harder to kill.\nGiants ignore defensive troops (Clan Castle Troops, Barbarian King and Archer Queen) while defensive buildings can be targeted. Be sure to eliminate defensive troops to protect Giants.</item>
Similar to example i had massive strings in my array and nearly 250 such string elements in the ARRAY. But i need to load only one item in to my android project, is it possible to do that.
I know, I can do
String[] k=getResources().getStringArray(R.array.Descriptions);
String Required=k[10];
But it consumes lot of memory because i am loading ton of waste. so i need to load only single item (Suppose i need to load just the 10th element) from that array in to my project to make it more efficient.
I am preparing a dynamic app so i need to load different strings from that array depending on what user wants.
Is there any way to do that, Thankyou
Solution
I think you are talking about resource
xml file, right? If I am not right, please ignore my answer at all.
If I am right, the answers suggested for now won't help you. The reason is because resource files are not packaged within the apk
file. They are prebuilt to a binary format so you cannot query them. My suggestion is to reconsider the approach with the resource files but use local database (SQLite). This way the string that you will load in the memory will be only those you query the database for.
Another approach (if you still want to use the xml format) is to store it as an asset
instead of a resource
file. Assets are delivered as they are within the apk
so the approaches with the SaxParser
or the XPathApis
will be useful.
Hope this was useful for you and helped you solve the problem :)
Answered By - Kiril Aleksandrov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.