如何在Android Async Task中加载延迟

时间:2014-09-12 21:43:22

标签: android android-asynctask

public Long doInBackground(StudentInfo... s)
{
  StudentInfo currentStudent = s[0];

  publishProgress("Creating New User");

  SiddDatabaseHelper dbHelper = SiddDatabaseHelper.getInstance(mContext);
  long newStudentID = dbHelper.addUpdateStudentInfo(currentStudent);

  Log.e("TTT", "saved user() newStudentID " + newStudentID);
  publishProgress("Saving New User in Session");

  try
  {
    Thread.sleep(700);
  }
  catch (InterruptedException e)
  {
    e.printStackTrace();
  }
  return newStudentID;
}

我正在尝试睡眠Thread,以便我可以在父活动中显示一些奇特的消息。似乎仍然doInBackground()进程立即完成,没有任何延迟。

1 个答案:

答案 0 :(得分:0)

这将做你想要的:

try {
    Thread.sleep(1000);                 
} catch(InterruptedException ex) {
    Thread.currentThread().interrupt();
}