Skip to content
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

Merged
merged 2 commits into from Jul 14, 2017

Conversation

garymathews
Copy link
Contributor

  • Fix TiBaseActivity dispatchCallback
  • Fix TiViewProxy MSG_GETSIZE and MSG_GETRECT
var win = Titanium.UI.createWindow(),
    btn = Ti.UI.createButton({
        title: 'CLOSE'
    });

btn.addEventListener('click', function(e) {
	var activity = Ti.Android.currentActivity;
	if (!activity) {
		return;
	}

	activity.onDestroy = function(e) {
		var size = btn.size;
		var rect = btn.rect;
	};
	activity.finish();
});

win.add(btn);
win.open();

JIRA Ticket

@garymathews garymathews added this to the 6.2.0 milestone May 30, 2017
@garymathews garymathews requested a review from ypbnv May 30, 2017 11:06
@jquick-axway
Copy link
Contributor

@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();

Copy link
Contributor

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();

Copy link
Contributor

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()

@garymathews
Copy link
Contributor Author

garymathews commented Jul 5, 2017

@ypbnv Updated PR

NOTE: I added the guards for safety, but I don't believe getAppRootOrCurrentActivity() would ever return null. The root activity must be alive until the app is terminated.

Copy link
Contributor

@ypbnv ypbnv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: Pass

Copy link
Contributor

@ssjsamir ssjsamir left a 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

@ssjsamir ssjsamir merged commit 1a64f65 into tidev:master Jul 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants