2014년 12월 8일 월요일

storing database among different screen

im a new hand learning ai2 recently,
my question is 
when I initialize a variable on screen 1
let's say , for grabbing the current time and display in a label
and I want to do this too on screen 2
do I have to initialize this variable again on screen 2 ?
is there a way that all screens share the same code ?
if so 
if I build a tiny DB component on screen 1
will screen 2 be able to catch the data stored in the tiny DB ?



Yes, a TinyDB is persistent.  Global variables only apply to the screen in which they are declared.

An app can only have ONE TinyDB... you can have one on every screen, and you can call them whatever you want, but they will all reference the SAME database...

So, save the data on screen1, retrieve it and use it on Screen2.



Regarding  
when I initialize a variable on screen 1
let's say , for grabbing the current time and display in a label
and I want to do this too on screen 2
do I have to initialize this variable again on screen 2 ?

Yes, and if you want the infor from screen 1 you have to pass that as a string or using TinyDB

Regarding
is there a way that all screens share the same code ?
if so 
if I build a tiny DB component on screen 1
will screen 2 be able to catch the data stored in the tiny DB ?

You place a TinyDB component on each of screen1 and screen2.     If you saved the data with a tag  on screen1 , you can read that same tag on screen2.
For instance the tag could be  Name   and you save  steve in that tag, go to screen 2 and recall the tag called Name   with code on that screen and you will find it will be   steve .

Generally, with AI2 you can not pass information between screens easily.  Each screen is, in effect, a separate app.  What global variables you have on other screens have to be 'duplicated' on successive screens and data passed to them with a TinyDB    or using  open another screen with start value ....etc.     Usually the second method is only good for a single value, but also will allow you to pass a string list.



hi there another steve XD



thank you very much :P


댓글 없음:

댓글 쓰기