Reputation: 1304
I've been trying to connect to a server to retrieve some data. First thing came to my mind was to create a thread to connect asynchronously.
new Thread(new Runnable() {
@Override
public void run() {
// retrieve data
}
}).run();
But the weird thing is that the thread I created worked synchronous with UI thread and I got a network exception so I ended up using AsyncTask. Do you guys know what could cause a thread to work non asynchronously with the UI thread? My class extends to a fragment.
Upvotes: 0
Views: 174
Reputation: 5020
Your must start your thread with start()
and not run()
in order to start the new thread:
new Thread(new Runnable() {
@Override
public void run() {
// retrieve data
}
}).start();
Upvotes: 5