Ways to save a lot of text and images in Android - android

Short version at the bottom
I'm working on an android app for a computer game, Heroes Of Newerth. A part of the apps functionality is to list all the heroes in the game. Each hero has:
a short description
a few stats(faction and primary attribute)
an icon
4 spells, which also has:
a short description
a few stats (mana cost, difference in ranks, etc.)
an icon.
There are approximately 110 heroes, which means I have about 500 sets of descriptions and stats.
I made a working version of the app. I downloaded all the images and put them in the drawable folder (note, this was 500 images), and created a Hero Enum which stored name, faction and primary attribute. Obviously, this was a bad idea, as it was horrible looking, and hard to extend to storing the rest of the data.
I have though about using a database, but as I don't have any experience with databases, I'm not really sure as how to do this, especially in Android. I looked it up, and it seems I need to initialize the database on the phone, which means I have to get that data from somewhere - which, again, means I'm back to square one.
I have never worked with this much data in a programming project, and have no idea for how to save it all. As if this is not enough, the game developer, S2 Games, releases new heroes with only weeks in between. As I wouldn't want to update one of my apps every other week, I want the app to be able to update itself with the new data. The best way I see this in my head is you download the app, either with a database of the current heroes, or without any, and the app checks each friday(patches are released on fridays) if the app is up to date. If not, update the database(with text and icons).
Short version
I want to save a few thousand strings, some formated in a special way(unless I can to this afterwards), and about 500 icons. How should I approach this?
Note: I know this was a really bad question, with a horrible structure, but I've been stuck here for weeks, and I couldn't get myself to ask someone, I really need help here!

well it's very recommended that you use sql and databases . you could go to w3schools for the basics .
if you don't want to use DB (or don't have time) , you can store all the data in xml files , and then parse them all . the images should never be part of the DB (or the xml files) , since they cause a bad performance while moving between items.put their names/paths instead .
if the images take a lot of space , consider using google expansion library .

Related

Gaming Databases Theory

I'd like some help with data management theory for Android games. I'm developing a role playing game and I'd like the character to be customisable with different outfits: hats, power armour weapons, etc. The player can buy these from a shop and then choose to wear them or change outfit but keep the item in a 'wardrobe ' to wear a different time.
So far, most of my data has been saved via SharedPreferences. However I know this is unsustainable for 100 different types items the player can buy and then save to wear on a different occasion.
Through research, I am beginning to believe SQLite would be best in Android Studio. Would anyone agree with this or have a better suggestion?
I understand SQLite would allow me to have the data pre-loaded with a 'not bought' status. When 'bought' this status would change and the player could 'wear' or 'not wear' the clothing.
If SQLite is best, how do I go about it best? Also, does SQLite take a long time to load and therefore slow the opening of an activity down? Could you combine SQLite with SharedPreferences to remember the latest selected outfit?
Finally, is SQLite what other apps use to store data (especially if built through Android Studio)? How do games such as Clash of Clans or Tapped Out save such data as owned items or location on a grid?
Thank you for even partial support or theory.
TL;DR Yes, SQLite is fine.
Let me answer this question from Clean Code perspective.
Answer below could be too complicated for the beginners, but I hope it will be helpful in the long term.
I think your actual question is - how do I save the stuff which I need later on? Well, in most cases it doesn't really matter how you will store the data as long as you can reliably read it back later on. So, instead of worrying about "should I use X?", I would instead start with defining the interface of the class which will solve your problem.
For instance, let's call it PlayerItemsRepository and it be responsible for saving your stuff and reading it back. How? I don't know yet, we can figure it out later on.
public interface PlayerItemsRepository {
void saveItems(List<Item> items);
List<Item> readItems();
}
OK, now we can integrate SQLite? Let's wait with that for a little - it's a bit of a boilerplate code to work with SQLite, so how about we will create some simple implementation of this interface which would just serialize the list and save it to file (assuming your Item is Serializable). Or if we are too lazy even for that, how about we'll just convert our List<Item> to JSON and save it to SharedPreferences (with something like Gson library which is stupid-simple to use)?
Now, if you're saving just 100 items (which is a rather small amount) I am pretty sure all those "easy" solutions will just work fine and you will be able to just forget about the whole story.
If you will start to run into necessity to have some sort of relational model, or performance of serialization is not acceptable to you, or you need a faster and more complicated search mechanics - then you might consider switching to SQlite. It is pretty common for Android applications, although (as I mentioned before) API is somewhat cumbersome and requires you to write quite some boilerplate - which is in the end require you to spend more time on it and it might be not worth the time for a small data set.

Android, storing big number of small images linked to database

