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 <[email protected]> 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

