Flutter plugin async and threadWhat is the difference between a process and a thread?“implements Runnable” vs “extends Thread” in JavaAsynchronous vs Multithreading - Is there a difference?How do I update the GUI from another thread?What is a daemon thread in Java?How to use threading in Python?How and when to use ‘async’ and ‘await’async await blocking ui wp8What is the difference between asynchronous programming and multithreading?C# Async Await never returns to main thread

Overlapping circles covering polygon

Given this phrasing in the lease, when should I pay my rent?

Personal or impersonal in a technical resume

How were servants to the Kaiser of Imperial Germany treated and where may I find more information on them

"Oh no!" in Latin

Isometric embedding of a genus g surface

When and why was runway 07/25 at Kai Tak removed?

Deciphering cause of death?

Check if object is null and return null

ContourPlot — How do I color by contour curvature?

In One Punch Man, is King actually weak?

How do I tell my boss that I'm quitting in 15 days (a colleague left this week)

How to reduce predictors the right way for a logistic regression model

Has the laser at Magurele, Romania reached a tenth of the Sun's power?

Is there a RAID 0 Equivalent for RAM?

How to preserve electronics (computers, iPads and phones) for hundreds of years

What happens if I try to grapple an illusory duplicate from the Mirror Image spell?

How do I prevent inappropriate ads from appearing in my game?

Why the "ls" command is showing the permissions of files in a FAT32 partition?

Alignment of six matrices

Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?

Is there anyway, I can have two passwords for my wi-fi

PTIJ: Which Dr. Seuss books should one obtain?

Mimic lecturing on blackboard, facing audience



Flutter plugin async and thread


What is the difference between a process and a thread?“implements Runnable” vs “extends Thread” in JavaAsynchronous vs Multithreading - Is there a difference?How do I update the GUI from another thread?What is a daemon thread in Java?How to use threading in Python?How and when to use ‘async’ and ‘await’async await blocking ui wp8What is the difference between asynchronous programming and multithreading?C# Async Await never returns to main thread













0















I have a flutter app that calls into a Java plugin using methodchannel.



I'm trying to understand the thread model and async behavior. So the order is like this...
A UI event handler calls await methodchannel.invoke("Foo", params). Which transfer control to the Java method call handler. There I reply.success to unblock the await in dart. The await returns and flutter UI event handler returns.



In the Java plugin I continue to the some more work after result.sucess. Say for another 2seconds.



The problem is (my question) during that 2 seconds, the dart main thread/UI is blocked, even though the flutter event handler had returned 2 seconds ago? Why is that? I can see from my logcat that dart and Java code are running in two separate threads. Your answer is appreciated.










share|improve this question
























  • Hmm, I'm skeptical of the problem you're describing. What you have described is true, and all Dart code is async, and Dart and Java run all different thread, thus except if Dart is doing something CPU-heavy, it should not block main thread/UI.

    – TruongSinh
    Mar 7 at 4:25












  • I am pretty sure you are doing something weird, if this is really happening. Also, don't return a fake success. The callbacks are all asynchronous, and are meant to provide real results.. if you don't want your dart code to "block" just don't await .. you can handle the result using future's then callback, or await in another isolate.

    – herbert
    Mar 7 at 6:23












  • post your java code: most likely you are somehow blocking the UI main thread there

    – pskink
    Mar 7 at 6:50











  • I haven't done anything with plugins myself yet, but await itself does not block the UI, it only delays the execution of the code below await from being executed until the returned Future completes. Other async code can still be called (from timers, or animation triggers, or other code invoked by the framework for example depending on screen refresh rate. I don't know though if calling out to Java can block the UI thread.

    – Günter Zöchbauer
    Mar 7 at 7:00






  • 1





    See this issue - the native code runs on the native UI thread, so you shouldn't block it or you risk stalling input and other platform specific issue. The solution is to do your additional 2 seconds of work on a separate thread. (The creator of the above issue argues that you should be able to do work on the main thread, but not many people seem to agree...) The point is there's an easy work around - background thread. I thought I saw a really good diagram of the 3 main threads the other day, but now I can't find it again.

    – Richard Heap
    Mar 7 at 14:13
















0















I have a flutter app that calls into a Java plugin using methodchannel.



I'm trying to understand the thread model and async behavior. So the order is like this...
A UI event handler calls await methodchannel.invoke("Foo", params). Which transfer control to the Java method call handler. There I reply.success to unblock the await in dart. The await returns and flutter UI event handler returns.



In the Java plugin I continue to the some more work after result.sucess. Say for another 2seconds.



