我在一个从线程中有一个敬酒,需要告诉用户建立连接。为此,我知道我需要使用异步来使烤面包发生,但是我不确定如何或如何在何处或如何实现扩展的异步。如果我理解的话,我认为我只能用the and onprogressupdate()吐司创建一个myasync?

@Override
public void onProgressUpdate(String... args) {

         Toast.makeText(context, args, Toast.LENGTH_SHORT).show();
}

感谢您的时间〜Aedon

有帮助吗?

解决方案

是的,您应该能够扩展异步并将模板变量更改为所需内容。吐司类是一个静态类,因此可以从任何线程调用,而不必担心冲突。

我没有看到您的代码上的任何问题,除非您不想自堆叠以来经常调用新的吐司消息。因此,如果您要连续调用.show()函数,它将堆叠它们,并继续在每个长度间隔内显示新的吐司消息,直到捕获为止。

至于一个异步箱的示例,您可以在这里:

private class MyAsync extends AsyncTask<<What to pass in to doInBackground>, <What to pass in to onProgressUpdate>, <What type onPostExecute receives>> {
     protected T (result type to onPostExecute) doInBackground(T... urls) {
         //Do big calculations in here
     }

     protected void onProgressUpdate(T... progress) {
         //Update
     }

     protected void onPostExecute(T result) {
         //Done
     }
 }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top