New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-24702] Android: Fix onDestroy dispatchCallback #9096
Conversation
@garymathews, you need to check if the getAppRootOrCurrentActivity() or getAppCurrentActivity() methods return null in the handleMessage() method. The reason is because an Android Handler's dispatched/posted message/runnable can still be invoked on the main UI thread even if there is no UI/activity being displayed... and you can't assume a handler's runnable/message has been invoked on-time. That is, a Handler is not bound to an active activity. You can post a message/runnable via a handler to be invoked say 1 minute later, back out of all activities, and that posted message/runnable will still be received/invoked while the app is in the background without any UI. This is normal behavior on Android. |
@@ -296,7 +296,7 @@ public boolean handleMessage(Message msg) | |||
TiDimension nativeHeight = new TiDimension(v.getHeight(), TiDimension.TYPE_HEIGHT); | |||
|
|||
// TiDimension needs a view to grab the window manager, so we'll just use the decorview of the current window | |||
View decorView = TiApplication.getAppCurrentActivity().getWindow().getDecorView(); | |||
View decorView = TiApplication.getAppRootOrCurrentActivity().getWindow().getDecorView(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard for null result from getAppRootOrCurrentActivity()
@@ -326,7 +326,7 @@ public boolean handleMessage(Message msg) | |||
TiDimension nativeTop = new TiDimension(position[1], TiDimension.TYPE_TOP); | |||
|
|||
// TiDimension needs a view to grab the window manager, so we'll just use the decorview of the current window | |||
View decorView = TiApplication.getAppCurrentActivity().getWindow().getDecorView(); | |||
View decorView = TiApplication.getAppRootOrCurrentActivity().getWindow().getDecorView(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard for null result from getAppRootOrCurrentActivity()
@ypbnv Updated PR NOTE: I added the guards for safety, but I don't believe
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CR: Pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FR Passed application no longer crashes when accessing 'size' & 'rect' button properties after activity.finish().
Test Steps
- Downloaded the SDK Build from this PR
- Created a new Titanium project
- Copied the the test case from description
- Ran the application
- Pressed
Close
- Window closed without any issues
Test Environment
Appcelerator Command-Line Interface, version 6.2.2
Google Nexus 6P (7.1.1)
Operating System Name: Mac OS X El Capitan
Operating System Version: 10.11.6
Node.js Version: 6.10.1
Xcode: 8.2
Appcelerator Studio: 4.9.0.201705251638
TiBaseActivity
dispatchCallback
TiViewProxy
MSG_GETSIZE
andMSG_GETRECT
JIRA Ticket