# Stored Variable

**URL:** <https://community.thunkable.com/t/stored-variable/2372465>\
**Category:** Questions about Thunkable X\
**Created:** [April 14, 2023, 1:31pm UTC](https://community.thunkable.com/t/stored-variable/2372465 "2023-04-14T13:31:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![twiki.like.itqinz6](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@twiki.like.itqinz6](https://community.thunkable.com/u/twiki.like.itqinz6)\
**Post date:** [April 14, 2023, 1:31pm UTC](https://community.thunkable.com/t/stored-variable/2372465/1 "2023-04-14T13:31:24Z")

</div>

I’m looking to store a variable between app sessions, so this seems like the perfect thing.

So in my block I initalise the variable, the app then does something and sets this to a text value, all good.

However, when I refresh the test app (using live view), it of course just reinitialises the variable back to null as it loads and doesn’t “store” anything.

Is this just a consequence of testing using the live preview or am I missing something? Does a “real” app know that the variable already exists and therefore doesn’t reinitialise it?

---

<div class="post-metadata">

**Author:** ![twiki.like.itqinz6](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@twiki.like.itqinz6](https://community.thunkable.com/u/twiki.like.itqinz6)\
**Post date:** [April 16, 2023, 1:58pm UTC](https://community.thunkable.com/t/stored-variable/2372465/2 "2023-04-16T13:58:16Z")

</div>

Yeah - even when the app is created - this value is being initialised when the app starts and doesn’t get remembered between app starts.  
So how are you supposed to create a persistent variable which doesn’t re=initialise when you start the app.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [April 16, 2023, 3:12pm UTC](https://community.thunkable.com/t/stored-variable/2372465/3 "2023-04-16T15:12:43Z")

</div>

If you use a _stored_ variable, it will keep its value between sessions.

Just make sure to check if the stored variable is equal to null when the screen opens. If so, set it to a starting value (such as an empty string “” or zero).

It’s best to test this on a mobile device.

---

<div class="post-metadata">

**Author:** ![twiki.like.itqinz6](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@twiki.like.itqinz6](https://community.thunkable.com/u/twiki.like.itqinz6)\
**Post date:** [April 16, 2023, 3:26pm UTC](https://community.thunkable.com/t/stored-variable/2372465/4 "2023-04-16T15:26:18Z")

</div>

This is what I have:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/f/8f0ab640312056077dd14e633bdbfa8dd77576c5.png)

So it should be initialising as “null” I believe. But doesn’t persist between sessions. If I set this vCurrentJob variable as something in the app - then close the app down, and relaunch it. txtCurrentJob.text is just blank.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [April 16, 2023, 7:08pm UTC](https://community.thunkable.com/t/stored-variable/2372465/5 "2023-04-16T19:08:34Z")

</div>

Those blocks should work **but** you need to do what I suggested and check for a null value.

This is a screenshot I found online but it shows an example of this:

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/b/ebb6011e4e8d6a17351cb67b8dae5ee4eccc600d.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)\
**Post date:** [July 15, 2023, 7:08pm UTC](https://community.thunkable.com/t/stored-variable/2372465/6 "2023-07-15T19:08:47Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
