Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Android] Only post DisableTimer to the queue if it's not on the UI thread #4866

Merged
merged 1 commit into from
Jan 10, 2019

Conversation

hartez
Copy link
Contributor

@hartez hartez commented Dec 27, 2018

Description of Change

PR #4177 attempts to fix an issue with disabling the Android timer on a non-UI thread by using BeginInvokeOnMainThread, which posts the action to the main looper to be run later on the UI thread.

But if the call to DisableTimer is happening because the Ticker itself has finished all of the pending actions, DisableTimer needs to be called immediately in order to end the animations so that awaited animation calls can return. Since the animations are running on the UI thread to begin with, these calls to DisableTimer are already on the UI thread; they don't need to be posted there for later invocation.

This change adds a check in DisableTimer to see if it's already on the UI thread; if so, it is executed immediately. Otherwise, it is posted to the UI thread.

Issues Resolved

  • fixes bug where awaited animations never finish (UI Test 39821)

API Changes

None

Platforms Affected

  • Android

Behavioral/Visual Changes

None

Before/After Screenshots

Not applicable

Testing Procedure

Run UI Test 39821; without the fix, it will never finish (i.e., the "Success" label will never be displayed).

PR Checklist

  • Has automated tests
  • Rebased on top of the target branch at time of PR
  • Changes adhere to coding standard

@hartez hartez changed the title Only post DisableTimer to the queue if it's not on the UI thread [Android] Only post DisableTimer to the queue if it's not on the UI thread Dec 27, 2018
@samhouts samhouts added this to In Review in v3.6.0 Dec 28, 2018
@hartez
Copy link
Contributor Author

hartez commented Dec 31, 2018

API 19 tests are failing on the 41424 test; nothing to do with this change, and fixed by e9274c0 when that gets merged into master.

@samhouts samhouts added this to In progress in Sprint 146 via automation Jan 2, 2019
@samhouts samhouts added the e/1 🕐 1 label Jan 2, 2019
Sprint 146 automation moved this from In progress to Ready for Review (PRs) Jan 3, 2019
Copy link
Contributor

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

I know this may break something, but would it be better to put this logic inside the begin invoke? Why is being requested here is to run something on the main thread... Shouldn't the method itself first check? Wouldn't that be an improvement everywhere?

@hartez
Copy link
Contributor Author

hartez commented Jan 4, 2019

would it be better to put this logic inside the begin invoke?

Which bit do you mean when you say "this logic"?

@mattleibow
Copy link
Contributor

The logic for if on main then run else use invoke. Basically the if check.

@hartez
Copy link
Contributor Author

hartez commented Jan 7, 2019

The logic for if on main then run else use invoke. Basically the if check.

Oh, I get what you're saying. So changing the Android implementation of BeginInvokeOnMainThread to something like

if(IsInvokeRequired) { 
    s_handler.Post(action); 
} else {
    action(); // we're already on the main thread, just go ahead a run it instead of posting to the queue
}

That would definitely break a few things. Most notably around layout, where there's logic which depends on putting the full layout pass onto queue. There are a couple of other places in the Android renderers which rely on that behavior (letting current operations finish before continuing).

It would also make Android behave very differently from iOS and UWP (and presumably the other platforms); they also post the action to the queue to be run later.

@rmarinho rmarinho merged commit 23ee5a3 into master Jan 10, 2019
v3.6.0 automation moved this from In Review to Done Jan 10, 2019
andreinitescu pushed a commit to andreinitescu/Xamarin.Forms that referenced this pull request Jan 29, 2019
@samhouts samhouts added this to Done in v4.0.0 Feb 2, 2019
@samhouts samhouts removed this from Done in v3.6.0 Feb 2, 2019
@samhouts samhouts modified the milestone: 4.0.0 Feb 6, 2019
@samhouts samhouts added this to the 3.6.0 milestone Feb 6, 2019
@samhouts samhouts removed this from Done in v4.0.0 Feb 7, 2019
@samhouts samhouts added this to Done in v3.6.0 Feb 7, 2019
@hartez hartez deleted the fix-android-disabletimer branch February 24, 2019 18:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Sprint 146
  
Ready for Review (PRs)
v3.6.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants