2017년 7월 25일 화요일

App runs fine in Companion but crashes when installed as APK


I have created a small app to replace our visitor signing in book at school. It works fine in the AI2 Companion but crashes when I build it as the APK. The original app had 4 screens:

Screen1 (basically 2 buttons - sign in and sign out)
Safeguarding (you're taken here if you click "Sign in", read some info and click the button to say you have)
SignIn (4 textboxes for the info and a submit button; when clicked the info is stored in a fusion table)
SignOut (a listpicker of names, populated from a fusion tables query which runs when the screen is initialised; after picking another query gets the correct ROWID, then a further query updates the fusion table with a departure time).

This version failed on attempting to access the SignOut screen from the button on Screen1. "Sorry, Visitor Sign In has stopped".

Having looked on the forums, it seemed that my issue might be the multiple screens, so I rebuilt the app as a single screen, with vertical arrangements for each "screen". If anything this is more unstable. The fusion table is being updated correctly when the app doesn't freeze (and sometimes when it does), but the gotResult block rarely seems to fire (it should trigger a notifier and return the user to the home screen). Rather than stopping, this version freezes the phone and eventually I am able to close it myself from my phone's 3rd ("overview") button.

There are no errors showing in the blocks editor and the apk file size seems fine (2.8MB for the original version and 2.56MB for the single screen version).

My suspicion is that the response from the fusion table is too slow, but I really don't know. It's the first app I've built using fusion tables and I may be making simple mistakes, but I am using the service user method and, as I said at the top, when using the Companion it all works beautifully.

Any ideas gratefully received!

--
Here are the blocks for the single screen version.











--
if you select only one column from the table (as in query3 and query2), then the recommended method to convert the result, which is a 1 column csv table into a list is to use the split block
just split at \n (new line) to get a simple list, the first item is the header row and the second item your value
you also will not need the closeBr and openBr methods then...

however this might not correct your problem...
so everything works fine exept the 4th query (the Update)?

--
Well, things are getting worse! I tried the change you suggested, and got an error that there was no 2nd item. I changed the index to 1, and that worked (blocks attached, just in case I have misinterpreted your advice). However, I just don't seem to be getting a result back as notifiers are never shown and the phone is just freezing. This is with the Companion now, and I do get an Out of Memory error reported in the browser (also attached).

Just for my own sanity, I just loaded up the original multi-screen version in the Companion and did a full cycle of Sign In and Sign Out - all fine and the fusion table updated as it should.

I do appreciate your help, Taifun - it was your site that got me going with fusion tables in the first place when I gave up on doing the same thing in Sheets!




--
Are you having your visitors sleep over overnight?

You are generating a list of names for signout from people
who signed in on another day  (date != today), not today.

Also, since you never clean out the table at end of day,
you might get multiple ROWIDs for a repeat visitor.
Just get the ROWID from his latest visit.

--
Also, you can rename your Fusion Table controls to include their purpose
to avoid confusion.  Remembering which is which is tedious and risky otherwise.

--
Thanks Abraham - good advice. When I started the project I thought I'd only need one fusion tables control, a little like making a database connection once before running various queries, so I was half expecting to be told I didn't need 4. Since I do need them all, however, I've now renamed them. I've also deleted the exclamation mark. I'm not sure why I wanted it to be visitors with no sign out time and a different date from today, but I remember looking up the SQL syntax for "not equals"! It seems completely bizarre now. It's late here and I can't test tonight, but I suppose that could be part of the issue, although the app was returning names of people who'd only just signed in, so I'm not sure the query was working properly anyway. I'll have a look in the morning and post to the group.

--
Well, things are getting worse! I tried the change you suggested, and got an error that there was no 2nd item. 

you forgot to show us what you have tried...
also you might want to use Do it to debug your blocks, see also tip 4 here 

--
The change I made was in capture6.png (reattached). It's all still very flaky, and my phone is still freezing (using the Companion).

Sign in works in that:
1. I click Sign In.
2. I click that I've read the info.
3. I fill in my details and submit.
4. The fusion table (open in another tab) receives the new data.

Then the app freezes my phone and nothing happens. Actually, while I've been typing this it's returned to the home screen, but the buttons are not working and the keyboard is still visible. EDIT: 30 seconds later and the app has closed itself, with the out of memory error I showed earlier.

Sign Out works to the extent that:
1. I click Sign Out.
2. I can choose from a list of people who are in the building.

Then the app freezes and, after around a minute, closes with the same memory error in the blocks editor.

Just to clarify, this position is much worse than a few days ago, when the original multi-screen app worked perfectly in the companion but failed as an APK. The only actual error I think I've found is the one Abraham pointed out with the !=. I can't decide whether I'd be better off trying to go back to that first version. I must admit I was hoping there was a known issue around built apps with an easy fix!


--
 the recommended method to convert the result, which is a 1 column csv table into a list is to use the split block
just split at \n (new line) to get a simple list, 

the first item is the header row and the second item your value

--
Thanks Taifun - that works (and I've learnt the "proper" way to do it). Both processes now "work" in that they update the fusion table, but the app is still freezing rather than triggering a notifier and loading up the home VA. I'm stuck.

--
My last idea tonight was to delete all images, including the app icon. The only file is now the key file for the fusion tables. It's nothing more than a single screen (fixed, not responsive) with some arrangements, labels, text boxes, buttons and a list picker. Same memory issue. :-(

--
Could you post the latest work?

--
Here are the blocks as they stand. I made the changes that you suggested (!= and naming the fusion tables controls) and those Taifun advised (amending the way I dealt with the query result and deleting the blocks for removing brackets). 

The only ftb controls that seem to complete correctly are the simple SELECTs to get the names for the listpicker and the ROWID for the UPDATE query (although the others update the fusion table they never seem to return a result to the app). I'm wondering if UPDATEs do return a result (I'd assume some kind of success code).

Thanks for your ongoing help!


--
I see a mismatch between the value of TimeOut for newly INSERTED
records and the expectations of the SELECT people who have not yet signed out query.

New records are added with TimeOut set to current date,
but you look for records with TimeOut equal to an empty string.

--
I think that one's fine - it's TimeIn which is set to the current time when a new record is inserted. I've attached a screenshot of the fusion table to show how it has been updated over the last couple of weeks by various iterations of the app, and the kind of data I expect.


--
Sorry, the length limitations on the text block holding the INSERT column
names made me guess wrong on the number of columns.

Unfortunately, only a JOIN of text blocks will show all the names
past a certain length.

Your table has 7 columns, but your INSERT has 6 values.
I would not trust Fusion Tables' default on that last column
to be blank.

Could you show us the data types of the table columns,
especially TimeIn and TimeOut and Date, to
eliminate Fusion Tables' unexpected format conversions?

I notice a dead csv table conversion data flow into a global at the top of
the SELECT  ROWIDS result event ftbGetNames.GotResult.
Also, there probably aren't any double quotes to filter out.
You might also want to force open the List Picker after loading its
Elements list, to save the user from having to hit the List Picker button.

The result formatting mentioned for UPDATE  at
says:
UPDATE
To update values in one or more columns of an existing row in a table, use the following syntax in an HTTP POSTrequest:
UPDATE <table_id>
SET <column_name> = <value> {, <column_name> = <value> }* WHERE ROWID = <row_id>

Returns

If the request succeeds, the server responds with a 200 OK status code and the number of affected rows in JSON format.

I would add error checking  on the  GET ROWID return to make sure
you have 2 list items before extracting the ROWID for the UPDATE,

I would also like to see the return from the UPDATE, to be able to 
error check it.

--
Also, the use of a blank for the default of TimeOut looks risky to me.
It opens up worries about the success of matching zero length
strings against an unknown number of blanks, in SQL and in AI2,
along with worries about whether or the value '' (two apostrophes) 
in the SQL WHERE clause value is interpreted properly,
or is just a " double quote character (they look the same.)  I would switch
to an application default value of '-'  to split the apostrophes and eliminate
doubt about blanks.

To eliminate worries about consistent formatting of today's date in
the INSERT versus the SELECT WHERE clause, I would hide the
today() calculation and formatting in a value procedure, invoked at
both places instead of the global variable today.

--
Another application thought - 

Does your school plan to use this app for visitors to an Astronomy club,
spanning midnight?  There goes your date check.

--
Wow - lots to think about there, thank you. First of all, I can't envisage a situation where a visitor would stay at school past midnight, so I'm comfortable leaving that as it is. I'll work on the other suggestions over the next day or so and post back the blocks afterwards, but in the meantime here is the "Edit columns" view for the fusion table. Apart from the date they are all just text fields with no validation.



--
Well, I think I've made the changes as you described, Abraham, but I may have misunderstood. We're not any further forward, unfortunately, with freezing in all the same places, but the fusion table being updated correctly on both sign in and sign out. I've attached the blocks as they are now, and also a little bit I just tried to see if I was getting a 200 result on the insert query. I may have made a mistake as I've never tried that before.




--
We're not any further forward, unfortunately, with freezing in all the same places, but the fusion table being updated correctly on both sign in and sign out. 

I notice you are not forcing open the List Picker after the list of people
who have not yet signed out arrives.
Is that where the freeze happens?

I've attached the blocks as they are now, and also a little bit I just tried to see if I was getting a 200 result on the insert query. 

INSERT queries return a numeric ROWID, almost never equal to 200.
A more appropriate test of the return value would be:
Is it a number?
There's a block for that.

If you prepare a dummy table for testing only, that would let you
safely post the .aia

--
That's the one query that seems to work fine, with no freezing. The listpicker populates as expected and I can select a value.

I can always create a new table if we can get this working and just change the tableID in the app, so I've attached the AIA. Thanks again for all your support with this!


--

Oh, and the bottom row has no data in it because it was created when I was trying "Do it" in the blocks editor". It's not a problem with the app.

--
I dealt with a spurious error 906 from closing a closed keyboard,
plus other changes in the change_log.

I forced open the name list, to save a step.
Also fixed the INSERT return check.

See attached.

It works on my emulator and old tablet, Android 2.2 on my home network.





--
Thank you so much. I have tested this in the Companion and will try the APK tomorrow. The fact you have taken the time to include a change log and also comment the code is fantastic and much appreciated.

I did find that the text boxes were now retaining the last entry from visitor to visitor, but I have just put 4 blocks in when the insert query completes to set them to blank text before the home screen is called.

--

댓글 없음:

댓글 쓰기