Converting from AI to B4A

JonPM

Well-Known Member
Licensed User
Longtime User
Hey all. I'm new around here and to programming in general. I started out with AppInventor several months ago and currently have 3 apps out on the market (each with an average of about 1000 users). My plans are to rewrite each app from the ground up using B4A (got tired of working with AI...). Anyhow, my question is this. For persistent data, AI uses "TinyDB" to store values and their tags. Since I will be eventually updating my apps with their B4A version I will need to preserve my users' TinyDB data in the B4A version. Does anyone know if this is possible. I'm not sure exactly how or where the data from AI gets stored. Perhaps Erel can help? I'm guessing if there is a way I would just need to use the exact same tags that I used in AI, and hopefully the stored data will just cross over.
I hope this is possible as it would probably piss of my users if they lost all their data :( Anyone?
 

agraham

Expert
Licensed User
Longtime User
I don't know much about App Inventor (apart from the fact it looks awful and seems to be exteremely limited) but it seems the TinyDB data is kept in File.DirInternal for each application and so is not accessible to other programs. The actual "database" looks trivial, the Basic4android equivalent would be File.ReadMap/WriteMap.

The only way to get at the data would be to write it out to the SDcard but it seems App Inventor does not support file write access. As far as I can see the only way to get data off the application is by TinyWebDB but that looks a bit too hacky to do it for 1000 users and would need each AI application modifying to do it.
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
I was planning on mimicking the apps I have out on the market with B4A, meaning I will be keeping the same package name, and obviously signing them with my key. By doing this do you think I can access the File.DirInternal for each app? I am hoping for a smooth transition so that the end user only see a market update (i.e. from v1.6 to v2.0), and everything else would be the same.
 
Upvote 0

Tom Christman

Active Member
Licensed User
Longtime User
According to the AI Forums the data is stored in "/data/data/appinventor.ai_<yourgmail>.<yourpackagename>/TinyDB.XML ". Sounds a bit challenging!
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I don't think that path is quite correct. A bit more research here indicates from someone who has looked at the source code that the data it is actually stored as Shared Preferences

>>> No I REALLY want to get my hands on that TinyDB file... but
>>> SharePrefrences... Just read up a bit... 0.o <-- Googly eyes.
>>> That was an education. SharedPrefrences uses a monolithic XML for the
>>> entire SharedPref Object apparently...
Looks like you would have to get at it through a Shared Preference object at which point I will bow out! :)
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
Looks like you would have to get at it through a Shared Preference object at which point I will bow out! :)

uh oh, that bad huh? Any tips for a newbie regarding shared preferences?

Sent from my DROIDX using Tapatalk
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
A suggestion which may work; if it was me i would look to tackle it this way,

Put a new version out in AI which reads all the data in the Dbase and writes it to a file in a known location which you CAN access. Then when you update to B4A you only need to read the file and re-populate your new database

Then again I know NOTHING about AI

Joe
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
Hmm. Well looks like I'm going to have a few thousand angry customers :(

Sent from my DROIDX using Tapatalk
 
Upvote 0

cammel8

Member
Licensed User
Longtime User
Although the program does not allow for writing to a file it does give you a way to export the data. Email! Just write a program in AI that will extract all the data from the tinydb and use the delimited text output as the main text portion of the email. This program can be made with all the instructions on how to backup the end users data.

Then you could do one of two things. First you could just have your customers copy the email to a text file and name it something specific like myprog_backup.txt and copy it to a specific directory on the sd card. Or second you could have the program email all the info to you, and you create the file for them and email it back to them as an attachment.

Then with your new program written in b4a, put a messagebox that shows up at install that instructs the person on how to back up the information from the old program, and when they click ok, sends them to the download location in marketplace to the backup utility you wrote in AI. Then the b4a program once the file is in place could read the file and use it to populate your new db and then bing bang boom, your information is backed up. Then no pissed off customers. I know if I had to either lose all my info or copy text from a email, Id copy the text.

P.S. As I was writing this, it occurred to me that there might even be an easier way. I know when I was researching for another program I was working on, that php can write files to the computer that it resides on. You could write a webpage in PHP, and host it on a computer of your own. Then write a program in AI that logs into the site and uploads the database info to the server. Then the website would create a text delimited file, and name it myprog_backup.text, and then using the persons email they provide, email the file as an attachment back to them. This would be completely automated and take away the need of the end user using a computer to do the transfer, as all of this could be done on the phone itself.

Well thats all I have right now, but between those two ideas you should be able to come up with something. And before you ask, no, I have no idea how to write a php site to do this. I never got into php. But I do know it has the ability to write to files on the computer it resides so you should be able to research it and find out how using google or maybe someone else here can help you.

I hope this has helped you or at least given you an idea on how to fix your problem.

Thanx
George
 
Upvote 0
Top