• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how can I update onprogressupdate in asynctask using ExecutorService and Future Interface

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've research a bit about speeding up the application I'm working on. It is a network/port scanner and originally it did everything on a single thread using Asynctask. But I wanted to speed it up. So I looked at Runnable and Callable interface. Since I need to return something from the thread (if there's another way please let me know) I settled for Callable interface. My problem is that I can't figure out how to get the results from the Callable class and update the Asynctask onProgressUpdate() method. The IpScanCallable class returns data of type Node. Which is an object that holds information about especific node eg: ip, mac. I tried publishUpdate(node) but that didn't work. Is there any way of achieving this. Thanks
AsyncTask is at the buttom

IpScanCallable
 
Saloon Keeper
Posts: 7597
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While you didn't say  what "that didn't work" means, exactly (please always TellTheDetails), what jumps out is that you're calling publishProgress with no parameters - so it can't possibly provide results. Either pass the Future to onProgressUpdate and handle it there, or remove the Callable/Future stuff entirely and run AsyncTask in parallel via executeOnExecutor().

As an aside, I took the liberty of removing the GUI code, since that doesn't have anything to do with the problem at hand.
 
PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic