githubw2015 / asmack

一个小的例子
https://github.com/githubw2015/asmack
Other
0 stars 0 forks source link

Unable to get UI Thread out of PacketListener-Thread #62

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What are you doing to produce the error?
I'm unsure as I'm new to java threading but this code, as what I read online
should set name to "main" :
a) in onCreate:
mHandler = new Handler();
b) instanciate new Packetlistener, inside it:

public void processPacket(Packet packet) {
mHandler.post(new Runnable() {
@Override
public void run() {
String name = Thread.currentThread().getName();
Log.d("events","thread name= "+ name);
}
});
...

What is the expected output?
name = main
I tested this, the UI thread has this name in onCreate()
What do you see instead? (Please attach a debug enabled logcat)
name = packelstmain
What version of aSmack / Android / Device do you use?
latest asmack / 1.5 / emulator
What server do you use? Is there a public server to reproduce the problem?
openfire
What else might help us to reproduce and hunt down the problem?
I'm altering the UI from this packetlistener and get weired errors in 75 % of 
the time I can only assume that it is thread related , since every altering of 
the UI _MUST_ be done from UI thread however , with asmack  I'm not getting a 
reference to it as it seems.

Original issue reported on code.google.com by steffen....@gmail.com on 12 Jul 2011 at 9:28

GoogleCodeExporter commented 8 years ago
I tried "runOnUiThread" instead of mHandler.post and I'm getting "main" as a 
result now , so it is not asmack that causes my issues with my gui, I guess. 
Please close this issue.

Original comment by steffen....@gmail.com on 12 Jul 2011 at 11:45