잘되넹.
Thread, Handle이랑 Excutor랑 이래저래 섞어서 쓰면 좋겠다 싶은데
사실 구조상으로 보면 Futuretask가 AsyncTask랑 같아 보인다.
package com.example.test1;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final FutureTask
ExecutorService excutor = Executors.newFixedThreadPool(1);
excutor.submit(fTask);
excutor.shutdown();
}
class MyCallable implements Callable
{
public Object call() throws Exception {
for (;;) {
Log.v("FTASK", "FUTURE TASK");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
댓글 없음:
댓글 쓰기
국정원의 댓글 공작을 지탄합니다.