Types of data storage

Put your problem here if it does not fit any of the other categories.

Types of data storage

Postby svynistodas » Thu Mar 08, 2012 5:51 pm

Hi. I have to create app which one take data from xml file. First of all I have to generate menu. If I click menu with id 102, then open new intent with page id 102.
already I know how to parse xml file. How I should to save data is application ? in sqlite DB, or in List, or ArrayList?


one xml data file
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>

   <menu>
      <li>
         <id>101</id>
         <level>1</level>
         <parent_id>0</parent_id>
         <type>M</type>
         <title>Menu no 1</title>
      </li>
      <li>
         <id>102</id>
         <level>1</level>
         <parent_id>0</parent_id>
         <type>M</type>
         <title>Menu no 2</title>
      </li>   
      <li>
         <id>103</id>
         <level>1</level>
         <parent_id>0</parent_id>
         <type>M</type>
         <title>Menu no 3</title>
      </li>
   </menu>
   
<pages>
   <page>
      <id>101</id>
      <level>1</level>
      <parent_id>0</parent_id>
      <type>N</type>
      <title> title 1</title>
      <content> fool content </content>   
   </page>   
   <page>
      <id>102</id>
      <level>1</level>
      <parent_id>0</parent_id>
      <type>N</type>
      <title> title 2</title>
      <content> fool content</content>   
   </page>      
   <page>
      <id>103</id>
      <level>1</level>
      <parent_id>0</parent_id>
      <type>N</type>
      <title> title 2</title>
      <content> fool content</content>   
   </page>      
</pages>
svynistodas
Freshman
Freshman
 
Posts: 6
Joined: Thu Mar 08, 2012 5:14 pm

Top

Re: Types of data storage

Postby Phyll » Thu Mar 08, 2012 6:54 pm

Hi svynistodas,

Is this something that is always the same and should be stored with the program or does it change after the program is operating?

If it does not change, you can store it in the res directory by making another directory called xml to keep such things in. You can then just refer to them like any other resource. That's what I do and they look like this:

Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<menu>
    <item name= "New\n  Message   " icon="and_add" id="1" />
    <item name="Edit\n  Messages  " icon="and_edit" id="2" />
    <item name="Edit\n Recipients " icon="and_edit" id="3" />
    <item name=      "    Help    " icon="and_help" id="4" />   
</menu>


If you need to store them after they are made or loaded from somewhere or something, after the program is started and ran for a while, you could keep them in local files or preferences. I guess if I were going to keep them in SQLite I wouldn't bother putting them into xml.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Types of data storage

Postby svynistodas » Thu Mar 08, 2012 9:25 pm

No you don't understood me.
xml file data will be reached by link. So if owner update his page, then xml also will be updated. I think that program had to download xml data on start or by pressing "refresh" button.
So it will be good if I will save data is SQLite ?
svynistodas
Freshman
Freshman
 
Posts: 6
Joined: Thu Mar 08, 2012 5:14 pm

Re: Types of data storage

Postby Phyll » Thu Mar 08, 2012 11:05 pm

Hi svynistodas,

That's why I asked. Is this something that is always the same and should be stored with the program or does it change after the program is operating?

Apparently the program can change it.

I would just store it in a local file. You may want to store it in a way that would allow you to get it back easier than an xml parser but that is up to you and your app design. But generally it is pretty easy to download something to a file. A local file is one that is stored in /data/data/com.your.package.name folder along with other things your app needs.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Types of data storage

Postby nuetronprotron » Fri Mar 09, 2012 5:28 am

Hi svynistodas,
correct me if i am wrong,I hope that the response xml is varied or changes every time then i think this would be good thing to try is
As per the structure try to create a pojo for the structure and access from that pojo(creating a class for the xml structure to store or parse into that class this class is called as pojo),by this you do not want to request the data every time of refreshing,it is better than storing in the file because you have to structure the string very carefully to store in the file.Remember that if the activity is ended then pojo will no longer will have hold the data.

If you want to store the particular xml for once and if you want to use this forever then go and store in a file.Note:try to design the string how you will store in the string so that it should not become difficult to you to restore properly.

For second case you can store in sqlite db and try to access it from there,it is not recommended for the first case.

hope this will help you
nuetronprotron
Developer
Developer
 
Posts: 37
Joined: Tue Jan 10, 2012 10:22 am

Re: Types of data storage

Postby svynistodas » Fri Mar 09, 2012 2:20 pm

ok. xml file will change after the program is operating.
But you don't understood me anyway. Maybe I write wrong title :D
Imagine that: is the web page with news. So my application have to get fresh news.
svynistodas
Freshman
Freshman
 
Posts: 6
Joined: Thu Mar 08, 2012 5:14 pm

Top

Re: Types of data storage

Postby Phyll » Fri Mar 09, 2012 3:26 pm

Hi svynistodas,

Are we maybe talking about an RSS feed?

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Types of data storage

Postby svynistodas » Fri Mar 09, 2012 3:36 pm

some thing like RSS, but in xml file will be not only news.
svynistodas
Freshman
Freshman
 
Posts: 6
Joined: Thu Mar 08, 2012 5:14 pm

Re: Types of data storage

Postby Phyll » Fri Mar 09, 2012 4:04 pm

Hi svynistodas,

So I am trying to understand what your question is. Between the two of us (nuetronprotron and I) we have gone over a number of ways of storing data and the reasons behind it. If that is not answering your question, what are you having trouble with?

Generally in an RSS feed, the information is displayed in a list and if an item in the list is selected, it is displayed.

Is that the general idea of what you would like to do?

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Types of data storage

Postby svynistodas » Fri Mar 09, 2012 4:14 pm

Yes.

Generally in an RSS feed, the information is displayed in a list and if an item in the list is selected, it is displayed.

Is that the general idea of what you would like to do?
svynistodas
Freshman
Freshman
 
Posts: 6
Joined: Thu Mar 08, 2012 5:14 pm

Re: Types of data storage

Postby Phyll » Fri Mar 09, 2012 4:28 pm

Hi svynistodas,

If it would help any, here is my favorite tutorial about RSS readers:

http://www.ibm.com/developerworks/xml/t ... ndroidrss/

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Types of data storage

Postby svynistodas » Fri Mar 09, 2012 4:39 pm

thanks to all :)
svynistodas
Freshman
Freshman
 
Posts: 6
Joined: Thu Mar 08, 2012 5:14 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 37 guests