Cannot get display of main activity
I have code like this
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
boolean autoLogin = false;
autoLogin = checkAutoLogin();
if(autoLogin) {
showProgress();// Show progress dialog
if(login(savedUserName,savedPassword)) {
//call home activity using startActivity();
}
// login(savedUserName,savedPassword), this function access the server and return true if username and password correct- this works properly
}
}
Now the question is, i get display of home activity
without displaying main activity
and its progress dialog
, during the authentication time of login(savedUser开发者_如何学运维Name,savedPassword)
(this function take countable time because of server authentication) function, I got only a black screen, during this time i want show main activity and progress dialog.
home activity
i can get main activity
and progress dialog
You should not do the network operation on UI thread,you can do it in separate thread and then you can call the home activity using Handler object,it iwll solve your problem
Do your Time Consuming Task in the AsynchTask. this class is designed exactly for the kind of work you are looking for.Use doInBackground() method to accomplish the task and onPreExecute you can show a progress Dialog.
Depending on what your showProgress()
method contains, I'd guess that showProgress
runs, sees that there is no active login
attempt happening, and dismisses itself, then the login()
method is called.
What you want to do is start login()
asynchronously and then start the progress dialog that will check to see if login()
is finished.
This is just a guess from what I can see of your code.
Could you post some more of it perhaps?
Try putting some logcat logging into the showProgress()
method to see if it is in fact being created and destroyed quickly.
精彩评论