I have been asked to create a tiny android app.
In everyday work i code for .NET and I have no experience connected with Android, but as it is a really small app I guess it's going to be a good experience rather than something hard.
The core of the app would be a small database (probably XML, unless somebody suggest better solution) that would contain categories, names of the institutions assigned with each category and logo (not very high resolution I guess a single file would be <100kB) of the institution.
The database also would not be very big - I expect not more than 1000 records in total. The DB has to be totally offline and local, it cannot require Internet access when operating.
The model I assume would be to ship new version of the application when the database changes (which is not going to be very frequent).
What is the best way to deal with these requirements?
My first idea was to create an XML file that would contain the records and link to the image. The XML and all the images linked to it would be stored in single file (preferably zip) that would be stored in app resources. This is very good as it is going to be very easy to update the database.
The second idea that somebody suggested me would be to use SQLite and store images in BLOB. In general I have read that it isn't a good idea to store images in database directly, and I am afraid if it's going to be possible to meet all requirements mentioned above.
Mostly I have no idea how to update the database easily and attach it to new version of application.
Any suggestions?
I would be grateful for any response.
I wouldn't go about using XML to save your data and by no means zip anything.
I think your way of thinking is ok, but you're making things really complicated for yourself.
Seeing as you're used to .NET I suppose you're also pretty confident with SQL, so I'd suggest you have a look at how to use the built-in SQLite database in Android.
If you would go the XML route you'd have to serialize and de-serialize the XML file over and over again and then parse the XML. Ok you don't have a lot of data, but searching inside an XML file with at least 1000 nodes would be slow in comparison to the performance of a database.
Also upgrading an existing SQLite database is not that hard - Android has methods for that (onUpgrade coming from the SQLiteOpenHelper).
As to saving images I'm assuming that you won't fetch new pictures from the Internet, so it would be best just to store them in the drawable folder of your app (be mindful of different screensizes) and then reading them into an ImageView when needed. To figure out what image should go for what institution I would store either the image name of each image in the SQLite database or store the resource id for each image in the database - for instance R.drawable.myawesomepictureformyinstitution.
I know my answer is somewhat "superficial", but your question is also somewhat "broad" and hard to answer without me actually writing most of the code, and that's not my intention ;-)
Hope this helps - let me know if anything is unclear.

Localization of external data and scalability

When a user finishes a workout in my app the workout is stored on their device with the name of the exercise together with an ID and some other fields.
Now that Im localizing the app Ive run into the problem that Ill have to "manually" translate the exercise names to the localized language. This brings up the question of scalability. When my app is available in many more languages Id like a system which is lightweight and so that minimal amount of work has to be done to translate exercises.
My most robust idea this far is:
Using the ID of each exercise to set its data when loading it. Name, instructions and all other fields will then be loaded in the localized language upon launch. The database will update itself when it detects that a new language is available. This system could be used throughout the app to translate schedules and all other data containing exercises as well. This system is also good when downloading images for the exercises from my future server.
Now on paper this seems very good. But I dont want to implement it without asking here since I didnt find any good resources on how to implement such a thing.
Thanks in advance.
Reading your question again, my understanding is that you store the actual String of the exercise name. Why not just store the int pointing to a string.xml value, like for instance R.string.situps. This way it is independent of language and, when reloaded, the correct language will be chosen.
Perhaps this is what you mean with ID?
In that case I believe that to be a good idea :)

Using a humongous database in an android APP

I am trying to use a database for my application which needs a list of all the words in Arabic language, unfortunately this database is very large in size, more than 200 MB, I've seen that the only solution for such a problem is using a web service or having my database online and download it on first use which is not practical in my case since this is a game and the user can play it while he's disconnected, plus the download size will be large and it will use alot of space on his phone. I couldn't find a way to make the size of my DB reasonable.
My question is if there is a way to shrink the size of the database knowing that all the data stored in it is of the type text.
I've noticed that the keyboard in my phone has an auto-complete feature, where is it getting the list of valid words from? Can i use it for my application?
You'll want to store your words in a prefix tree (or trie). It is a space-efficient structure for this kind of data.
For more info, see: https://gamedev.stackexchange.com/questions/4142/best-way-to-store-a-word-list-in-java-android
your database might have so much extra information included, for example grammar, inflections, comments etc. If this is the case, then re-create your database with only the limited data/columns you need to be used inside phone.

Design recommendation for an android app

I am planning to develop an android app. This will be my first app if I upload it.
I have pretty good idea , what my app should do , But I lack design skills and have no one to ask around. So asking android experts here.
App objective : very simple , have a listview with proper titles , on clicking it(list items) , it will show an appropriate image.
Approaches which I thought.
Have a relation between title(or a tag) and image names and have all images in drawable folder. whenever list item is clicked, point to appropriate drawable and show it.
Pros: easy to do it.
Cons: Seems like not scalable.
Store id,title,drawable reference( drawable ids ) in database and use it.
Pros: (different approach than prev one)
Cons: Creating database is painful if number of items are more !
I want some guidance in this approach, how people create huge database(for android) which
works offline.
Have a server, database there , provide an API for my app , whenever update is pressed ,
local database is synced !
Pros: Seems like scalable approach.
Cons: Hell lot of work for a simple app !
Should one consider storing images in database as BLOB data ?
Or none of these approach is correct.
Any advice will be helpful.
How many images are we talking about? Is this set of images static? If so, I'd go with the first option. Especially if these images are small in size.
If you have to modify the set of images (add/remove images from it somehow), and/or the images are huge I'd use the SD card solution too.
I would go with first option with storing the images on the SD card in a folder.

Categories

Resources