0

I'm currently creating my first android app and I've a simple class 'Player' I want to save a few instances (a dozen or two) of that consist of 5 ints. All I wish to use them for is for the user to be able to save and load players.

I'm currently a bit bewildered as to how to do this as googling and searching this site returns Parcelable, Serializable, JSON, Externalizable, SQL, Simple XML, shared preferences and many more techniques all of which have pros and cons and look quite complex to work given they may be slow or might not work or not be suited to the simplicity of what I wish to do.

What approach of compression and storage should I be taking? Thanks

1
  • Edited my answer and add an working project. Please Let me know if it works. If it's ok for you vote up & accept the answer. :p Commented Apr 18, 2012 at 6:59

2 Answers 2

1

If you want easier solution then go with JSON or SharedPreferences. Easier to parse and easier to store.

Here is an example code I've uploaded for you. ObjectSavingTest

Sign up to request clarification or add additional context in comments.

4 Comments

Shared preferences can't store objects can they?
Create a JSON object and store as String in SharedPreferences ;)
Is there anywhere you can point me to showing how to do this? I've been trying for 2weeks and it isn't easy :p I'm using GSON and I'm trying to store an ArrayList in sharedPreferences.
Edited my answer and add an working project. Please Let me know if it works. If it's ok for you vote up & accept the answer. :p
1

I think you can create a SQLite database with 12 rows and 5 columns.. for 5 integers in your class.. and rows for your player names..

1 Comment

This was my original plan but it seemed a bit excessive as I will never sort or organize the data and I will only ever need to load the Player as a whole and not certain aspects of player. Would it be slower than JSON/Shared Preferences?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.