• java 线程


    线程一
    class LoginThread extends Thread{
    public void StartThread() {
    Thread a = new Thread(this);
    a.start();
    }
    @Override
    public void run() {
    try {
    sleep(1000);
    Login();
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }

    使用
    LoginThread lt =new LoginThread();
    lt.StartThread();
    线程二

    public class MyRunnable implements Runnable{
    public void run(){

    }
    }

    使用

    Thread thread=new Thread(new MyRunnable());
    thread.start();

    线程三
    Handler myHandler = new Handler(){
    @Override
    public void handleMessage(Message msg) {
    switch (msg.what) {
    case 3:

    break;
    case 1:
    //createNotification(1);
    break;
    case 2:
    StopLoading();
    Alerts("下载出错,请稍后再试");
    break;
    }
    }
    };

    使用
    myHandler.sendEmptyMessage(2);

    或者
    Message message = new Message();
    Bundle boBundle = new Bundle();
    boBundle.putString("Title", "系统提示");
    boBundle.putString("Msg", "检测到系统有新版本,是否更新");
    message.setData(boBundle);
    message.what=3;
    myHandler.sendMessage(message);
    线程四

    private class AsyncCallWS extends AsyncTask<Void, Void, Void> {
    @Override
    protected Void doInBackground(Void... params) {
    SetAdapter(); //有数据
    return null;
    }
    }

    使用

    AsyncCallWS task = new AsyncCallWS();
    task.execute();

  • 相关阅读:
    基于flv.js自定义播放器UI界面
    使用node.js将xmind导出的excel转换为json树
    开启Hyper-V
    vue刷新当前路由
    react native练习
    mock js使用方法简单记录
    前端小技巧总结
    常用js函数开始收集~
    文字跳动
    cordova 修改状态栏的颜色,修改顶部电池字体颜色
  • 原文地址:https://www.cnblogs.com/lucoo/p/3678602.html
Copyright © 2020-2023  润新知