나는 몇 가지 컨트롤을 가지고 있는데, 어떤 이유로 스레드를 만들었습니다. asycntask를 사용하여로드 중 한 화면을 다른 화면에 표시하고 싶습니다. 내 문제는로드 표시 줄이 빠르게 표시되고로드가없는 동일한 화면을 기다리는 중입니다. 그리고 잠시 후 두 번째 화면으로 이동합니다. 사후 집행이 제대로 작동하지 않는 것 같아. 아무도 도와 줄 수 있니?onPostExecute()가 너무 오래 기다리고 있습니까?
private class ProgressBarAsync extends AsyncTask<Void, Integer, Void>{
/** This callback method is invoked, before starting the background process */
@Override
protected void onPreExecute() {
super.onPreExecute();
/** Creating a progress dialog window */
mProgressDialog = new ProgressDialog(Login.this);
/** Close the dialog window on pressing back button */
mProgressDialog.setCancelable(true);
/** Setting a horizontal style progress bar */
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
/** Setting a message for this progress dialog
* Use the method setTitle(), for setting a title
* for the dialog window
* */
mProgressDialog = ProgressDialog.show(Login.this,
"Giriş yapıyorsunuz", "Lütfen bekleyin...");
}
/** This callback method is invoked on calling execute() method
* on an instance of this class */
@Override
protected Void doInBackground(Void...params) {
try {
startMyApplication() ;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
/** This callback method is invoked when publishProgress()
* method is called */
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
mProgressDialog.setProgress(mProgressStatus);
}
/** This callback method is invoked when the background function
* doInBackground() is executed completely */
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if (mid > 0) {
Intent btn_login = new Intent(
getApplicationContext(), MainScreen.class);
startActivity(btn_login);
}
else {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(Login.this);
// Setting Dialog Title
alertDialog.setTitle("GİRİŞ");
// Setting Dialog Message
alertDialog.setMessage("Kullanıcı adı veya Parola Hatalı Lütfen tekrar deneyin.");
// Setting Icon to Dialog
//alertDialog.setIcon(R.drawable.delete);
// Setting Negative "NO" Button
alertDialog.setNegativeButton("TAMAM", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
}
//run();
mProgressDialog.dismiss();
이것은 startmyapp theads :이 섹션은 지연의 원인이되는
public void startMyApplication() throws InterruptedException {
ExecutorService executor = Executors.newFixedThreadPool(2);
FutureTask<String> futureOne = new FutureTask<String>(
new Callable<String>() {
public String call() throws Exception {
if (isOnline()) {
// Call Login Web Service with username and password and get mid
mid = callLoginWS(username.getText().toString(), password.getText().toString());
if (mid > 0) {
//callPasswordGeneratorWS(mid);
// Insert mid and username into sqllite
dbInstance.insertMerch(mid,username.getText().toString());
}
Log.i("futureone", "futureone");
}
return "TEST";
}
});
FutureTask<String> futureTwo = new FutureTask<String>(
new Callable<String>() {
public String call() throws Exception {
// Get mid from database
mid = dbInstance.selectMerch(username.getText().toString());
return "TEST";
}
});
// ... Dispatch
// Check if user exists previously
// ... Dispatch
mid = dbInstance.selectMerch(username.getText().toString());
dbInstance.close();
executor.execute(futureOne);
while (!(futureOne.isDone())) {
executor.execute(futureTwo);
}
Log.i("login","new login");
//}
executor.shutdown();
}
이 함수는 무엇입니까'startMyApplication(); –
내 질문을 편집했습니다. – DuyguK