小编Mat*_*vos的帖子

使用UI线程改进2个回调问题

我正在制作一个简单的材料设计登录屏幕,显示进度对话框,同时改造正在获取数据.

我最近升级到改装2,所以我对此很新.

我的LoginActivity代码:

private void login(){
        Log.d(TAG, "Attempting login");

        if(!validate()){
            onLoginFailure();
            return;
        }

        login_button.setEnabled(false);

        progressDialog = new ProgressDialog(LoginActivity.this, R.style.AppTheme_Dark_Dialog);
        progressDialog.setIndeterminate(true);
        progressDialog.setMessage("Authenticating...");
        progressDialog.show();

        String username = _usernameText.getText().toString().toLowerCase(); //all usernames are lowercase only
        String password = _passwordText.getText().toString();

        //here we handle the NWL section.

        startTime = System.currentTimeMillis();
        NWL.login(username, password, this); //This runs async to UI anyway.
    }
Run Code Online (Sandbox Code Playgroud)

和LoginActivity中的其他功能:

@BindView(R.id.login_button)
Button login_button;

 public void loginOK() {
        progressDialog.dismiss();
        login_button.setEnabled(true);
        toastCreator.showToastLong("Login OK");
        Log.d(TAG, "Total time: " + (System.currentTimeMillis()-startTime));
 }
Run Code Online (Sandbox Code Playgroud)

我的NetworkLogic(NWL)类的代码:

public void login(String username, String password, …
Run Code Online (Sandbox Code Playgroud)

android ui-thread android-handler retrofit2

-2
推荐指数
1
解决办法
3229
查看次数

标签 统计

android ×1

android-handler ×1

retrofit2 ×1

ui-thread ×1