android 线程

new Thread(runnable).start();

用这个开始一个线程

android 线程
    static Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Bundle data = msg.getData();
            String val = data.getString("username");
            if (val != null) {
                Log.i("Exception", "请求结果-->" + val);
            }
        }
    };
android 线程

用这个handler处理UI线程的更新

android 线程
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            // if(validate()){
            Log.i("Exception", "validate ok");
            editor = sharedPreferences.edit();
            String username = userAccount.getText().toString();
            Log.i("iwork",username);
            editor.putString("username", username);
            editor.commit();
            Intent intent = new Intent(LoginActivity.this,
                    HomeworkListActivity.class);
            startActivity(intent);
            Message msg = new Message();
            Bundle data = new Bundle();
            data.putString("username", sharedPreferences.getString("username", null));
            msg.setData(data);
            Log.i("iwork","sendMessage data:"+msg.getData().getString("username"));
            handler.sendMessage(msg);
        }
    };
android 线程

再实现runnable,实例一个线程

android 线程

上一篇:Unity3d游戏中添加移动MM支付SDK问题处理(failed to find resource file(mmiap.xml})


下一篇:Android标签tabhost常见的一个小错误