Android: RunOnUiThread vs AsyncTask

前端 未结 5 1046
渐次进展
渐次进展 2020-12-01 00:50

I believe Google suggests developers to use AsyncTask. However, I would like to know how is it different from using \'new Thread\' and then calling \'RunOnUiThread\' in perf

5条回答
  •  死守一世寂寞
    2020-12-01 01:32

    The main disadvantage is that using your own Thread will keep your activity alive when finish is called. Android will give your activity time for all of your threads to finish. This has the effect of creating an activity leak that will eventually cause your app to run very very slow until your app is force quit from either the user or the OS.

    You can verify this by looking at your process in ADB. Even when the activity is finished you will still see it hanging there taking up resources.

    So, if you use your own thread, make sure you manage it. Or, just use the android api's. the choice is yours.

提交回复
热议问题