Hello everyone! Welcome back to Kodular Free AIA. This is Hifza, and today we're learning one of the most useful components in Kodular: TinyDB.
Have you ever built an app, typed something in, closed it, and found that everything was gone when you opened it again? That happens because Kodular apps start fresh every time they run. Variables are not remembered. TinyDB fixes that. It saves small pieces of data on the phone so your app can remember them, even after a restart.
By the end of this tutorial you will know how to:
- Save text, numbers and lists with TinyDB
- Load saved data when the app opens
- Keep a user logged in so they don't need to log in every time
- Delete one value or clear everything (for a Logout button)
What is TinyDB in Kodular?
TinyDB is a non-visible component found in the Storage section of the Kodular designer. It stores data as tag–value pairs. Think of the tag as a label on a box and the value as what you put inside the box.
| Tag (label) | Value (data) |
|---|---|
| username | hifza |
| highscore | 250 |
| isLoggedIn | true |
Some important things to know:
- Data stays on the phone after the app is closed or the phone restarts.
- All screens of the same app can read the same TinyDB data, so it's a simple way to pass data between screens.
- One app cannot read another app's TinyDB.
- While testing with the Companion app, all your test apps share one TinyDB. This goes away once you build the APK, so don't panic if you see old test data during testing.
TinyDB Blocks Explained
Click TinyDB1 in the Blocks editor and you'll see these blocks:
- call TinyDB1.Store Value (tag, valueToStore): saves a value under a tag. If the tag already exists, the old value is replaced.
- call TinyDB1.Get Value (tag, valueIfTagNotThere): reads a value. If nothing is saved under that tag yet, it returns the value you put in valueIfTagNotThere. Always fill this in, usually with an empty text block or 0.
- call TinyDB1.Clear Tag (tag): deletes one saved value.
- call TinyDB1.Clear All: deletes everything saved in this TinyDB's namespace.
- call TinyDB1.Get Tags: returns a list of all saved tags. Handy for checking how many items you've saved.
- call TinyDB1.Get Entries: returns all saved data as a dictionary.
- Namespace property: the "folder" your data is saved in. The default is TinyDB1. Use different namespaces if you want separate stores, for example one for settings and one for scores.
Remember: blocks only run inside an event, like when Screen1.Initialize or when Button1.Click. A Store Value block floating on its own will do nothing.
Example 1: Save and Load a Name
Designer
- Add a TextBox (rename it TextBox_Name).
- Add a Button with text "Save" (rename it Button_Save).
- Add a Label (rename it Label_Welcome).
- From Storage, drag in a TinyDB.
Blocks
Saving:
when Button_Save.Click
call TinyDB1.Store Value
tag: "username"
valueToStore: TextBox_Name.Text
set Label_Welcome.Text to join("Welcome, ", TextBox_Name.Text)
Loading when the app opens:
when Screen1.Initialize
set Label_Welcome.Text to join("Welcome, ",
call TinyDB1.Get Value
tag: "username"
valueIfTagNotThere: "Guest")
Now type your name, tap Save, close the app completely and open it again. Your name is still there!
Example 2: Keep the User Logged In
This is the question beginners ask most on the Kodular community: "How do I make my app remember the user after the first login?" Here is the simple way.
We'll use two screens: Screen1 (login) and Home (the main app). If you don't have a login screen yet, grab our free Kodular Login and Register App AIA and add these blocks to it.
Step 1: Save the login
Inside your login success block (after checking the email and password are correct), add:
call TinyDB1.Store Value
tag: "isLoggedIn"
valueToStore: true
call TinyDB1.Store Value
tag: "userEmail"
valueToStore: TextBox_Email.Text
open another screen screenName: "Home"
Step 2: Skip the login screen next time
when Screen1.Initialize
if call TinyDB1.Get Value
tag: "isLoggedIn"
valueIfTagNotThere: false
then
open another screen screenName: "Home"
Now when a logged-in user opens the app, Screen1 sends them straight to Home.
Step 3: Show the user's email on Home
Add a TinyDB to the Home screen too (keep the same namespace, TinyDB1), then:
when Home.Initialize
set Label_User.Text to call TinyDB1.Get Value
tag: "userEmail"
valueIfTagNotThere: ""
Step 4: Logout button
when Button_Logout.Click
call TinyDB1.Clear Tag tag: "isLoggedIn"
call TinyDB1.Clear Tag tag: "userEmail"
open another screen screenName: "Screen1"
Use Clear Tag here instead of Clear All, so other saved things like settings or high scores are not deleted when the user logs out.
Example 3: Save a List
TinyDB can store whole lists, which is perfect for a to-do app, favourites, or a history screen.
when Button_Add.Click
initialize local items to call TinyDB1.Get Value
tag: "todoList"
valueIfTagNotThere: create empty list
add items to list list: items item: TextBox_Task.Text
call TinyDB1.Store Value
tag: "todoList"
valueToStore: items
set ListView1.Elements to items
And on Screen1.Initialize, set ListView1.Elements to the saved todoList (with create empty list as the default) so the list appears every time the app opens.
Common TinyDB Mistakes
- Different spelling of tags. "userName" and "username" are two different tags. Copy-paste your tag text blocks to avoid typos.
- Empty valueIfTagNotThere. If you leave it empty on the first run, your app may show errors or blank screens. Always give it a sensible default.
- Different namespaces on different screens. If Screen1 uses namespace TinyDB1 and Home uses MyData, Home won't see Screen1's data.
- Storing big data. TinyDB is for small things like settings, scores and login status. For images or large data, use a file or an online database like Firebase.
- Saving passwords as plain text. Don't store passwords in TinyDB. Save a login status or user ID instead. </
- Remembering login status
- Saving app settings (dark mode, language, sound on/off)
- High scores in games and quiz apps
- Showing an intro or welcome screen only on the first launch
- Small offline lists like notes or favourites
Download Free AIA:
The complete .aia source file for this Student Attendance App is free to download, including the full Blocks logic for the Present/Absent count feature described above.
ul>When Should You Use TinyDB?
For example, our Quiz Application in Kodular could use TinyDB to save the player's best score, and the Student Attendance App could use it to remember the teacher's class settings. Try adding it as practice!
Conclusion
TinyDB is the easiest way to make your Kodular app remember things. Learn just two blocks, Store Value and Get Value, and you can already save names, scores, settings and login status. Add Clear Tag for logout, and you've covered what most beginner apps need.
Download Free AIA:
If you have any questions, leave a comment below and we'll help you out. Don't forget to check our other Free AIA projects, and share this post with a friend who's learning Kodular!
.png)