[android-developers] Re: AsyncTask why not must be created in UI thread?
I found out that you can create AsyncTask instances on any thread, as long as your code initially loads the class on the main UI thread (as you stated in your message, Bob). I hit upon this issue when writing JUnit tests that were testing AsyncTask subclasses in my code. JUnit tests don't run on the main UI thread. Creating just one dummy AsyncTask on the main UI thread before running the tests, let my JUnit tests run fine. On Dec 31 2010, 1:50 am, Bob Kerns r...@acm.org wrote: You need to create the AsyncTask instance on the UI thread, but the doInBackground() method runs in a separate thread. The reason for creating the AsyncTask instance on the UI thread is so that it can connect to the proper Looper and MessageQueue for that thread. (It does this through a single static Handler, so it will not work correctly if you first load the class in a different thread. That's unnecessarily fragile, in my opinion, but not a problem if you are using it as intended, as an easy way to move code off the main thread.) On Dec 30, 9:39 pm, water boiled boiledwater4...@gmail.com wrote: I mean that can i create AsycnTask instance not in UI thread? On 12月31日, 下午1时30分, water boiled boiledwater4...@gmail.com wrote: I mean that can i AsycnTask instance not in UI thread? On 12月31日, 下午1时24分, water boiled boiledwater4...@gmail.com wrote: the AsycnTask document says that:The task instance must be created on the UI thread. why create task instance must be created in UI thread? On 12月29日, 上午10时26分, Frank Weiss fewe...@gmail.com wrote: It's difficult to understand what you are asking. What problem are you having with AsyncTask.- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: AsyncTask why not must be created in UI thread?
thanks everybody! On 2010年12月31日, 下午2时50分, Bob Kerns r...@acm.org wrote: You need to create the AsyncTask instance on the UI thread, but the doInBackground() method runs in a separate thread. The reason for creating the AsyncTask instance on the UI thread is so that it can connect to the proper Looper and MessageQueue for that thread. (It does this through a single static Handler, so it will not work correctly if you first load the class in a different thread. That's unnecessarily fragile, in my opinion, but not a problem if you are using it as intended, as an easy way to move code off the main thread.) On Dec 30, 9:39 pm, water boiled boiledwater4...@gmail.com wrote: I mean that can i create AsycnTask instance not in UI thread? On 12月31日, 下午1时30分, water boiled boiledwater4...@gmail.com wrote: I mean that can i AsycnTask instance not in UI thread? On 12月31日, 下午1时24分, water boiled boiledwater4...@gmail.com wrote: the AsycnTask document says that:The task instance must be created on the UI thread. why create task instance must be created in UI thread? On 12月29日, 上午10时26分, Frank Weiss fewe...@gmail.com wrote: It's difficult to understand what you are asking. What problem are you having with AsyncTask. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: AsyncTask why not must be created in UI thread?
the AsycnTask document says that:The task instance must be created on the UI thread. why create task instance must be created in UI thread? On 12月29日, 上午10时26分, Frank Weiss fewe...@gmail.com wrote: It's difficult to understand what you are asking. What problem are you having with AsyncTask. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: AsyncTask why not must be created in UI thread?
I mean that can i AsycnTask instance not in UI thread? On 12月31日, 下午1时24分, water boiled boiledwater4...@gmail.com wrote: the AsycnTask document says that:The task instance must be created on the UI thread. why create task instance must be created in UI thread? On 12月29日, 上午10时26分, Frank Weiss fewe...@gmail.com wrote: It's difficult to understand what you are asking. What problem are you having with AsyncTask. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: AsyncTask why not must be created in UI thread?
I mean that can i create AsycnTask instance not in UI thread? On 12月31日, 下午1时30分, water boiled boiledwater4...@gmail.com wrote: I mean that can i AsycnTask instance not in UI thread? On 12月31日, 下午1时24分, water boiled boiledwater4...@gmail.com wrote: the AsycnTask document says that:The task instance must be created on the UI thread. why create task instance must be created in UI thread? On 12月29日, 上午10时26分, Frank Weiss fewe...@gmail.com wrote: It's difficult to understand what you are asking. What problem are you having with AsyncTask. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
RE: [android-developers] Re: AsyncTask why not must be created in UI thread?
Async tasks runs in the background automatically not on the ui thread. If you want to call something on the ui thread you need to use RunOnUIThread or post a message if that’s what you asking. -Original Message- From: android-developers@googlegroups.com [mailto:android-develop...@googlegroups.com] On Behalf Of water boiled Sent: Friday, December 31, 2010 12:40 AM To: Android Developers Subject: [android-developers] Re: AsyncTask why not must be created in UI thread? I mean that can i create AsycnTask instance not in UI thread? On 12月31日, 下午1时30分, water boiled boiledwater4...@gmail.com wrote: I mean that can i AsycnTask instance not in UI thread? On 12月31日, 下午1时24分, water boiled boiledwater4...@gmail.com wrote: the AsycnTask document says that:The task instance must be created on the UI thread. why create task instance must be created in UI thread? On 12月29日, 上午10时26分, Frank Weiss fewe...@gmail.com wrote: It's difficult to understand what you are asking. What problem are you having with AsyncTask. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: AsyncTask why not must be created in UI thread?
You need to create the AsyncTask instance on the UI thread, but the doInBackground() method runs in a separate thread. The reason for creating the AsyncTask instance on the UI thread is so that it can connect to the proper Looper and MessageQueue for that thread. (It does this through a single static Handler, so it will not work correctly if you first load the class in a different thread. That's unnecessarily fragile, in my opinion, but not a problem if you are using it as intended, as an easy way to move code off the main thread.) On Dec 30, 9:39 pm, water boiled boiledwater4...@gmail.com wrote: I mean that can i create AsycnTask instance not in UI thread? On 12月31日, 下午1时30分, water boiled boiledwater4...@gmail.com wrote: I mean that can i AsycnTask instance not in UI thread? On 12月31日, 下午1时24分, water boiled boiledwater4...@gmail.com wrote: the AsycnTask document says that:The task instance must be created on the UI thread. why create task instance must be created in UI thread? On 12月29日, 上午10时26分, Frank Weiss fewe...@gmail.com wrote: It's difficult to understand what you are asking. What problem are you having with AsyncTask. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en