Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass parameters from inside handler to an Asynctask?

 
AhFai Chan
Ranch Hand
Posts: 81
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, my Java fails me again

I need to pass some parameters from my MainActivity to an asynctask using a handler, so I can start and stop the process anytime.

The parameters (this, loginstatus, result) in the asynctask are used to display the results in the UI ( the TextViews in the XML).

Problem: ( see pic)




Following is my MainActivity that calls the asynctask:




And this is the Asynctask:


AAAAAAAAAAAAAAAAAAAAAAAAAAAAA.jpg
[Thumbnail for AAAAAAAAAAAAAAAAAAAAAAAAAAAAA.jpg]
 
Darryl A. J. Staflund
Ranch Hand
Posts: 314
2
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I haven't really used Android handler's before, but from what I have read handlers can be used to send messages to other objects and messages can hold data bundles. So maybe you could add your data to a bundle, add the bundle to the message, and then use the handler to send the message to the AsyncTask. It should work in theory, but having never used handlers I am not sure.

Darryl
 
Giovanni Montano
Ranch Hand
Posts: 247
4
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl A. J. Staflund wrote:Hi there,

I haven't really used Android handler's before, but from what I have read handlers can be used to send messages to other objects and messages can hold data bundles.  So maybe you could add your data to a bundle, add the bundle to the message, and then use the handler to send the message to the AsyncTask.  It should work in theory, but having never used handlers I am not sure.

Darryl


this is a great documentation, for the curious http://codetheory.in/android-handlers-runnables-loopers-messagequeue-handlerthread/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic