我在想我应该在我的Android项目中放置AsyncTask
的位置。截至目前,我正在执行一个AsyncTask
作为我的活动的一个私人类。我要做的是在每个有网络通话的活动中,我将执行其自己的私人课程AsyncTask
。我有几个问题,但Android with ASYNC任务
In The
preexecute
method it says I can interact with the activity and place a spinner or progress bar. I do this by usingMy_Activity_Class_Name.this
. So my question is does that line of code reference the activity theAsyncTask
is called from? If so I believe that will be a static method. How do i actually pass in the instance of the class so I can interact with non static functions?I want to place all my Async code into one class for its respective needs. My quesiotn though is if i need to return a type back to the class that calls the Async method how can I return a value? Also is this the best practice?
当我使类静态时,我得到错误错误:(104,34)错误:非静态变量,这不能从静态上下文中引用。创建一个弱引用将解决这个问题吗? – Esko918
<! - language:lang-js - > – Esko918
@ Esko918是的,而不是在你的Activity中使你的AsyncTask静态,让它成为一个外部类 - 这里是一个例子:https://gist.github.com/rorist/459787 – marcinj