5

I am just starting in Android programming. I have an App that gives progoses based on mathematical methods of stock papers and warns when a stock paper is going to rise or fall. I have a Depot Class that contains a list of papers that are being watched. My Question now is what is the best and hopefully easiest way to store the data.

As I said my depot has an ArrayList of my Stock Paper Class. The User can add and remove to this. My paper Class has the following Values which should all be saved:

protected String Bezeichnung;
protected String WKN;
protected String ISIN;
protected String Typ;
protected String Schwerpunkt;
protected String Domizil;
protected String KAG;
protected Date Stand;
protected List<History_Entry> Historie;
protected Date Startdatum;
protected Date Enddatum;
protected int Durchschnitt1 = 200;
protected int Durchschnitt2 = 38;

The Tricky thing is the Historie Value. It contains all the historical Values of the StockPaper. It is an ArrayList with the Class History_Entry. History_Entry basicly just has a double Value with the Value and the corresponding date. Further it has the two Average Values but i can recalculate those at the beginning.

My Idea is to establish a Database that contains all the historical Values. And a Database that contains the Stock Paper Name and all the other Values from the Paper class.

I hope I am not to far off, but i am happy about anything new to learn.

  • I would suggest reading this in the Android Documentation. http://developer.android.com/training/basics/data-storage/index.html – Tristan May 05 '15 at 21:35
  • I read that, and because of it i came to the idea with the two database. I just wanted to get another idea or a "yes thats a good idea" – Carsten Berensmeier May 05 '15 at 21:42
  • No, don't use two databases. My first thought would be a StockPaper table and a History table. Every time you get a value for a paper, add it to the History table with a timestamp. When you want to know the current value, select the row from the History table with the correct StockPaper foreign key value and the most recent timestamp. – nasch May 05 '15 at 22:05

2 Answers2

3

Solution for you depends how big your data is and what you do with it.

Is it big? Do you search a lot by keys? Do you do aggregation, filtering, selection? If one of answers is "yes" then you need database approach.

If "No" then you can use any simple approach. I see all your data is String or convertible to String. You may simply save file with rows as your records and later read it and parse with split function. That's few lines of code.

Another approach is serialization All your data - String, double and ArrayList are serializable. Simply serialize/deserialize to local file. There a lot of examples or tutorials how to do simple serialization.

Alex
  • 4,457
  • 2
  • 20
  • 59
  • My Paper Class is already Serializable because i needed it to pass it between activitys. Thanks for the idea, Im gonna try it. – Carsten Berensmeier May 06 '15 at 07:30
  • You can attach it to intent which you use to interact between activities then. No need for file at all. – Alex May 06 '15 at 12:31
  • I must save it to a file because I want to keep the data after shutting down or restarting the app. I will report how the serialization works for me, but I had to fix a few things before I can start on it. But thanks already for the advices – Carsten Berensmeier May 06 '15 at 22:19
0

You have a few different options to save data in Android such as...

If you want to save your data to a remote database there a lot of tutorials online, check out this post.

Community
  • 1
  • 1
ctapp1
  • 556
  • 1
  • 5
  • 19