Problem
This issue occurs in an app that I have made but is also occurring in the 5.2.0 Sample app (
https://github.com/appcelerator-developer-relations/appc-sample-ti520 ).
This issue occurs when the app is launched and put in to the background, after multiple other apps are used if the app is launched from the android launcher or by selecting the app from the back-grounded app list the splash screen for the app will briefly show followed by what looks like the app closing and then re-opening.
All state for the app is lost and while the relaunch is happening the user sees their launcher icons as if the app has crashed.
This may be happening due to the app being paused or closed due to memory management but ideally the main window should show while the relaunch happens and not the launcher icons.
Test case
Install on device
Open the sample app
Background the sample app
Open other applications and switch between them until some of them start to relaunch on resume
Foreground the sample app and the bug should be recreated
Video showing relaunch behaviour
https://streamable.com/x4th
What exactly do you mean by _until some of them start to relaunch on resume_? I can't get that to happen on a Nexus 5.
Hi @Fokke Zandbergen Hard to explain but when you have many apps open some of the apps reload when you foreground them, generally when this happens it triggers the bug for the titanium app. I made a quick video showing the behaviour when the bug occurs: https://streamable.com/x4th
I am not able to reproduce this issue. I created the sample app from the [link](https://github.com/appcelerator-developer-relations/appc-sample-ti520). Open the app and then backgrounded the app. And, I switched to some other apps. After that I reopen the sample app and it did open smoothly. The app resumed from the state as it was when I backgrounded the app. It did not launched showing the splash screen. *Environment*: *Device info:* Nexux7 (android 6.0.1) *Node.js Version:* 0.12.7 *npm Version:* 2.11.3 *Titanium SDKs:* 5.2.0.v20160220080449 and 5.1.2.GA *Java Development Kit Version:* 1.8.0_73 *Titanium CLI Version:* 5.0.5
To recreate this issue you will have to continuously open backgrounded apps until those apps open then quickly relaunch their main window. After this occurs with 3-4 different apps you then try to unbackground the appcelerator app and it will open, crash then relaunch the window as shown in the video. This may seem like an edge case, but after using your device all day this behavior becomes quite common over an extended period of time. Therefore relaunching an app that does not receive frequent use, suddenly it feels like the app has to open / crash / relaunch every time you try to use it. This behavior does not seem to occur when the device is charging, which makes it difficult to record a video of the entire process.
[~lukeda] unfortunately I also cannot get any backgrounded apps to relaunch when I reopen them. If you have any more leads, like an error log or something we can reopen.
Hello, This looks to me a device memory issue. Over an extended period of time if you put an app in the background, Relaunching the app forgot it's initial stage and start from it's home page. Though I can't generate the issue, as the reported said that the app crashes and relaunch. Any crush or error logs would be helpfull. Thanks.
Same problem here and I was able to get a log:
It is not happening all the time but even with 5.2.2.GA I can reproduce it after a while. Android 6.0.1 (HTC A9) Android 5.1.1 (Nexus 4) Doesn't happen with "non-Titanium" apps as far as I can say. But I'll keep an eye on that too
I am also seeing this as in Michael G's log but I am building with Ti SDK 5.3.0 and testing on a Nexus 7 under Android 6.0.1 Is it simply the OS reclaiming memory? What would we expect to see in a log under those circumstances? The error message 'Runtime has been disposed or app has been killed. Finishing.' is coming from TiBaseActivity.java described as being in response to: // If all the activities has been killed and the runtime has been disposed or the app's hosting process has // been killed, we cannot recover one specific activity because the info of the top-most view proxy has been // lost (TiActivityWindows.dispose()). In this case, we have to restart the app. Which seems a bit of a catch-all. Can anybody enlighten us?
I'm seeing this too and I'm not sure exactly what's happening. Anyone figure anything out?
Another issue I'm seeing with this - it seems like on older versions of Android the restart actually works without the user seeing a crash dialog, but in newer versions of Android, from what I'm seeing in 7.0 crash reports, the restart doesn't even work and it instead results in a visible app crash with the very non-descriptive crash report "Native crash at /data/app/com.hexicallabs.devrant-1/lib/arm/libkroll-v8.so"
An update - I'm trying to come up with a patch for the restart functionality Michael pointed out to stop the crash from occurring during restart. If anyone has any ideas, please let me know and I'm happy to modify the code, compile, test and contribute back anything that works. So far I've tried increasing the restart delay, removing savedInstanceState in onCreate, and a few other things, but haven't had any luck at preventing the crash from occurring. By the way, I found an easy way to reproduce it in the emulator for those who have had trouble (I'm using a Nexus 5X emulator running Android 7). I just set the device memory to something low, like 600mb for example. Open the app, then background it and start opening a bunch of other apps. When you back to your app and the OS has tried to kill, Titanium attempts an app restart which fails and the user sees a crash. The behavior mimics what my users are seeing on their devices. Any help is appreciated.
Output of 6.0.0.v20161005072811 Problem still exists: {noformat} I/ActivityManager(4384): Start proc 4804:com.miga.podstars/u0a172 for activity com.miga.podstars/org.appcelerator.titanium.TiActivity I/TiApplication(4804): (main) [0,0] checkpoint, app created. I/TiApplication(4804): (main) [62,62] Titanium 6.0.0 (2016/10/05 07:28 undefined) I/TiApplication(4804): (main) [78,140] Titanium Javascript runtime: v8 W/TiBaseActivity(4804): (main) [30,170] Runtime has been disposed or app has been killed. Finishing. W/TiApplication(4804): (main) [27,197] Scheduling application restart D/ActivityManager(4384): screenshot for ActivityRecord{5cd3572 u0 com.miga.podstars/.PodstarsActivity t15232 f}, bitmap=null, time = 0 E/BufferQueueProducer(515): [Starting com.miga.podstars] queueBuffer: BufferQueue has been abandoned E/Surface(4384): queueBuffer: error queuing buffer to SurfaceTexture, -19 E/Surface(4384): queueBuffer (handle=0x556673b150) failed (No such device) E/ViewRootImpl(4384): Could not unlock surface E/ViewRootImpl(4384): java.lang.IllegalArgumentException E/ViewRootImpl(4384): at android.view.Surface.nativeUnlockCanvasAndPost(Native Method) E/ViewRootImpl(4384): at android.view.Surface.unlockSwCanvasAndPost(Surface.java:301) E/ViewRootImpl(4384): at android.view.Surface.unlockCanvasAndPost(Surface.java:282) E/ViewRootImpl(4384): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2884) E/ViewRootImpl(4384): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2787) E/ViewRootImpl(4384): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2564) E/ViewRootImpl(4384): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2164) E/ViewRootImpl(4384): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1174) E/ViewRootImpl(4384): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6241) E/ViewRootImpl(4384): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:873) E/ViewRootImpl(4384): at android.view.Choreographer.doCallbacks(Choreographer.java:676) E/ViewRootImpl(4384): at android.view.Choreographer.doFrame(Choreographer.java:606) E/ViewRootImpl(4384): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:859) E/ViewRootImpl(4384): at android.os.Handler.handleCallback(Handler.java:739) E/ViewRootImpl(4384): at android.os.Handler.dispatchMessage(Handler.java:95) E/ViewRootImpl(4384): at android.os.Looper.loop(Looper.java:168) E/ViewRootImpl(4384): at android.os.HandlerThread.run(HandlerThread.java:61) E/ViewRootImpl(4384): at com.android.server.ServiceThread.run(ServiceThread.java:46) W/WindowManager(4384): Failed looking up window W/WindowManager(4384): java.lang.IllegalArgumentException: Requested window android.view.ViewRootImpl$W@dbc7fa7 does not exist W/WindowManager(4384): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8975) W/WindowManager(4384): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8966) W/WindowManager(4384): at com.android.server.wm.WindowManagerService.finishDrawingWindow(WindowManagerService.java:3540) W/WindowManager(4384): at com.android.server.wm.Session.finishDrawing(Session.java:232) W/WindowManager(4384): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2613) W/WindowManager(4384): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2164) W/WindowManager(4384): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1174) W/WindowManager(4384): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6241) W/WindowManager(4384): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:873) W/WindowManager(4384): at android.view.Choreographer.doCallbacks(Choreographer.java:676) W/WindowManager(4384): at android.view.Choreographer.doFrame(Choreographer.java:606) W/WindowManager(4384): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:859) W/WindowManager(4384): at android.os.Handler.handleCallback(Handler.java:739) W/WindowManager(4384): at android.os.Handler.dispatchMessage(Handler.java:95) W/WindowManager(4384): at android.os.Looper.loop(Looper.java:168) W/WindowManager(4384): at android.os.HandlerThread.run(HandlerThread.java:61) W/WindowManager(4384): at com.android.server.ServiceThread.run(ServiceThread.java:46) W/WindowManager(4384): Failed looking up window W/WindowManager(4384): java.lang.IllegalArgumentException: Requested window android.view.ViewRootImpl$W@dbc7fa7 does not exist W/WindowManager(4384): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8975) W/WindowManager(4384): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8966) W/WindowManager(4384): at com.android.server.wm.WindowManagerService.finishDrawingWindow(WindowManagerService.java:3540) W/WindowManager(4384): at com.android.server.wm.Session.finishDrawing(Session.java:232) W/WindowManager(4384): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2613) W/WindowManager(4384): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2164) W/WindowManager(4384): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1174) W/WindowManager(4384): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6241) W/WindowManager(4384): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:873) W/WindowManager(4384): at android.view.Choreographer.doCallbacks(Choreographer.java:676) W/WindowManager(4384): at android.view.Choreographer.doFrame(Choreographer.java:606) W/WindowManager(4384): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:859) W/WindowManager(4384): at android.os.Handler.handleCallback(Handler.java:739) W/WindowManager(4384): at android.os.Handler.dispatchMessage(Handler.java:95) W/WindowManager(4384): at android.os.Looper.loop(Looper.java:168) W/WindowManager(4384): at android.os.HandlerThread.run(HandlerThread.java:61) W/WindowManager(4384): at com.android.server.ServiceThread.run(ServiceThread.java:46) W/InputMethodManagerService(4384): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@164484a attribute=EditorInfo { packageName=com.google.android.googlequicksearchbox, inputType=0x0, imeOptions=0x0, privateImeOptions=null }, token = android.os.BinderProxy@a57c0f9, client pid=2945, inputType=0x0 E/InputEventReceiver(4384): Looper::removeFd(407) is failed, result(0), input channel 'a516c54 Starting com.miga.podstars (client)' W/WindowManager(4384): Failed looking up window W/WindowManager(4384): java.lang.IllegalArgumentException: Requested window android.view.ViewRootImpl$W@dbc7fa7 does not exist W/WindowManager(4384): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8975) W/WindowManager(4384): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8966) W/WindowManager(4384): at com.android.server.wm.WindowManagerService.removeWindow(WindowManagerService.java:2755) W/WindowManager(4384): at com.android.server.wm.Session.remove(Session.java:187) W/WindowManager(4384): at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:3244) W/WindowManager(4384): at android.view.ViewRootImpl.doDie(ViewRootImpl.java:5821) W/WindowManager(4384): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3576) W/WindowManager(4384): at android.os.Handler.dispatchMessage(Handler.java:102) W/WindowManager(4384): at android.os.Looper.loop(Looper.java:168) W/WindowManager(4384): at android.os.HandlerThread.run(HandlerThread.java:61) W/WindowManager(4384): at com.android.server.ServiceThread.run(ServiceThread.java:46) I/ActivityManager(4384): Start proc 4836:com.google.process.gapps/u0a16 for content provider com.google.android.gsf/.gservices.GservicesProvider W/System(4836): ClassLoader referenced unknown path: /system/priv-app/GoogleServicesFramework/lib/arm64 W/V8Object(4804): (KrollRuntimeThread) [546,743] Runtime disposed, cannot set property 'userAgent' I/MemoryTrimmer(4794): Trimming objects from memory, since app is in the background. I/ActivityManager(4384): Start proc 4859:com.google.android.partnersetup/u0a20 for content provider com.google.android.partnersetup/.RlzAppProvider E/lowmemorykiller(512): Error writing /proc/4691/oom_score_adj; errno=22 E/JavaBinder(4384): !!! FAILED BINDER TRANSACTION !!! (parcel size = 76) I/ActivityManager(4384): Recipient 4691 E/InputEventReceiver(5753): Looper::removeFd(41) is failed, result(0), input channel 'ClientState{8683c1b uid 10391 pid 4691} (client)' W/System(4859): ClassLoader referenced unknown path: /system/priv-app/GooglePartnerSetup/lib/arm64 W/ActivityManager(4384): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x4 cmp=com.miga.podstars/.PodstarsActivity (has extras) } I/TiRootActivity(4804): (main) [0,0] checkpoint, on root activity create, savedInstanceState: null I/TiApplication(4804): (main) [1,1] Analytics have been disabled I/ActivityManager(4384): START u0 {cmp=com.miga.podstars/org.appcelerator.titanium.TiActivity (has extras)} from uid 10172 pid 4804 on display 0 I/TiRootActivity(4804): (main) [0,0] checkpoint, on root activity resume. activity = com.miga.podstars.PodstarsActivity@ef48ad4 D/Window(4804): Checkpoint: postWindowCreated() I/ActivityManager(4384): Displayed com.miga.podstars/org.appcelerator.titanium.TiActivity: +222ms (total +6s260ms) {noformat} Some patches have been applied here: https://github.com/appcelerator/titanium_mobile/pull/8472 for other start/resume issues but they didn't have any impact on this issue
I can confirm that SDK 5.5.1(Windows) still has this problem. Tested with TODO app from appcelerator. Also on my own app. Crashes. It works fine on first launch but if you switch between other (memory consuming apps) then back to titanium app it will crash on resume from task swicher window [(image from internet)](http://www.androidpolice.com/wp-content/uploads/2014/10/nexus2cee_43.png) Phone LG G2 mini, Android 5.0.2
We are seeing this same issue with a large production app using Ti 6.0.X.
Still doing some more debugging here and finally recorded a video of the problem: http://www.migaweb.de/video.mp4 happens with all Titanium apps sooner or later. * App is running * putting it into background (not closing it!) * running some other apps * returning to the Ti app will open it, close it, wait 5 sec and restart it! I've added some logs (sorry its getting very messy now :-) ) in the TiBaseActivity and TiLaunchActivity to see whats going on and had a look at
isUnsupportedReLaunch
since that decides if it failed. *Normal start of an app:* * isUnsupportedReLaunch: null || com.miga.bs.appActivity@f3cbe7b || true || 0 * isUnsupportedReLaunch: null || com.miga.bs.appActivity@f3cbe7b || true || 0 * isUnsupportedReLaunch: null || com.miga.bs.appActivity@f3cbe7b || true || 0 * I/RESTART start(21793): start * I/RESTART resume(21793): resume * I/RESTART base(21793): resume * I/RESTART pause(21793): pause * isUnsupportedReLaunch: null || org.appcelerator.titanium.TiActivity@2561c2f || false || 0 * I/RESTART base(21793): resume * I/RESTART CHECK(21793): base stop isUnsupportedReLaunch is checked 4 times (values aresavedInstanceState + " || " + activity + " || " + KrollRuntime.isDisposed() + " || " + TiApplication.getInstance().rootActivityLatch.getCount()}
) *Normal resume:* * I/RESTART base(21793): restart * I/RESTART base(21793): resume *Here is the resume when the crash happens:* * 11:58:57.693: I/RESTART CHECK(21793): base stop * 11:59:08.586: isUnsupportedReLaunch: || org.appcelerator.titanium.TiActivity@a466377 || true || 1 (<---- 1) * 11:59:10.618: I/RESTART destroy(23153): destroy * 11:59:10.618: I/RESTART destroy(23153): isRestartPending * 11:59:15.714: isUnsupportedReLaunch: null || com.miga.bs.appActivity@3469c82 || false || 1 * 11:59:15.720: isUnsupportedReLaunch: null || com.miga.bs.appActivity@3469c82 || false || 0 * 11:59:15.721: isUnsupportedReLaunch: null || com.miga.bs.appActivity@3469c82 || false || 0 * 11:59:16.561: I/RESTART start(23153): start * 11:59:16.564: I/RESTART resume(23153): resume * 11:59:16.564: I/RESTART base(23153): resume * 11:59:16.578: I/RESTART pause(23153): pause * 11:59:16.594: isUnsupportedReLaunch: null || org.appcelerator.titanium.TiActivity@6a45fbb || false || 0 * 11:59:17.055: I/RESTART base(23153): resume * 11:59:17.801: I/RESTART CHECK(23153): base stop As you can see by the times: you have a 5 sec gap between onDestroy/isRestartPending and the relaunch. This is here: https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/TiLaunchActivity.java#L446 After the isRestartPending it is doing the normal "app start" routine. So the resume is not starting with restart/resume but with a onStop from n the TiBaseActivity. I know that the android system is allowed to kill apps in background but it is very annoying if the restart looks like this: starting the app, leave a white screen, close it, wait 5sec, restart it. If it would just do the restart it would be perfectly fine (ok, better if it would just resume it :-) ) *One other thing I've noticed*: when the app starts the fist time (so right after ti build and deploy) it will resume like this: * I/RESTART base(21793): restart * I/RESTART base(21793): resume * I/RESTART destroy(21793): destroy * I/RESTART destroy(21793): finishing2373 so it is going into onDestroy (TiLaunchActivity) with finishing2373=true all the time! Once I close it with the back button (destroy and onStop in BaseActivity) it will run the logs above so without destroy and finishing2373! Edit: This is the commit that introduced the restart from an unsupported state in 2012: https://github.com/appcelerator/titanium_mobile/commit/64f9a05fb80e44bcc2dffd88f67da204ec26cf15Testing https://github.com/appcelerator/titanium_mobile/pull/8843 results in a quicker restart but also leads to this crash when closing a restarted app:
[~michael] Thanks for looking into this! I'll see what else I can find.
Our apps have suffered for years from *exactly* the same behavior Michael G captured in his video. It has been a minor annoyance, since it usually resulted in a quick "flash", and then the app would start from splash screen. I think most users probably don't even know that anything bad has happened. It was just an aesthetic problem. Lately, however, android is popping up dialogs saying that the app has stopped, requiring the user to tap a "restart" button. I don't know if this is something that has happened in newer android versions (I see it on Nougat, and it seems like the problem started either with my phone updating to Nougat, or our app updating to Ti SDK version 6.x.x). This bug is extremely hard to reproduce, but if you use the app 4 or 5 times a day, it will happen at least every other day. It's just very hard to *make* it happen for debugging purposes. But it is *very* real, and if these restart dialogs can't be fixed, it will present a serious UX problem for our android users.
[~jpriebe] doesn't that "restart" dialog appear when the app is not responding (e.g. freezing, too much work): "app is not responding - wait / restart"? Or a different dialog? I'm not seeing that popup in my tests but I have the same problem that it is very hard to reproduce it and takes some time. About the restart: Not sure if you follow the Github PR: https://github.com/appcelerator/titanium_mobile/pull/8843 It's much better with the latest [bugfix](https://github.com/appcelerator/titanium_mobile/pull/8843#issuecomment-289566096)
Michael - it's not happening during any freezing or hard work (we don't block the UI or do anything computationally intensive in our app anyway). This happens when the app is foregrounded (usually after it has been in the background for a while). I will try to screencap the dialog so you can see exactly what it says. I will look into the PR; thanks for the tip. BTW -- I tried to use the "user mention" feature of the comments editor, and it's not working for me. But you seem to be following this pretty closely.
The "user mention" button is wrong ;) It is
Hope you can create a screenshot/-capture. And perhaps try a 6.1 nightly build to see if that works better. There are many useful patches (and the latest PR aren't even in yet)
[~michael] - I got a screenshot. App had been in background for several hours. I opened the app, and I briefly saw the contents of the app, it crashed and restarted immediately. Saw the splash screen, and then it shut down again, presenting this dialog. !http://i.imgur.com/fYPZzb4.png! I didn't have access to a debugger at the time, so I don't have any logs, but I've looked at the logs in the past when this happens, and I haven't seen anything obvious. There's some information about Android N's crash handling [here](http://www.androidpolice.com/2016/03/10/android-n-feature-spotlight-new-force-close-pop-up-has-reset-and-restart-and-mute-until-device-restarts-options/). The article doesn't specifically say that the "restart app / send feedback" dialog is new in Android N, but I really feel like these dialogs only started coming up when I upgraded my phone to Nougat.
This is exactly what is happening to all our users on Android 7.x+. I also see a pull request that is being blocked here https://github.com/appcelerator/titanium_mobile/pull/8843 When will this be in and can we get an emergency patch to Ti SDK 6.0.x? Here is the stack trace when users send the crash as feedback to Google Play
[~gmathews] Hey Gary do we have any update on this ticket?
BTW -- still happening with SDK version 6.0.3.
[~gmathews] - I don't think that issue is the same as what I'm seeing. I see this happen all the time, and I've never once taken permissions away from the app while it was backgrounded. I built our app with 6.0.4 a couple of days ago; I will report back on what happens with 6.0.4. (btw - if you read the previous edit of this post, I *thought* I was running the app with 6.0.4, but apparently my phone did not have the build from a couple of days ago. I will install that now and see what happens).
It might be too early to be sure, but so far, with 6.0.4, things seem better. Over the past few days, I have been launching our app, leaving it in the background for an hour or two, and then resuming it. Most importantly, I'm not getting the "app has stopped" dialogs, but even better, I'm not getting the quick "flash" of an auto-restart. I don't exactly understand how a fix for TIMOB-24265 could have fixed this, but initial results are certainly encouraging.
[~jpriebe] its been a year since you reported it might looked fixed. Can you still confirm it does?
I have not seen this problem since 6.0.4.
Titanium's app resume and intent handling has been rewritten by [TIMOB-26075] in of 8.0.0. This change will fix this issue. Closing.