나는 그것을 이해할 수 없다.왜 내 스레드가 UI 스레드를 고정 시키나요?
무엇 때문에,이 스레드 코드는 실제로 UI 스레드에서 실행됩니다. 중단 점이 있으면 UI가 중지됩니다. 또는 잠자기, UI가 중지되었습니다. 따라서 네트워크 활동은 "ui"스레드에서 허용되지 않습니다.
Ive는 비동기 작업을 사용하지 않았습니다. 루핑하는 적절한 방법을 알지 못하기 때문입니다. (onPostExecute
에서 그것의 새로운 인스턴스를 호출하면 나쁜 관행처럼 보이고, 것처럼 비동기은 일회성 작업입니다.
public class SyncManager extends Thread {
public SyncManager(Context context){
sdb = new SyncManagerDBHelper(context);
mContext = context;
}
@Override
public void run() {
while(State == RUNNING) {
try{
SyncRecords(); // Break point here = UI freeze.
} catch (Exception e) {
e.printStackTrace();
}
try {
Thread.sleep(10000); // So also causes UI freeze.
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public void startThread() {
Log.i("SyncManager", "start called");
if((State == PAUSED || State == STOPPED) && !this.isAlive())
{
State = RUNNING;
run();
}
}
을 내 활동에서 나는
sm = new SyncManager(this);
sm.startThread();
전화
봐 : https://stackoverflow.com/questions/8052522/why-we-call-thread-start-method-which-in-turns-calls-run-method/36812010#36812010 –