I have been able to call an http post process in a new thread, but the variables sent over the post vary based off of the value of another variable, posttype, set before this thread is run.
The variable that determines what values are sent over the post is set as: public String posttype = "load";
before the new thread is run posttype is set as either “load” or “unload”. Based off of these values, the data sent over post is determined.
the new thread function I use is from: http://android-developers.blogspot.com/2009/05/painless-threading.html
I use the SECOND function shown of runnable from the above link.
Inside the first run() I sent the variables over http. Inside the second run() I parse the returned variable.
The problem is this: I cannot access the value of the posttype and the else statement inside the new thread function is always chosen because the if statement cannot access the variable posttype.
How to I make the variable posttype truly global or usable by a new thread?
Thanks,
If I get it right you can’t access the variable because it’s not final. If so you can take a final variable of the same type as posttype, assign it that value and use it in the second run.
To make it more clear check my answer to this question: final variable issue in an inner class
The listener in that case is run in a situation where the same logic applies.