Works Great in Dev Env not When Deployed to Xoom

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
wm-f-simons
Posts: 4
Joined: Tue Sep 20, 2011 1:57 am

Works Great in Dev Env not When Deployed to Xoom

Post by wm-f-simons » Tue Sep 20, 2011 3:55 am

I am having difficulty deploying an app from my development environment to my Motorola Xoom. The app works great within the development environment.

Live Code Version 4.6.4

The Stack:
One Card, name = "ARRM_UI"
Three Scrolling List Fields, name one = "Year"; name two = "City"; name three = "ARRMdata
One button, name = "submit"
two fields, name one "year_picked" and name two "city_picked"

The database (with 780 rows)
one table, name = "ARRM"
Column one = "RowID"
Column two = "FY" (FY=Fiscal Year)
Column three = "City"
Column four to eight all numerical data

Standalone Application Settings:
General Tab = Selected "Search for required...." and Selected "Remove all profiles..."
Stack Tab = stackname.livecode
Copy Files = databasename.sqlite
Android Tab = Checked "Android"; Basic Application Settings checked SQLite; Requirements and Restrictions all radio buttons "N/A"; Application Permissions none checked; User interface options "landscape"

Menu Bar's --> Development the device is visible and checked.

I have two goals:
1. Get it to deploy on Xoom
2. More efficient live code script: as you will see below I use the fields "year_picked" and "city_picked" to store the user input that should be handled better using global variables but I am not getting it to work

Here is the script for the stack:

Code: Select all


Local tDataBaseID

on preopenstack
   databaseConnect
   if the environment is "mobile" then
      mobileSetAllowedOrientation "portrait, portrait upside down, landscape left, landscape right"
   end if
end preopenstack

##Open the connection to the database
on databaseConnect
   put SpecialFolderPath ("Desktop") &"/MyAppsFolder/MyDatabaseName.sqlite" into tDatabasePath
   put revOpenDatabase ("sqlite", tDatabasePath,,,,) into tDatabaseID
end databaseConnect

##This LiveCode and SQLite script will return the distinct values of FY's (2012, 2013, etc) for a table build into the scrolling list field of "year"
Function FYdata
   put SpecialFolderPath ("Desktop") &"/MyAppsFolder/MyDatabaseName.sqlite" into tDatabasePath
   put revOpenDatabase ("sqlite", tDatabasePath,,,,) into tDatabaseID
   
   put "SELECT DISTINCT FY FROM ARRM" into tSQL
   put revDataFromQuery(tab, return, tDatabaseID, tSQL) into tFYdata
   return tFYdata
end FYdata

##This LiveCode and SQLite script will return the distinct values of Cities (Chicago, Boston, etc) for a table build into the scrolling list field of "year"

Function CityNames
   put SpecialFolderPath ("Desktop") &"/MyAppsFolder/MyDatabaseName.sqlite" into tDatabasePath
   put revOpenDatabase ("sqlite", tDatabasePath,,,,) into tDatabaseID
   
   put "SELECT DISTINCT City FROM ARRM" into tSQL2
   put revDataFromQuery(tab, return, tDatabaseID, tSQL2) into tCityNames
   return tCityNames
end CityNames

##This live code and SQLite code will return all years and cities who have a value = to tFY and = to tCity
##I use hidden fields here because I am having trouble with making the global variable work
Function AggregateARRMdata
   put field "FY_picked" into tFY
   put field "City_Picked" into tCity
   
   put SpecialFolderPath ("Desktop") &"/MyAppsFolder/MyDatabaseName.sqlite" into tDatabasePath
   put revOpenDatabase ("sqlite", tDatabasePath,,,,) into tDatabaseID
   
   put "SELECT * FROM ARRM where FY = '"& tFY &"' and City = '"& tCity &"'" into tSQL3
   put revDataFromQuery(tab, return, tDatabaseID, tSQL3) into tAggregateARRMdata
   return tAggregateARRMdata 
end AggregateARRMdata
Here is the script for the card:

Code: Select all

##Build the distinct lists when the card is opened
on preopencard
   buildlistdisplay
end preopencard

##When the card opens the distinct list of fiscal years will be displayed
On buildlistdisplay
   put FYdata() into tFYData
   put tFYdata into field "Year_Picked"

##When the card opens the distinct list of cities will be displayed   
   put CityNames() into tCityName
   put tCityName into field "City_Picked"
      
end buildlistdisplay
Here is the code for the scrolling list fields which have distinct lists:

Code: Select all

##User will select a fiscal year (2012, 2013, 2014, etc)
## the clicked line will be saved as a variable and put into field "year_picked"

on MouseUp
   put the value of the clickLine into tFY 
   put tFY into field "Year_Picked"
end MouseUp

Code: Select all


##User will select a city (Chicago, Boston, New York, etc)
## the clicked line will be saved as a variable and put into field "city_picked"

on MouseUp

   put the value of the clickLine into tCity 
   put tCity into field "City_Picked"

end MouseUp
Here is the script from the submit button:

Code: Select all


on mouseUp

##Calls from the function script in the stack
##From the user input (Year and City) the fields (Year_Picked and City_Picked) are put into variables so that 
##the SQL script will Select a list from the table where Year= selected year and City = selected city
##The data returned from the database is put into field "ARRMdata"
   
   put AggregateARRMdata() into tAggregateARRMdata
   put tAggregateARRMdata into field "ARRMdata"

end mouseUp


Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Works Great in Dev Env not When Deployed to Xoom

Post by Mark » Tue Sep 20, 2011 9:13 am

Dear ...,

Could you describe in 1 brief sentence which part does work in the Android simulator but not on your Xoom device?

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

wm-f-simons
Posts: 4
Joined: Tue Sep 20, 2011 1:57 am

Re: Works Great in Dev Env not When Deployed to Xoom

Post by wm-f-simons » Tue Sep 20, 2011 10:54 am

Hi Mark,

I have not tested this code in the simulator (the simulator is flaky); I built it on my pc and test it on my device.

This stack works great while I am working with it in the live code software (the SQL statements call the database and returns all three querys and operate as expected). When I compile into .apk and instal it on my Motorola Xoom, only the two DISTINCT SQL statements build the list in the scrolling fields. After I select a year and a city then push the submit button, the "SELECT * FROM table WHERE year = "selected year" and city = "selected city" SQL Statement will not return the query from the database.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Works Great in Dev Env not When Deployed to Xoom

Post by Mark » Tue Sep 20, 2011 11:18 am

Hi ....,

One thing I've noticed is that you use specialfolderpath("desktop"). I don't think this works on a mobile device.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm
Location: NE USA

Re: Works Great in Dev Env not When Deployed to Xoom

Post by WaltBrown » Tue Sep 20, 2011 12:26 pm

I was wondering about a couple things. I know caseSensitive should not affect messages, but do the MouseUp handlers fire in the XOOM? Are the SQL statements correctly filled out when they execute?

I noticed you have used "FY_picked" and "Year_Picked". Are they different fields?

Just a thought from a beginner :-)

Walt
Walt Brown
Omnis traductor traditor

wm-f-simons
Posts: 4
Joined: Tue Sep 20, 2011 1:57 am

Re: Works Great in Dev Env not When Deployed to Xoom

Post by wm-f-simons » Tue Sep 20, 2011 1:29 pm

Mark,

The database is included in the .apk under the stand alone application settings: which has worked perfect on another app.

The population of the two scrolling list fields (year and city) works perfect with SQL statements.

The failure seems to be when I click the "submit" button and call on the database to select all from table where fy="a year" and city = "a city":

Submit Button:

Code: Select all

on Mouseup
   put GetARRMdata() into tARRMdata
   put tARRMdata into Field "ARRM"
end Mouseup
The above code calls a function from the stack script

Code: Select all

Function AggregateARRMdata
   put field "FY_picked" into tFY
   put field "City_Picked" into tCity
   
   put SpecialFolderPath ("Desktop") &"/MyAppsFolder/MyDatabaseName.sqlite" into tDatabasePath
   put revOpenDatabase ("sqlite", tDatabasePath,,,,) into tDatabaseID
   
   put "SELECT * FROM ARRM where FY = '"& tFY &"' and City = '"& tCity &"'" into tSQL3
   put revDataFromQuery(tab, return, tDatabaseID, tSQL3) into tAggregateARRMdata
   return tAggregateARRMdata
end AggregateARRMdata

Walt...

You are correct, it is year_picked. I had to change the names for this post so that it made sense.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Works Great in Dev Env not When Deployed to Xoom

Post by Mark » Tue Sep 20, 2011 1:56 pm

....,

It takes me too much time to test this all by myself, but if you could attach a very simple stack to illustrate the problem, then I'd be happy to give it a try in the Android simulator. I can't test it on a real Android device, unfortunately.

I still think you need to change specialfolderpath("desktop") because specialfolderpath("desktop") returns empty on a mobile device.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Works Great in Dev Env not When Deployed to Xoom

Post by sturgis » Tue Sep 20, 2011 3:44 pm

Just noticed something, not sure if it relates to the problem, but..

I notice that you open the database in the preopenstack handler, and also in each function call to grab data, but I don't see any place where you close the database. I believe this will leave hanging instances. You might consider adding a bit of error checking to each function because i'm wondering if android has issues with concurrent hits on the db file.

So, for example, you might change this to:

Code: Select all

on databaseConnect
   put SpecialFolderPath ("Desktop") &"/MyAppsFolder/MyDatabaseName.sqlite" into tDatabasePath
   put revOpenDatabase ("sqlite", tDatabasePath,,,,) into tDatabaseID
   if tDatabaseID is not an integer then
        answer "There was an error: " & tDatabaseID
   end if
end databaseConnect
Do the same for each place you open the database. If there are no errors, you might also consider putting in a button to check the results of revopendatabases() to see if you have multiple instances the open database. Finally, after your select, you might insert an answer dialog there too to look at the result. (so right after a select, answer information the result)

There is also try / catch that you can use to get information back but I haven't messed with try and catch much so am too clueless to give more information on them.

Also as mark said, i'm surprised it works using specialfolderpath("desktop") and am wondering if you have your field saved with the data from a previous run (IE from windows) so the data is there, but the initial database hit is failing.

oops nope nevermind that, worst case it should empty the field, so you are right, the database connect is working. In which case my guess would be that the path to the database is actually /MyAppsFolder/MyDatabaseName.sqlite and is unaffected by specialfolderpath("desktop") being empty.

Hope something here points you in the right direction, good luck.

wm-f-simons
Posts: 4
Joined: Tue Sep 20, 2011 1:57 am

Re: Works Great in Dev Env not When Deployed to Xoom

Post by wm-f-simons » Tue Sep 20, 2011 8:48 pm

Sturgis,

You were right. I think this is a bug with LiveCode when SQL statements are in a button.

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: Works Great in Dev Env not When Deployed to Xoom

Post by BarrySumpter » Wed Sep 21, 2011 8:17 am

...
When I compile into .apk and install it on my Motorola Xoom,
...
You don't need to compile to .apk and install.
You can run on an attached physical device by selecting
Development | Test Target | myMobileHashNumber
Then click the Test button on the IDE Menubar

The last 2 or 3 pages of this document discusses how to setup your phone.
1. the phone setting must allow for debug mode.
2. the phone setting must allow for unAuthorized installs (sorry can't remember the exact wording)

Better - How-do-I-Become-an-Android-Developer-on-a-PC win32
http://forums.runrev.com/viewtopic.php?f=53&t=8137

My installs and runs were taking about 30 seconds. I was trying to save the wear and tear on my physical phone.
My tests on an attached physical device take about 5 seconds.

This works on both win32 and OSX on my Android HTC HD2.

hth
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Works Great in Dev Env not When Deployed to Xoom

Post by sturgis » Wed Sep 21, 2011 2:07 pm

Just re-read my response, and I neglected to say that if you ARE going to open the database in each function call, you need to close it within the same call. If you are going to open and close the database each time within each individual function call, there is no need to do so from you preOpenStack. Its opened and then nothing is done with it until you build your initial list, which opens it a 2nd time, changing the tDataBaseID leaving the first instance that was opened but ignored.

For each function then, it would appear something like the following

Code: Select all

Function myExampleFunction
   put "path/to/MyDatabaseName.sqlite" into tDatabasePath -- for the example, just made up a path
   put revOpenDatabase ("sqlite", tDatabasePath,,,,) into tDatabaseID -- open the database
    if tDatabaseId is not an integer then  -- check for error opening db
       answer information "Couldn't open DB:" && tDatabaseID -- if there was an error, say so. 
       put empty into tDatabaseID --not necessary if the tDatabaseID is NOT declared as a script local
   else -- otherwise
       do your selection stuff here, and return the datafromquery
       close tDatabaseID -- close it 
       put empty into tDatabaseID -- not necessary if the tDatabaseID is NOT declared as a script local
   end if
end myExampleFunction
The other alternative is to open the database once on startup, and close it on shutdown, doing checks in your functions to make sure its actually open before trying to do your query (but not opening it again unless necessary). One other thing about using this second method. You probably shouldn't connect to your database using the preopenstack handler because the necessary support may not yet be loaded. (IE the database functionality) Better to do it in openstack, or preopencard.

If you look at the very last comment for revOpenDatabase it says this on the subject.
revOpenDatabase, like all the revDB commands and functions is implemented in a separate library called an External, rather than in the Revolution core engine.

The database library is loaded by adding a hidden group to your stack when deploying it. This hidden group then loads up the library by creating a wrapper stack for the external and inserting it into the message path. It does this on receipt of its first preOpenBackground message.

The consequence of this is that attempting to connect to the database before this preOpenBackground message has initialized the external will fail. For example, don't connect to the database on preOpenStack. Instead use openStack or openCard.
--edited 7:39 because I can't type.

Post Reply

Return to “Android Deployment”