The problem is (my question) during that 2 seconds, the dart main thread/UI is blocked, even though the flutter event handler had returned 2 seconds ago? Why is that? I can see from my logcat that dart and Java code are running in two separate threads. Your answer is appreciated.










share|improve this question
























  • Hmm, I'm skeptical of the problem you're describing. What you have described is true, and all Dart code is async, and Dart and Java run all different thread, thus except if Dart is doing something CPU-heavy, it should not block main thread/UI.

    – TruongSinh
    Mar 7 at 4:25












  • I am pretty sure you are doing something weird, if this is really happening. Also, don't return a fake success. The callbacks are all asynchronous, and are meant to provide real results.. if you don't want your dart code to "block" just don't await .. you can handle the result using future's then callback, or await in another isolate.

    – herbert
    Mar 7 at 6:23












  • post your java code: most likely you are somehow blocking the UI main thread there

    – pskink
    Mar 7 at 6:50











  • I haven't done anything with plugins myself yet, but await itself does not block the UI, it only delays the execution of the code below await from being executed until the returned Future completes. Other async code can still be called (from timers, or animation triggers, or other code invoked by the framework for example depending on screen refresh rate. I don't know though if calling out to Java can block the UI thread.

    – Günter Zöchbauer
    Mar 7 at 7:00






  • 1





    See this issue - the native code runs on the native UI thread, so you shouldn't block it or you risk stalling input and other platform specific issue. The solution is to do your additional 2 seconds of work on a separate thread. (The creator of the above issue argues that you should be able to do work on the main thread, but not many people seem to agree...) The point is there's an easy work around - background thread. I thought I saw a really good diagram of the 3 main threads the other day, but now I can't find it again.

    – Richard Heap
    Mar 7 at 14:13














0












0








0








I have a flutter app that calls into a Java plugin using methodchannel.



I'm trying to understand the thread model and async behavior. So the order is like this...
A UI event handler calls await methodchannel.invoke("Foo", params). Which transfer control to the Java method call handler. There I reply.success to unblock the await in dart. The await returns and flutter UI event handler returns.



In the Java plugin I continue to the some more work after result.sucess. Say for another 2seconds.



The problem is (my question) during that 2 seconds, the dart main thread/UI is blocked, even though the flutter event handler had returned 2 seconds ago? Why is that? I can see from my logcat that dart and Java code are running in two separate threads. Your answer is appreciated.










share|improve this question
















I have a flutter app that calls into a Java plugin using methodchannel.



I'm trying to understand the thread model and async behavior. So the order is like this...
A UI event handler calls await methodchannel.invoke("Foo", params). Which transfer control to the Java method call handler. There I reply.success to unblock the await in dart. The await returns and flutter UI event handler returns.



In the Java plugin I continue to the some more work after result.sucess. Say for another 2seconds.



The problem is (my question) during that 2 seconds, the dart main thread/UI is blocked, even though the flutter event handler had returned 2 seconds ago? Why is that? I can see from my logcat that dart and Java code are running in two separate threads. Your answer is appreciated.







multithreading asynchronous dart flutter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 7:01









Günter Zöchbauer

332k701005940




332k701005940










asked Mar 7 at 3:18









S. VagharS. Vaghar

66113




