I have defined two Handlers MainHandler and Child Handler
My Thread XYZ is able to send data to main via MainHandler but I also want to communicate to Thread from Main
the problem faced by me is that my Thread has a infinite loop which is in its run() routine
how Can I have an infinite loop inside my Thread and also transfer data to it via main code
public class XYZ extends Thread
{
@Override
public void run()
{
while(true)
{
//communicate with the server and pass the data to main via MainHandler.sendMessage(myData)
//Thread.sleep(defined_Interval);
.........
}
}
}
I tried by adding
Looper.prepare();
ChildHandler = new Handler() {
public void handleMessage(Message msg)
{
Log.i("TCP", "Got an incoming message from the main thread - " + (String)msg.obj);
}
};
Looper.loop();
while(true)
{
//my code
}
but my part of code doesnt work and when I try this
Looper.prepare();
ChildHandler = new Handler() {
public void handleMessage(Message msg)
{
Log.i("TCP", "Got an incoming message from the main thread - " + (String)msg.obj);
}
};
while(true)
{
//my code
}
Looper.loop();
it says that Unreachable code at Looper.Loop(); line
My Thread XYZ is able to send data to main via MainHandler but I also want to communicate to Thread from Main
the problem faced by me is that my Thread has a infinite loop which is in its run() routine
how Can I have an infinite loop inside my Thread and also transfer data to it via main code
public class XYZ extends Thread
{
@Override
public void run()
{
while(true)
{
//communicate with the server and pass the data to main via MainHandler.sendMessage(myData)
//Thread.sleep(defined_Interval);
.........
}
}
}
I tried by adding
Looper.prepare();
ChildHandler = new Handler() {
public void handleMessage(Message msg)
{
Log.i("TCP", "Got an incoming message from the main thread - " + (String)msg.obj);
}
};
Looper.loop();
while(true)
{
//my code
}
but my part of code doesnt work and when I try this
Looper.prepare();
ChildHandler = new Handler() {
public void handleMessage(Message msg)
{
Log.i("TCP", "Got an incoming message from the main thread - " + (String)msg.obj);
}
};
while(true)
{
//my code
}
Looper.loop();
it says that Unreachable code at Looper.Loop(); line