Android开启线程的方法有多种,以下是常用的几种方法:
public class MyThread extends Thread {
@Override
public void run() {
// 线程的逻辑
}
}
// 启动线程
MyThread myThread = new MyThread();
myThread.start();
public class MyRunnable implements Runnable {
@Override
public void run() {
// 线程的逻辑
}
}
// 启动线程
MyRunnable myRunnable = new MyRunnable();
Thread thread = new Thread(myRunnable);
thread.start();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
// 线程的逻辑
}
});
// 启动线程
thread.start();
ExecutorService executor = Executors.newFixedThreadPool(1);
executor.execute(new Runnable() {
@Override
public void run() {
// 线程的逻辑
}
});
// 关闭线程池
executor.shutdown();
以上是常用的几种Android开启线程的方法,根据实际需求选择合适的方法。