提问者:小点点

为什么新处理程序被弃用?[重复]


public class SpalshScreen extends AppCompatActivity {


FirebaseUser currentUser;

private FirebaseAuth mAuth;


@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_spalsh_screen);

    mAuth = FirebaseAuth.getInstance();

    if (mAuth != null) {

        currentUser = mAuth.getCurrentUser();

    }

    new Handler().postDelayed(new Runnable() {

        @Override

        public void run() {

            FirebaseUser user = mAuth.getCurrentUser();

            if (user == null) {

                Intent intent = new Intent(SpalshScreen.this, LoginActivity.class);

                startActivity(intent);

                finish();

            } else {

                Intent mainIntent = new Intent(SpalshScreen.this, DashboardActivity.class);

                mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

                startActivity(mainIntent);

                finish();

            }

        }

    }, 1000);

}
}

共1个答案

匿名用户

尝试使用以下代码。仅弃用无参数构造函数,现在通过Loopo. getMainLooper()方法在构造函数中指定Looper。

    new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
        @Override
        public void run() {
            
        }
    }, 1000);