the best solution to save data in android and ios

1,632 views
Skip to first unread message

Martin Guillermo Acosta

unread,
Aug 22, 2013, 8:52:11 AM8/22/13
to kivy-...@googlegroups.com
Hi guys, recently I finish a kivy application for android and now I'm thinking in improve the perfomance caching the data json that I'm getting from internet and use in my app.

What is the best solution to save this data json in android and ios? a file in sd or a with a database of the device?

Important: in my json I have some private information, so is complicated save the information in the sd because the user has directly and public access.

Sorry for my english, I wish you could help me!

Thanks!!

Mathieu Virbel

unread,
Aug 22, 2013, 3:59:37 PM8/22/13
to kivy-...@googlegroups.com
Hey Martin,

Yes you can safely save it in a json. Best is just to use
App.user_data_dir property for the directory:

from os.path import join

def on_pause(self):
fn = join(self.user_data_dir)
with open('state.json', 'w') as fd:
json.dump(self.yourstate, fd)

Or something like that :)

Mathieu

Le 22/08/2013 14:52, Martin Guillermo Acosta a �crit :
> --
> You received this message because you are subscribed to the Google
> Groups "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to kivy-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Martin Guillermo Acosta

unread,
Aug 22, 2013, 5:36:03 PM8/22/13
to kivy-...@googlegroups.com
Wow! Mathieu that is!!!! thanks man!!

Maybe you can help me with another thing, I'm learning about how create a new widget.

Do you know if exist an event to catch the after moment when the kv template is render?

For example I have this class:

class CustomButton(Button):
  
  def __init__(self, **kwargs):
    super(CustomButton, self).__init__(**kwargs)
    self.addMyName()

  def addMyName(self):
    self.text = 'Martin '+self.text

And in my kv template:

CustomButton:
  text: 'hello'

So what I thought is, when the widget is initialized render the widget as a button with the text:

'Martin hello'

but is not working, because the event __init__ obviously is called before the render and in that moment the property text don't has
anything, so...there is a way to catch the event before rendered and call the function addMyName?

Thanks :D!!!! with this....good by java for android, hello python+kivy+android!!!



El jueves, 22 de agosto de 2013 16:59:37 UTC-3, Mathieu Virbel escribió:
Hey Martin,

Yes you can safely save it in a json. Best is just to use
App.user_data_dir property for the directory:

    from os.path import join

    def on_pause(self):
        fn = join(self.user_data_dir)
        with open('state.json', 'w') as fd:
            json.dump(self.yourstate, fd)

Or something like that :)

Mathieu

Le 22/08/2013 14:52, Martin Guillermo Acosta a �crit :

Gabriel Pettier

unread,
Aug 22, 2013, 7:17:48 PM8/22/13
to kivy-...@googlegroups.com
You could use the clock:

def __init__(self, **kwargs):
super(CustomButton, self).__init__(**kwargs)
Clock.schedule_once(self.addMyName, 0) # executed next frame

def addMyName(self, *args):
self.text = 'Martin ' + self.text


It's not perfect though, as it assume that you add the widget to a
parent just after creating it, but i understand it's fine for your use
case, if it was different, i guess you would put that in on_parent.

cheers
> El jueves, 22 de agosto de 2013 16:59:37 UTC-3, Mathieu Virbel escribi�:
> >
> > Hey Martin,
> >
> > Yes you can safely save it in a json. Best is just to use
> > App.user_data_dir property for the directory:
> >
> > from os.path import join
> >
> > def on_pause(self):
> > fn = join(self.user_data_dir)
> > with open('state.json', 'w') as fd:
> > json.dump(self.yourstate, fd)
> >
> > Or something like that :)
> >
> > Mathieu
> >
> > Le 22/08/2013 14:52, Martin Guillermo Acosta a �crit :
> > > Hi guys, recently I finish a kivy application for android and now I'm
> > > thinking in improve the perfomance caching the data json that I'm
> > > getting from internet and use in my app.
> > >
> > > What is the best solution to save this data json in android and ios? a
> > > file in sd or a with a database of the device?
> > >
> > > Important: in my json I have some private information, so is complicated
> > > save the information in the sd because the user has directly and public
> > > access.
> > >
> > > Sorry for my english, I wish you could help me!
> > >
> > > Thanks!!
> > >
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Kivy users support" group.
> > > To unsubscribe from this group and stop receiving emails from it, send
> > > an email to kivy-users+...@googlegroups.com <javascript:>.
Reply all
Reply to author
Forward
0 new messages