Remove unnecessary Task.Run from androidtest template#11339
Merged
simonrozsival merged 1 commit intoMay 14, 2026
Conversation
OnStart() is an instrumentation callback (not UI-thread bound) and the work is already async, so the Task.Run just adds an unnecessary thread pool hop and allocation. Making OnStart async void is appropriate here since it is a framework callback with comprehensive try/catch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR simplifies the androidtest template instrumentation startup path by removing an unnecessary Task.Run wrapper around already-async test execution work.
Changes:
- Changes
OnStart()toasync void, matching the framework callback pattern. - Moves the existing async test setup/run/reporting logic directly into
OnStart(). - Preserves existing try/catch handling and result bundle reporting.
jonathanpeppers
added a commit
that referenced
this pull request
May 14, 2026
Run tests directly on the instrumentation thread instead of a .NET thread pool thread. Java.Lang.JavaSystem.LoadLibrary and Runtime.Load both use the calling thread's ClassLoader to resolve native library paths. On a thread pool thread there are no Java frames on the stack, so the ClassLoader is null and app-private .so files cannot be found. This matches the approach in PR #11339 for the androidtest template. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
simonrozsival
approved these changes
May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
OnStart()in theandroidtesttemplate wrapped all its async work inTask.Run(async () => { ... }). This is unnecessary becauseOnStart()is an instrumentation callback -- not a UI-thread method -- and the work inside is already async. TheTask.Runjust adds an extra thread pool hop and allocation for no benefit.This change makes
OnStartanasync voidmethod directly, which is the appropriate pattern for framework callbacks that have comprehensive try/catch error handling.