[android-developers] Re: finish() at onStop causes ANR
It is true that the documentation does not specifically forbid calling finish() from onStop(). But then what documentation does document ALL the things you are not supposed to do? None that I know of. Still, I have to suspect that TreKing is right, even if the documentation does not clearly support him. This is because it is really too clear that yours is an unexpected usage. Very unexpected. Normally, one would never bother calling finish() from onStop(), since 1) that part of lifecycle management is already handled by the system, which does well enough and 2) finish() does the same thing as pressing the Back key, which of course can only happen while the Activity is in the Foreground Process. Yet you are calling the finish() API from the Background Process. Again, this is no proof that it is wrong, just a strong indicator. But that together with what you already showed, that the ANR happens from mKeyWaiter implies that finish() really was expecting to still have user input focus, which no Background Process has. On Jul 31, 7:30 pm, James Wang jameswangc...@gmail.com wrote: @TreKing Thanks for your replies. We do have some reasons to call finish because Android did not finish one when another is shown before it.Probably, but with your code, not Android. Document does not say finish is not allowed to be called at onStop. How to explain there is no problem with calling finish just after startActivity. @Dianne Thanks for your replies. We do believe it is a problem with framework. WindowManagerService.java: private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) { if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG, dispatchPointer + ev); if (MEASURE_LATENCY) { lt.sample(3 Wait for last dispatch , System.nanoTime() - qev.whenNano); } Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, ev, true, false, pid, uid); When calling finish() after startActivity, mKeyWaiter.waitForNextEventTarge returns activity A. And after checking A.isVisibleLW(), the key up event is discarded successfully. When calling finish() at onStop, ANR happens in mKeyWaiter.waitForNextEventTarge and it is seems never get out. James -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: finish() at onStop causes ANR
Again, get the stack crawls. This discussion is fairly pointless without at least having the stack crawls of the app when it ANRed. As for calling finish() in onStop() -- you can call finish() at any time. (Well, not after onDestroy().) And in fact it would be hard for doing this in onStop() to directly cause an ANR, since by this time the activity that is executing onStop() no longer has input focus so *can't* ANR because of something happening then. mKeyWaiter.waitForNextEventTarget not returning... well, yeah, that is what happens when there is an ANR. The window manager has dispatched an event, is waiting for the application to process it, and ends up waiting for more than 5 seconds. ANR. That's what that function is doing. On Sat, Jul 31, 2010 at 7:30 PM, James Wang jameswangc...@gmail.com wrote: @TreKing Thanks for your replies. We do have some reasons to call finish because Android did not finish one when another is shown before it. Probably, but with your code, not Android. Document does not say finish is not allowed to be called at onStop. How to explain there is no problem with calling finish just after startActivity. @Dianne Thanks for your replies. We do believe it is a problem with framework. WindowManagerService.java: private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) { if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG, dispatchPointer + ev); if (MEASURE_LATENCY) { lt.sample(3 Wait for last dispatch , System.nanoTime() - qev.whenNano); } Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, ev, true, false, pid, uid); When calling finish() after startActivity, mKeyWaiter.waitForNextEventTarge returns activity A. And after checking A.isVisibleLW(), the key up event is discarded successfully. When calling finish() at onStop, ANR happens in mKeyWaiter.waitForNextEventTarge and it is seems never get out. James -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: finish() at onStop causes ANR
@TreKing Thanks for your replies. We do have some reasons to call finish because Android did not finish one when another is shown before it. Probably, but with your code, not Android. Document does not say finish is not allowed to be called at onStop. How to explain there is no problem with calling finish just after startActivity. @Dianne Thanks for your replies. We do believe it is a problem with framework. WindowManagerService.java: private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) { if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG, dispatchPointer + ev); if (MEASURE_LATENCY) { lt.sample(3 Wait for last dispatch , System.nanoTime() - qev.whenNano); } Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, ev, true, false, pid, uid); When calling finish() after startActivity, mKeyWaiter.waitForNextEventTarge returns activity A. And after checking A.isVisibleLW(), the key up event is discarded successfully. When calling finish() at onStop, ANR happens in mKeyWaiter.waitForNextEventTarge and it is seems never get out. James -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en