where is the best place to save game progress? - android

I'm developing a quiz game and I want to save the progress... Actually I use sharedsettings, is easy and fast, but the user can delete program files and lose the progress. Same happens with a database. I should use a file? I'm only interesting to save a boolean for each question: "correct answered or not?"
Thank you!!

SharedSettings. And you're already using it. It's very difficult to save a user from his/herself. If it's on the device then it can be destroyed either stupidly or maliciously. And don't forget that everything is a file and there's nothing you can put on the device that will be hack/idiot proof.
The only way to get around this would be to store user settings off the device via something like a web service (and backing database.) But I would say that if you're using SharedSettings... you're OK. Leave it at that. I would only consider using an app-specific db if you expect the number of question you track to grow to a very large size and want more control over the data.

Where in code logic?
In general, it's best to save any UI preferences at onPause. Android design wants you to never have a "save" button, rather save constantly.
As far as at each question, i guess you would save after answering each question?

Related

What is the best way to save all high-scores of multiple levels in android?

I am writing a minesweeper application in android. It's got 3 difficulty modes and I want to save all the scores of all three difficulty modes. If I wanted to store just the high scores for all the modes, I could have done it with a SharedPreferences object but I want to store all the scores and display them to the player sorted by the time taken to solve or date on which it is solved.
I have thought of saving data in a file, or in a json file. I don't want to use SQLite databases because it's too much code.
I simply want to know if there is a better way to do this other than saving everything in a file (maybe in the assets).
There is a similar question but I don't think the accepted solution can be used to solve my problem.
You can use Firebase Database for that. The good thing with the database is that if you want your game to also display the leaderboards to others who are playing it, it shows in real-time. Simply add data when the game ends and filter the results based on the data. Hope this helped, heres a link to get you started here

Best way to save history for app

I want to write an android calculator app like the one on my android phone. It saves history for operations and by clicking a button it shows last operations. Now my question is what is the best way to save operations? Is it reasonable to save them to a file in internal storage or what?
There's some options..
1) Include a SQLite Database, as others mentioned. This makes storing lots of information really easy. You can find tutorials on how to include one properly in your project, and don't hvae to care for much more. You can then work with content providers to read and store data.
http://developer.android.com/guide/topics/providers/content-providers.html
2) SharedPreferences. If you just intend to store like the last, or the last 3 Operations, you can just use shared Preferences. This is way less overhead than adding a Database, if it is a small project, albeit you will have to keep your data structured yourself.
http://developer.android.com/reference/android/content/SharedPreferences.html
3) If you just want to store the users current session you can just Keep a Stack of the used operations. On undo, or however you call it, you would just pop the stack.
By implementing onSaveInstanceState and Parcelable you can make sure that no data is lost on rotation / low memory and such.
I personally would advise you without knowing more about your project to use plain java objects and storing the state. A calculater would in most cases not need persistent storage. If you really want to know what the user did 2 weeks ago, you should use a Database.
I would recommend you to use database(SQLite) for storing the data.
If you don't know more about SQLite in android have a look at these
tutorials.
I think database should be handy for history if more than one operations has to be stored else for one operation you can use shared preference.

Should small amounts of data be stored in a database in Android?

If I was creating an Android app that for example stored alarm clock times and information, would it be best to put that information in a database, write to file, or user preferences. I would only access that data to create the list of alarms and when editing a specific alarm.
Personally, the overhead of creating a database is overkill for this. Writing to a file, well, it depends, but it seems like this would be a good way to do it. I'm assuming that you don't know how many of them there will be. If it's a fixed small number, you could use preferences.
I tend to pick the easiest way that doesn't rely on anything else working correctly :)

Save everything of an activity

I've got an activity and I want to keep everything inside it (Bitmaps, texts, buttons..) so when the user restarts the phone and clicks on my app, everything is like the last time he used it.
Any idea?
I've been reading about the lifecycle of an application in Android, and i know the basics theoretically but I don't know how to implement it.
Thank you.
Actually, you don't need to do anything on objects such as Buttons and TextViews, since they do not change during your Activity's lifetime. When your application restarts, they just get recreated and they look the same anytime. Things that you want to save are possibly user inputs or downloaded files. If you have any of these, then I'd recommend learning this post, it describes different data storage mechanisms in Android. For different kinds of data you'll need different solutions, for example text inputs can be saved in SharedPreferences, but bitmaps should probably be saved in the file system. Hope this helps.
Maybe it is not the best solution, but you can try SharedPreferences and save different user data into different variables upon exiting.
When the app is restarted, read the values stored in the SharedPreferences and display these values in your respective views.
Other than SharedPreferences, you can also try out these various options according to the type of data you would want to persist!

Blocking access to my app's database

I need to block user access to my app's data stored in the SD card... like the images etc as they are crucial to my app's proper functioning and if deleted by mistake, will cause the application to function way different from what is expected of it. Is there any way to do so programmatically, like when I create this directory structure during my first run, lock the access to it to be only unlocked when the app runs?
Short answer... NO, it's not possible at all.
If it's that important, you could store all your data in a encrypted file. That way if it's deleted then you know it's all deleted and you have to start again. You also know that it's 'most likely' haven't been tampered with.
Most likely tho, the best solution is to handle errors better and become a more robust application.

Categories

Resources