Sharing a tinydb between apps

I made an app a long time ago to collect only work related contacts with job related data to simplify my work life. it works well.
I want to share the information with other apps I make, like a schedule app, or billing app so I can just click from a listpicker to get all the customer data all at once instead of retyping it all. (DRY... don't repeat yourself)
I have made sure the name of the database is the same, and also the namespace.... is there something else I need to do?

Hi, if I understand correctly, try and just go over your old app a few more times, maybe you missed a piece for your new apps.

I have tried that, also have made sure that I test on my chromebook and my phone, so i have two databases, one on each device. They both hold only the data I put into them on the device, and are not shared between devices. (That aspect comes later) For now I need one database on one device to share the data with two (possibly more) apps.

Even after compiling them both after check all the naming is exact, it still won't share

How about adding code to each app to upload its TinyDB to a common online spreadsheet or other database?

Ha ha, yes, I have tried that, and I will go back to that. I was having trouble formatting the data, but will get it eventually.
But for sharing a local database.... shouldn't it work?

Hmm. I notice that it shares the data while under construction, but after it's compiled, it creates a different instance of the DB.
for clarity, the original database is named 'Custard', the new app, for now, is called 'custard tart'
I can flip back and forth in AI, connected to my phone, and both apps, custard and custard tart will pull the same data. However, after compiling, custard creates a database with different data, and custard tart (so far) does not grab any data, the listpicker it should be in comes up blank

There is a sharing component for exporting text files, which I have not yet used.

I can post code to export TinyDB into a text file and import from a similar file.

People with more file experience can probably tell you how to transfer files across apps.

TinyDB_export_import.aia (5.9 KB)

According to the TinyDB docs, you can't access the database between different apps. This is because TinyDB stores the database privately.

I shall get into that, thanks ABG. According to err_invalid_name, i can share data until it's compiled then it privatized. Our governments keep demonstrating that privatization doesn't

Thanks for your assistance, ABG

thanks invalid, i shall read into that for sure.
Looks like I'll be leaning about text files

I can see I misread that document.... screens, not apps. Thanks for the poke in the eye! :stuck_out_tongue_winking_eye:

You could convert the TinyDB to a dictionary, save it to a file, and then access it in another app. Converting the TinyDB to a dictionary would end up looking something like the following image.
for each (tag) in list (TinyDB.GetTags): set value for key (tag) in dictionary (exampleDictionary) to (TinyDB.GetValue for tag (tag))

There are extensions available which can export and import a TinyDB. You can find them in the extensions directory App Inventor Extensions | Pura Vida Apps
To import TinyDB from another app, you need SAF...
SAF: App Inventor implementation of Storage Access Framework
See also Some basics on Android storage system


SAF can select / open file from other app's private dir?

No, App1 exports TinyDB to shared storage and App2 imports TinyDB from there using SAF



wow... so much not like the medieval days when you just had a disc to save and retrieve from. :roll_eyes:

so store the data on a cloud database is much easier.

you are correct there, methinks, Kevin. at least then i can use the apps whilst i learn about all this other stuff...

An alternative to TinyDB is the TinyWebDB component. It stores the data in one shared database instead of on a per-app database. By default it uses MIT's server but they strongly recommend against using the default server for anything more than basic testing. To run your own TinyWebDB database you could either use App Inventor's instructions or Kodular's instructions (Note: the two different instructions are for two different pieces of software that accomplish the same thing).