我的应用程序没有运行,而是在模拟器上显示一个白色的屏幕,我被跳过的帧淹没,据我所知,我主线程中的代码相对简单..
public class MainActivity extends AppCompatActivity {
EditText etEmail, etPassword;
Button signInButton;
UserLocalStore userLocalStore;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
etEmail = (EditText) findViewById(R.id.etEmail);
etPassword = (EditText) findViewById(R.id.etPassword);
signInButton = (Button) findViewById(R.id.signInButton);
userLocalStore = new UserLocalStore(this);
signInButton.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v) {
switch (v.getId()) {
case R.id.signInButton:
String email = etEmail.getText().toString();
String password = etPassword.getText().toString();
User user = new User(null, null, email, password);
authenticate(user);
break;
}
}
private void authenticate(User user) {
ServerRequests serverRequest = new ServerRequests(MainActivity.this);
serverRequest.GetUserDataAsyncTask(user, new GetUserCallback() {
@Override
public void done(User returnedUser) {
if (returnedUser == null) {
showErrorMessage();
} else {
logUserIn(returnedUser);
}
}
});
}
private void showErrorMessage() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this);
dialogBuilder.setMessage("Incorrect user details");
dialogBuilder.setPositiveButton("Ok", null);
dialogBuilder.show();
}
private void logUserIn(User returnedUser) {
userLocalStore.storeUserData(returnedUser);
userLocalStore.setUserLoggedIn(true);
startActivity(new Intent(MainActivity.this, HomeScreenActivity.class));
}
}
);
}
@Override
protected void onStart() {
super.onStart();
if (authenticate()) {
displayUserDetails();
} else {
startActivity(new Intent(MainActivity.this, MainActivity.class));
}
}
private boolean authenticate() {
return userLocalStore.getUserLoggedIn();
}
private void displayUserDetails() {
User user = userLocalStore.getLoggedInUser();
etEmail.setText(user.email);
}
}
然而,我仍然设法获得数百个跳帧消息,例如:
02-24 17:45:10.412 3051-3051/k.unionapp I/Choreographer: Skipped 42 frames! The application may be doing too much work on its main thread.
02-24 17:45:10.917 3051-3051/k.unionapp I/Choreographer: Skipped 40 frames! The application may be doing too much work on its main thread.
02-24 17:45:11.712 3051-3051/k.unionapp I/Choreographer: Skipped 40 frames! The application may be doing too much work on its main thread.
02-24 17:45:12.227 3051-3051/k.unionapp I/Choreographer: Skipped 39 frames! The application may be doing too much work on its main thread.
02-24 17:45:12.746 3051-3051/k.unionapp I/Choreographer: Skipped 35 frames! The application may be doing too much work on its main thread.
02-24 17:45:13.184 3051-3051/k.unionapp I/Choreographer: Skipped 36 frames! The application may be doing too much work on its main thread.
02-24 17:45:13.721 3051-3051/k.unionapp I/Choreographer: Skipped 38 frames! The application may be doing too much work on its main thread.
02-24 17:45:14.167 3051-3051/k.unionapp I/Choreographer: Skipped 37 frames! The application may be doing too much work on its main thread.
02-24 17:45:14.621 3051-3051/k.unionapp I/Choreographer: Skipped 37 frames! The application may be doing too much work on its main thread.
02-24 17:45:15.258 3051-3051/k.unionapp I/Choreographer: Skipped 43 frames! The application may be doing too much work on its main thread.
02-24 17:45:15.813 3051-3051/k.unionapp I/Choreographer: Skipped 48 frames! The application may be doing too much work on its main thread.
02-24 17:45:16.298 3051-3051/k.unionapp I/Choreographer: Skipped 43 frames! The application may be doing too much work on its main thread.
02-24 17:45:16.844 3051-3051/k.unionapp I/Choreographer: Skipped 43 frames! The application may be doing too much work on its main thread.
02-24 17:45:17.595 3051-3051/k.unionapp I/Choreographer: Skipped 76 frames! The application may be doing too much work on its main thread.
02-24 17:45:18.032 3051-3051/k.unionapp I/Choreographer: Skipped 44 frames! The application may be doing too much work on its main thread.
02-24 17:45:18.535 3051-3051/k.unionapp I/Choreographer: Skipped 39 frames! The application may be doing too much work on its main thread.
02-24 17:45:19.163 3051-3051/k.unionapp I/Choreographer: Skipped 45 frames! The application may be doing too much work on its main thread.
02-24 17:45:19.738 3051-3051/k.unionapp I/Choreographer: Skipped 48 frames! The application may be doing too much work on its main thread.
02-24 17:45:20.311 3051-3051/k.unionapp I/Choreographer: Skipped 44 frames! The application may be doing too much work on its main thread.
02-24 17:45:20.868 3051-3051/k.unionapp I/Choreographer: Skipped 43 frames! The application may be doing too much work on its main thread.
02-24 17:45:21.371 3051-3051/k.unionapp I/Choreographer: Skipped 36 frames! The application may be doing too much work on its main thread.
02-24 17:45:21.850 3051-3051/k.unionapp I/Choreographer: Skipped 48 frames! The application may be doing too much work on its main thread.
我无法理解这是导致这个问题的原因,任何帮助都将不胜感激!提前谢谢。