66113












  • Hmm, I'm skeptical of the problem you're describing. What you have described is true, and all Dart code is async, and Dart and Java run all different thread, thus except if Dart is doing something CPU-heavy, it should not block main thread/UI.

    – TruongSinh
    Mar 7 at 4:25












  • I am pretty sure you are doing something weird, if this is really happening. Also, don't return a fake success. The callbacks are all asynchronous, and are meant to provide real results.. if you don't want your dart code to "block" just don't await .. you can handle the result using future's then callback, or await in another isolate.

    – herbert
    Mar 7 at 6:23












  • post your java code: most likely you are somehow blocking the UI main thread there

    – pskink
    Mar 7 at 6:50











  • I haven't done anything with plugins myself yet, but await itself does not block the UI, it only delays the execution of the code below await from being executed until the returned Future completes. Other async code can still be called (from timers, or animation triggers, or other code invoked by the framework for example depending on screen refresh rate. I don't know though if calling out to Java can block the UI thread.

    – Günter Zöchbauer
    Mar 7 at 7:00






  • 1





    See this issue - the native code runs on the native UI thread, so you shouldn't block it or you risk stalling input and other platform specific issue. The solution is to do your additional 2 seconds of work on a separate thread. (The creator of the above issue argues that you should be able to do work on the main thread, but not many people seem to agree...) The point is there's an easy work around - background thread. I thought I saw a really good diagram of the 3 main threads the other day, but now I can't find it again.

    – Richard Heap
    Mar 7 at 14:13


















  • Hmm, I'm skeptical of the problem you're describing. What you have described is true, and all Dart code is async, and Dart and Java run all different thread, thus except if Dart is doing something CPU-heavy, it should not block main thread/UI.

    – TruongSinh
    Mar 7 at 4:25












  • I am pretty sure you are doing something weird, if this is really happening. Also, don't return a fake success. The callbacks are all asynchronous, and are meant to provide real results.. if you don't want your dart code to "block" just don't await .. you can handle the result using future's then callback, or await in another isolate.

    – herbert
    Mar 7 at 6:23












  • post your java code: most likely you are somehow blocking the UI main thread there

    – pskink
    Mar 7 at 6:50











  • I haven't done anything with plugins myself yet, but await itself does not block the UI, it only delays the execution of the code below await from being executed until the returned Future completes. Other async code can still be called (from timers, or animation triggers, or other code invoked by the framework for example depending on screen refresh rate. I don't know though if calling out to Java can block the UI thread.

    – Günter Zöchbauer
    Mar 7 at 7:00






  • 1





    See this issue - the native code runs on the native UI thread, so you shouldn't block it or you risk stalling input and other platform specific issue. The solution is to do your additional 2 seconds of work on a separate thread. (The creator of the above issue argues that you should be able to do work on the main thread, but not many people seem to agree...) The point is there's an easy work around - background thread. I thought I saw a really good diagram of the 3 main threads the other day, but now I can't find it again.

    – Richard Heap
    Mar 7 at 14:13

















Hmm, I'm skeptical of the problem you're describing. What you have described is true, and all Dart code is async, and Dart and Java run all different thread, thus except if Dart is doing something CPU-heavy, it should not block main thread/UI.

– TruongSinh
Mar 7 at 4:25






Hmm, I'm skeptical of the problem you're describing. What you have described is true, and all Dart code is async, and Dart and Java run all different thread, thus except if Dart is doing something CPU-heavy, it should not block main thread/UI.

– TruongSinh
Mar 7 at 4:25














I am pretty sure you are doing something weird, if this is really happening. Also, don't return a fake success. The callbacks are all asynchronous, and are meant to provide real results.. if you don't want your dart code to "block" just don't await .. you can handle the result using future's then callback, or await in another isolate.

– herbert
Mar 7 at 6:23






I am pretty sure you are doing something weird, if this is really happening. Also, don't return a fake success. The callbacks are all asynchronous, and are meant to provide real results.. if you don't want your dart code to "block" just don't await .. you can handle the result using future's then callback, or await in another isolate.

– herbert
Mar 7 at 6:23














post your java code: most likely you are somehow blocking the UI main thread there

– pskink
Mar 7 at 6:50





post your java code: most likely you are somehow blocking the UI main thread there

– pskink
Mar 7 at 6:50













I haven't done anything with plugins myself yet, but await itself does not block the UI, it only delays the execution of the code below await from being executed until the returned Future completes. Other async code can still be called (from timers, or animation triggers, or other code invoked by the framework for example depending on screen refresh rate. I don't know though if calling out to Java can block the UI thread.

– Günter Zöchbauer
Mar 7 at 7:00





I haven't done anything with plugins myself yet, but await itself does not block the UI, it only delays the execution of the code below await from being executed until the returned Future completes. Other async code can still be called (from timers, or animation triggers, or other code invoked by the framework for example depending on screen refresh rate. I don't know though if calling out to Java can block the UI thread.

– Günter Zöchbauer
Mar 7 at 7:00




1




1





See this issue - the native code runs on the native UI thread, so you shouldn't block it or you risk stalling input and other platform specific issue. The solution is to do your additional 2 seconds of work on a separate thread. (The creator of the above issue argues that you should be able to do work on the main thread, but not many people seem to agree...) The point is there's an easy work around - background thread. I thought I saw a really good diagram of the 3 main threads the other day, but now I can't find it again.

– Richard Heap
Mar 7 at 14:13






See this issue - the native code runs on the native UI thread, so you shouldn't block it or you risk stalling input and other platform specific issue. The solution is to do your additional 2 seconds of work on a separate thread. (The creator of the above issue argues that you should be able to do work on the main thread, but not many people seem to agree...) The point is there's an easy work around - background thread. I thought I saw a really good diagram of the 3 main threads the other day, but now I can't find it again.

– Richard Heap
Mar 7 at 14:13













0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55035528%2fflutter-plugin-async-and-thread%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55035528%2fflutter-plugin-async-and-thread%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved