【发布时间】:2012-05-09 08:26:55
【问题描述】:
我有一个名为“A 类”的类 a) 我有一个叫做验证的按钮 b) onClick 验证我调用 auth.authenticate() 返回布尔值 c) 在真实情况下 - 我必须调用一个意图
authentication 函数在另一个类中(auth 是一个 ref)
认证函数如下()
布尔验证(){
new AsyncTask<String, String, String>() { preExecute() { --starting a progress bar-- } doInBackground(String ) { ---- huge authentication code----- ------ returns true or false -------isVerified } onPostExecute(String) { --- dismiss progress bar----------- } }.execute(); } --------end of AsynTask block---- synchronized (this) { try { this.wait(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return isVerified; ---- this should return to MyClass - after async finishes
--但是这是在异步完成之前返回的。实际上它是正确的-因为这些是线程-并行运行,因此要使其工作-我一直等到异步使用该同步块完成-但这将阻塞我的主线程-(也没有进度条)
我可以在执行后成功调用我的下一个活动 - 因为我正在制作一个库类..我认为不应该......请帮助
}
【问题讨论】:
标签: android multithreading asynchronous android-asynctask