Skip to main content

Home/ Android Dev/ Group items tagged AsyncTask

Rss Feed Group items tagged

Vincent Tsao

避免Android开发中的ANR | Log4think - 0 views

  • AsyncTask要点 1、必须从主线程调用,或者线程中有Handler或Looper。 2、不要在一个可能会被另外一个AsyncTask调用的库里面使用AsyncTask(AsyncTask是不可重入的) 3、如果从一个activity中调用,activity进程可能会在AsyncTask结束前退出,例如: 用户退出了activity 系统内存不足 系统暂存了activity的状态留待后用 系统干掉了你的线程 如果AsyncTask中的工作很重要,应该使用……
  • IntentService 的好处 Acitivity的进程,当处理Intent的时候,会产生一个对应的Service Android的进程处理器现在会尽可能的不kill掉你 非常容易使用
  • 总结 离开主线程! 磁盘和网络操作不是马上就能完的 了解sqlite在干嘛 进度展示很好
Vincent Tsao

kaeppler/droid-fu - GitHub - 6 views

  • Droid-Fu offers both support classes meant to be used alongside existing Android code, as well as self-contained, ready-to-be-used components like new adapters and widgets. The areas tackled by Droid-Fu include: application life-cycle helpers support classes for handling Intents and diagnostics better support for background tasks super-easy and robust HTTP messaging powerful caching of Objects, HTTP responses, and remote images custom adapters and views I suggest you read this introductory article, and anything that follows.
  •  
    大哥你有覺得這個比AsyncTask好用嗎?
  • ...2 more comments...
  •  
    BetterAsyncTask本质就是AsyncTask,我想在用法上应该没有太大区别 但AsyncTask有个硬伤就是它的life-cycle对当前的activity的life-cycle有依赖,容易引起FC,而BetterAsyncTask解决了这个问题,Ref: http://groups.diigo.com/group/android_related/content/introducing-droid-fu-for-android-betteractivity-betterservice-and-betterasynctask-brain-flush-2838716 当然还有其他解决办法,我自己偏向于 IntentService + Broadcast mechanism的解决方案
  •  
    難怪你會搜尋到我布落格 呵呵
  •  
    哈哈,其实是我几个月前看了你的blog后,才有了更多的认识的
  •  
    在我最近的案子裡 幾乎很少機會用到IntentService。 我目前唯一用到的是AsyncTask, 而且那還是我硬用,才有機會用到它。
Vincent Tsao

Introducing Droid-Fu for Android: BetterActivity, BetterService and BetterAsy... - 2 views

  • So the basic idea is: launch an AsyncTask making your service call, show a nifty progress dialog while the task thread is running, and have the task’s result be posted back to your activity once it completes. Cool, but what if the user decides to rotate the screen while your task is running? Or a phone call comes in, interrupting your app, and Android decides to kill it? Both these actions will effectively terminateyour activity, and recreate it when resuming (yes, a screen rotation kills your activity, very clever, isn’t it?). Unfortunately, any AsyncTask that was still running now holds a stale reference to your activity, because the restarted activity will be an entirely different object in memory (and it will go through onCreate(), as if the activity had started for the first time). I’m not entirely sure whether AsyncTask will actually post back the data to the old activity object (if it was a weak reference, it may already have been garbage collected), but in any case, your “new” activity will never see it, because it’s a different instance.
    • Vincent Tsao
       
      This situation always raise a FC bug, an alternative solution is IntentService + broadcast 
Vincent Tsao

Exploring the world of Android :: Part 2 « JTeam Blog / JTeam: Enterprise Jav... - 1 views

  • But in practice, you will notice that the AsyncTask is limited to 10 threads. This number is hardcoded somewhere in the Android SDK so we cannot change this. In this case it’s a limitation we cannot live with, because often more than 10 images are loaded at the same time.
    • Vincent Tsao
       
      使用AsyncTask类开辟的线程还有数量限制?必须小于10,这个倒是以前没有注意到的,要看看源代码怎么实现的
  • I’ve shown you how to improve performance of a ListView in three different ways: By loading images in a seperate thread By reusing rows in the list By caching views within a row
  • ...1 more annotation...
  • Notice that I used a SoftReference for caching images, to allow the garbage collector to clean the images from the cache when needed. How it works: Call loadDrawable(imageUrl, imageCallback) providing an anonymous implementation of the ImageCallback interface If the image doesn’t exist in the cache yet, the image is downloaded in a separate thread and the ImageCallback is called as soon as the download is complete. If the image DOES exist in the cache, it is immediately returned and the ImageCallback is never called.
  •  
    这个帖子完美解决了Image lazy load的性能问题, it works~
Vincent Tsao

ysl 的程式天堂 - Android 應用開發‧研究‧與諮詢: 深入研究 IntentService 原始碼 - 1 views

  • 如果你呼叫 startService() 多次,每一次的呼叫都會被轉成一個 message,並放在 mServiceLooper 的 message queue 中,等待被服務。一個 message 所對應的工作被完成後,才會繼續服務下一個工作。所以,這些等待被服務的工作,並不是一起並行 (Concurrent) 的,而是循序執行。
  • 從研究這個 IntentService 的原始碼,我們可以學到如何運用簡單的 pattern (Service + Handler + HandlerThread),幫我們更簡易與有系統地,完成我們所想要做的事
  • 最後我們先前說過,在 IntentServcie 中等待被服務的工作,並不會被一起並行,而是循序執行。如果你今天想要這些等待被服務的工作,能夠一起被並行,在研讀完這個 IntentService 的原始碼後,你自己知不知道如何寫個可支援並行工作的 IntentService? 提示:可以用 Service + AsyncTask 的組合
Vincent Tsao

android-writing-zippy-android-apps.pdf - 1 views

  •  
    Funny facts: "zippy" 音译成四川话就是"驰皮",也就是"拉风"的意思 
Vincent Tsao

Implementing "Pull To Refresh" in your Android App | Blog // Recursive Awesome // Table... - 1 views

  • For completeness we really should handle the possibility of the task getting cancelled. This can happen when the user navigates away from the app and the task is killed before its completed. This will cause the onPostExecute() method to not be called and so the onRefreshComplete() method won’t be called. Depending on how the user navigates through the app, they could return to this activity without going through the complete onCreate() lifecycle, and you’ll end up with the screen still showing the “loading” progress message in the header. This is common when using tabs between multiple ListViews. Also, the documented best practices for implementing an AsyncTask says that in long running background work you should periodically check if the task has been cancelled and try to gracefully quit your work and exit. So let’s get all of that in there.
1 - 11 of 11
Showing 20 items per page