Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27083] [Android] Continues functions after Ti.App._restart()

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionWon't Do
Resolution Date2019-05-21T21:49:34.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsactivity, andoid, bluetooth, engTriage, memory, reset
Reporterjosh.mocek
AssigneeEric Merriman
Created2018-09-21T19:42:43.000+0000
Updated2019-05-21T21:49:34.000+0000

Description

Build this app onto an android device. Connect a bluetooth keyboard. Open the app. Press the blue button a few times. Disconnect the scanner while the app is counting. The app resets and picks back up where it left off. This is a problem because if I am running sql queries while the app resets it can continue to run the backbone functions without variables/Globals defined yet resulting in red screens. I am restarting the app. Why are variables still defined? Why are functions still running? In this app some variables are keeping their values, but in a larger scale app not all variables are redefined on Resume. I have added a testString variable that is defined initially as 'not Clicked', but redefined as 'clicked' once the runQueries function runs. You can see this in the second set of logs. If you press Clear after a reset it outputs 'not Clicked' and if you press it before the restart it says 'clicked'. This makes it very difficult when using an app that has bluetooth devices connected since it is impossible to know which variables will be defined correctly after a bluetooth reset. Now if you could fix the app from restarting when a bluetooth scanner is connected that would be great, but I think that's just an android problem. Log:
09-21 14:46:41.950: E/TiAPI(8748):  currentCount: 58/150
09-21 14:46:42.017: E/TiAPI(8748):  currentCount: 59/150
09-21 14:46:42.248: E/TiAPI(8748):  currentCount: 60/150
09-21 14:46:42.292: E/TiAPI(8748):  currentCount: 61/150
09-21 14:46:42.602: E/TiAPI(8748):  currentCount: 62/150
09-21 14:46:42.602: E/TiAPI(8748):  currentCount: 63/150
09-21 14:46:42.951: E/TiAPI(8748):  currentCount: 64/150
09-21 14:46:43.017: E/TiAPI(8748):  currentCount: 65/150
09-21 14:46:43.236: E/TiAPI(8748):  *-*-*-*-*-*-* PAUSE BY OS *-*-*-*-*-*-*
09-21 14:46:43.246: E/TiAPI(8748):  *-*-*-*-*-*-* STOP BY OS *-*-*-*-*-*-*
09-21 14:46:43.247: E/TiAPI(8748):  *-*-*-*-*-*-* DESTROY BY OS *-*-*-*-*-*-*
09-21 14:46:43.247: E/TiAPI(8748):  Restart Start
09-21 14:46:43.348: E/TiAPI(8748):  Restart End
09-21 14:46:43.348: E/TiAPI(8748):  currentCount: 66/150
09-21 14:46:43.348: E/TiAPI(8748):  currentCount: 67/150
09-21 14:46:43.601: E/TiAPI(8748):  currentCount: 68/150
09-21 14:46:43.601: E/TiAPI(8748):  currentCount: 69/150
09-21 14:46:43.952: E/TiAPI(8748):  currentCount: 70/150
09-21 14:46:44.017: E/TiAPI(8748):  currentCount: 71/150
09-21 14:46:44.029: E/TiAPI(8748):  *-*-*-*-*-*-* WINDOW OPENED *-*-*-*-*-*-*
09-21 14:46:44.029: I/TiAPI(8748):  OS_ANDROID
09-21 14:46:44.033: I/TiAPI(8748):  END OS_ANDROID
09-21 14:46:44.033: E/TiAPI(8748):  *-*-*-*-*-*-* START BY OS *-*-*-*-*-*-*
09-21 14:46:44.041: E/TiAPI(8748):  *-*-*-*-*-*-* RESUME BY OS *-*-*-*-*-*-*
09-21 14:46:44.185: I/TiAPI(8748):  ACS Login Results for environment development:
09-21 14:46:44.185: I/TiAPI(8748):  [object Object]
09-21 14:46:44.349: E/TiAPI(8748):  currentCount: 72/150
09-21 14:46:44.349: E/TiAPI(8748):  currentCount: 73/150
09-21 14:46:44.602: E/TiAPI(8748):  currentCount: 74/150
09-21 14:46:44.602: E/TiAPI(8748):  currentCount: 75/150
09-21 14:46:44.954: E/TiAPI(8748):  currentCount: 76/150
09-21 14:46:45.018: E/TiAPI(8748):  currentCount: 77/150
09-21 14:46:45.350: E/TiAPI(8748):  currentCount: 78/150
09-21 14:46:45.350: E/TiAPI(8748):  currentCount: 79/150
09-21 14:46:45.602: E/TiAPI(8748):  currentCount: 80/150
another:
09-21 14:58:55.394: I/TiAPI(11235):  count: 175
09-21 14:58:55.471: E/TiAPI(11235):  currentCount: 129/175
09-21 14:58:55.739: E/TiAPI(11235):  currentCount: 130/175
09-21 14:58:55.773: E/TiAPI(11235):  currentCount: 131/175
09-21 14:58:55.835: E/TiAPI(11235):  currentCount: 132/175
09-21 14:58:55.900: E/TiAPI(11235):  *-*-*-*-*-*-* PAUSE BY OS *-*-*-*-*-*-*
09-21 14:58:55.906: E/TiAPI(11235):  *-*-*-*-*-*-* STOP BY OS *-*-*-*-*-*-*
09-21 14:58:55.909: E/TiAPI(11235):  *-*-*-*-*-*-* DESTROY BY OS *-*-*-*-*-*-*
09-21 14:58:55.909: E/TiAPI(11235):  Restart Start
09-21 14:58:56.007: E/TiAPI(11235):  Restart End
09-21 14:58:56.134: E/TiAPI(11235):  currentCount: 133/175
09-21 14:58:56.139: E/TiAPI(11235):  currentCount: 134/175
09-21 14:58:56.609: E/TiAPI(11235):  currentCount: 135/175
09-21 14:58:56.609: E/TiAPI(11235):  currentCount: 136/175
09-21 14:58:56.739: E/TiAPI(11235):  currentCount: 137/175
09-21 14:58:56.778: E/TiAPI(11235):  currentCount: 138/175
09-21 14:58:56.786: E/TiAPI(11235):  *-*-*-*-*-*-* WINDOW OPENED *-*-*-*-*-*-*
09-21 14:58:56.786: I/TiAPI(11235):  OS_ANDROID
09-21 14:58:56.790: I/TiAPI(11235):  END OS_ANDROID
09-21 14:58:56.791: E/TiAPI(11235):  *-*-*-*-*-*-* START BY OS *-*-*-*-*-*-*
09-21 14:58:56.796: E/TiAPI(11235):  *-*-*-*-*-*-* RESUME BY OS *-*-*-*-*-*-*
09-21 14:58:56.835: E/TiAPI(11235):  currentCount: 139/175
09-21 14:58:57.097: I/TiAPI(11235):  ACS Login Results for environment development:
09-21 14:58:57.097: I/TiAPI(11235):  [object Object]
09-21 14:58:57.135: E/TiAPI(11235):  currentCount: 140/175
09-21 14:58:57.140: E/TiAPI(11235):  currentCount: 141/175
09-21 14:58:57.609: E/TiAPI(11235):  currentCount: 142/175
09-21 14:58:57.609: E/TiAPI(11235):  currentCount: 143/175
09-21 14:58:57.740: E/TiAPI(11235):  currentCount: 144/175
09-21 14:58:57.777: E/TiAPI(11235):  currentCount: 145/175
09-21 14:58:57.836: E/TiAPI(11235):  currentCount: 146/175
09-21 14:58:58.134: E/TiAPI(11235):  currentCount: 147/175
09-21 14:58:58.141: E/TiAPI(11235):  currentCount: 148/175
09-21 14:58:58.610: E/TiAPI(11235):  currentCount: 149/175
09-21 14:58:58.610: E/TiAPI(11235):  currentCount: 150/175
09-21 14:58:58.740: E/TiAPI(11235):  currentCount: 151/175
09-21 14:58:58.778: E/TiAPI(11235):  currentCount: 152/175
09-21 14:58:58.835: E/TiAPI(11235):  currentCount: 153/175
09-21 14:58:59.134: E/TiAPI(11235):  currentCount: 154/175
09-21 14:58:59.142: E/TiAPI(11235):  currentCount: 155/175
09-21 14:58:59.612: E/TiAPI(11235):  currentCount: 156/175
09-21 14:58:59.612: E/TiAPI(11235):  currentCount: 157/175
09-21 14:58:59.741: E/TiAPI(11235):  currentCount: 158/175
09-21 14:58:59.777: E/TiAPI(11235):  currentCount: 159/175
09-21 14:58:59.836: E/TiAPI(11235):  currentCount: 160/175
09-21 14:59:00.135: E/TiAPI(11235):  currentCount: 161/175
09-21 14:59:00.141: E/TiAPI(11235):  currentCount: 162/175
09-21 14:59:00.611: E/TiAPI(11235):  currentCount: 163/175
09-21 14:59:00.611: E/TiAPI(11235):  currentCount: 164/175
09-21 14:59:00.741: E/TiAPI(11235):  currentCount: 165/175
09-21 14:59:00.778: E/TiAPI(11235):  currentCount: 166/175
09-21 14:59:00.835: E/TiAPI(11235):  currentCount: 167/175
09-21 14:59:01.135: E/TiAPI(11235):  currentCount: 168/175
09-21 14:59:01.142: E/TiAPI(11235):  currentCount: 169/175
09-21 14:59:01.613: E/TiAPI(11235):  currentCount: 170/175
09-21 14:59:01.613: E/TiAPI(11235):  currentCount: 171/175
09-21 14:59:01.743: E/TiAPI(11235):  currentCount: 172/175
09-21 14:59:01.777: E/TiAPI(11235):  currentCount: 173/175
09-21 14:59:01.836: E/TiAPI(11235):  currentCount: 174/175
09-21 14:59:02.137: E/TiAPI(11235):  currentCount: 175/175
09-21 14:59:04.849: I/TiAPI(11235):  testString: not Clicked

Attachments

FileDateSize
alloy.js2018-09-21T19:41:10.000+00001696
app.tss2018-09-21T19:41:10.000+0000780
index.js2018-09-21T20:02:46.000+00002640
index.tss2018-09-21T19:41:10.000+0000155
index.xml2018-09-21T19:41:10.000+0000386
tiapp.xml2018-09-21T19:41:10.000+00003650

Comments

  1. Sharif AbuDarda 2018-11-28

    Hello, Please test on SDK 7.5.0.GA and let us know if the issue still there. Thanks.
  2. josh.mocek 2018-11-29

    Not fixed with 7.5.0
  3. Rakhi Mitro 2019-01-02

    Hello, Just passing as update here. I thought I’d check in to see how things are progressing.  Please let us know your current status of the issue.
  4. josh.mocek 2019-01-02

    Tested this on 7.1.0 and 7.5.0 again with run-on-main-thread = false and this is still an issue. If y'all have any update on this let me know.
  5. Rakhi Mitro 2019-01-29

    Hello, Just wanted to circle back here. Still are you experiencing this issue? Can you please check, if the issue also reproducible without using a Bluetooth keyboard on your end?
  6. josh.mocek 2019-01-29

    Still reproducible w/ the bluetooth keyboard. You will notice that in the OnDestroy listener I call Ti.App_restart() because on android it would restart anyway and this is cleaner than the dirty restart a bluetooth connect/disconnect forces. From what I understand is that on android the bluetooth connect and disconnect forces the app to restart.
  7. Joshua Quick 2019-01-29

    Can someone summarize what the issue is in 1 sentence please? Is the issue that the app UI disappears when connecting/disconnecting a bluetooth keyboard? If so, then it sounds like the "AndroidManifest.xml" main <activity/> element's android:configChanges is missing the "keyboard" setting. This will override the Android OS' default behavior of destroying and recreating the activity when a keyboard has been attached/detached or if a device's slide-out keyboard has been slid-out/in. https://developer.android.com/guide/topics/manifest/activity-element#config [~josh.mocek], try adding the following to your "tiapp.xml". Note that your app's main activity name is based on your app's name, which for the attached test project is "runOnMainThread". So, you use the app's name, capitalize the first letter and lower case all other letters, and then append "Activity" to it.
       <?xml version="1.0" encoding="UTF-8"?>
       <ti:app xmlns:ti="http://ti.appcelerator.org">
       	<android xmlns:android="http://schemas.android.com/apk/res/android">
       		<manifest>
       			<application>
       				<activity android:name=".RunonmainthreadActivity" android:configChanges="keyboard|keyboardHidden|orientation|fontScale|screenSize|smallestScreenSize|screenLayout|density">
       					<intent-filter>
       						<action android:name="android.intent.action.MAIN"/>
       						<category android:name="android.intent.category.LAUNCHER"/>
       					</intent-filter>
       				</activity>
       				<activity android:name="org.appcelerator.titanium.TiActivity" android:configChanges="keyboard|keyboardHidden|orientation|fontScale|screenSize|smallestScreenSize|screenLayout|density"/>
       			</application>
       		</manifest>
       	</android>
       </ti:app>
       
    Note that I don't have a bluetooth keyboard on me at the moment to confirm the issue, but this is how I remember it working on Google's end in the past. The Android OS by default will destroy, restart an activity, and then reload its UI from XML when various things happen such as orientation change, attaching/detaching a keyboard, etc. But for apps that create the UI dynamically via code (such as Titanium), there is no XML to reload the UI from. So, these "configChanges" types in the manifest need to be overridden to prevent this behavior.
  8. Joshua Quick 2019-01-29

    I've obtained a bluetooth keyboard and was able to reproduce the issue. What I've stated above is definitely the issue and I've confirmed that the above "tiapp.xml" change does work-around the issue. I've written up a separate bug report for this issue here: [TIMOB-26777] We'll look into updating our build system to automatically add the "keyboard" setting into the "AndroidManifest.xml" in the future. Thanks for bringing this issue to our attention.
  9. Sharif AbuDarda 2019-01-30

    Hello [~josh.mocek], Can you follow up here? Did the workaround solve the issue you were having? Let us know. Thanks.
  10. josh.mocek 2019-02-12

    It still rebuilds, but now instead of calling: destroy window open start resume it rebuilds and just calls: window open start resume
  11. Sharif AbuDarda 2019-02-12

    Hello [~josh.mocek], Please post a comment in the TIMOB ticket for our engineers to follow up and updating any other requirements necessary. Thanks.
  12. josh.mocek 2019-02-12

  13. Joshua Quick 2019-02-12

    Titanium's _restart() function is not a public API. We use it internally for LiveView to restart the app. And yes, the _restart() function will not recreate the root activity window. That is by design, because closing it would kick you out to the device's homescreen. Instead, it closes all child activity windows, brings you back to the root activity which shows the splash screen, and then restarts the JavaScript runtime. This means you will not get an activity destroy event from the root activity window. That is by design and is working correctly. We're not changing this behavior. The XML settings I posted above resolves an issue where connecting/disconnecting a keyboard will destroy and re-create the current activity, causing all UI creating by Titanium to disappear. That's a legit issue you've found.
  14. josh.mocek 2019-02-13

    After adding that XML code I disconnected the scanner and it works. When I put that into our app it causes it to crash. Not sure why yet, but I'm going to do some more tests. Without the XML: I did notice that on 7.5.0 run-on-main-thread = false when the scanner disconnects it calls: destroy stop window open start resume when run-on-main-thread = true it only runs: window open start resume Should it not still be running destroy and stop when run-on-main-thread = true? Should I make a new ticket?
  15. Joshua Quick 2019-03-14

    The _restart() function is an undocumented feature that's intended for Titanium's LiveView feature. It's not intended to be used by app developers. We don't plan on making any changes to it. My understanding is that you're using the _restart() function to work-around the bluetooth keyboard issue. If you add the XML configChanges "keyboard" setting as shown above, then you'll no longer need to implement your restart work-around.
  16. Rakhi Mitro 2019-03-20

    [~josh.mocek], We haven't heard back from you since our last response. I thought I’d check in to see how things are progressing with your need?  Please let us know if the problem persists.  Have a great day. Thanks
  17. josh.mocek 2019-03-25

    When I put that code in the app we have in production and connect a bluetooth keyboard it doesn't restart, but the app freezes then crashes with no error.
  18. Rakhi Mitro 2019-03-26

    [~josh.mocek], Did you apply the work around suggested by Josua Quick?
  19. josh.mocek 2019-03-26

    Yes, that was what caused the freeze and crash
  20. Sharif AbuDarda 2019-05-01

    Hello [~josh.mocek], Whats the status of your issue? [~jquick], What's can be done with the issue?
  21. Eric Merriman 2019-05-21

    Hello [~josh.mocek] - We have the ticket created for TIMOB-26777, and this can be used to track the bluetooth keyboard connection issue. This will be out in SDK 8.0.2 which should be our next release. I will close this ticket since you shouldn't need the restart functionality and since that API is intended only for live view use. If you'd like we can let you know when we have a pre-release candidate of 8.0.2 for you to check the function with. This should be within days. If you disagree with our course of action, please let me know.

JSON Source