comparison of Thread vs Asynctask in android?

by Hitendrasinh Gohil » Thu, 19 May 2011 14:38:16 GMT


Sponsored Links
 hi,

I have just found one google doc for ANR.i am using thread class to
retrieve data from server.and displaying it to app.

so i just want to that whether i should use Thread or should forget
the Thread because android is providing Asynctask.

can anyone elaborate this,pls?

-- 



Re: comparison of Thread vs Asynctask in android?

by Miguel Morales » Thu, 19 May 2011 14:46:42 GMT


 The only difference is that AsyncTask uses a thread pool to do its work.  If
you use a thread, you will have a slight overhead of creating and starting
the thread.  However, they both work relatively the same.

On Wed, May 18, 2011 at 11:38 PM, Hitendrasinh Gohil <







-- 
~ Jeremiah:9:23-24
Android 2D MMORPG:  http://solrpg.com/ ,
 http://www.youtube.com/user/revoltingx 

-- 


Sponsored Links


Re: comparison of Thread vs Asynctask in android?

by Saurav » Thu, 19 May 2011 14:51:48 GMT


 In my experience, (I have used both), you need to create a Hander object to
change something from the procedure that is running inside your Thread.

Whereas, if you use the AsycTask, there will be call backs to do UI
updations... I also agree with Miguel Morales.




Regards,
Saurav Mukherjee.


On Thu, May 19, 2011 at 12:08 PM, Hitendrasinh Gohil <




-- 



Re: comparison of Thread vs Asynctask in android?

by Hitendrasinh Gohil » Thu, 19 May 2011 14:55:28 GMT


 hi,

i have read this from google doc,"ANR"(Application not responding) happens
when ,

I)main thread("event thread"/"ui thread") doesnt respond to input events in
5 sec
ii)broadcast receiver doesnt finish in 10 seconds.


in my application flow is like

classA >thread>callback to classA with data>from classA activity is called

which is called the main thread in above scenario?
in this case what happens?




-- 
Regards,
Hitendrasinh Gohil

-- 



Re: comparison of Thread vs Asynctask in android?

by Miguel Morales » Thu, 19 May 2011 15:02:58 GMT


 Have you read:
 http://developer.android.com/resources/articles/painless-threading.html ? 

On Wed, May 18, 2011 at 11:55 PM, Hitendrasinh Gohil <






-- 
~ Jeremiah:9:23-24
Android 2D MMORPG:  http://solrpg.com/ ,
 http://www.youtube.com/user/revoltingx 

-- 



Re: comparison of Thread vs Asynctask in android?

by Ali Chousein » Thu, 19 May 2011 15:09:04 GMT


 Keep in mind that Asynctask is provided for finite tasks. If you need
to have a thread which should run forever, don't use Asynctask, but
use Thread.

-Ali

-- 



Re: Re: comparison of Thread vs Asynctask in android?

by Hitendrasinh Gohil » Thu, 19 May 2011 20:25:43 GMT


 hi,

i am using thread to retrieve string data from server and asynctask to
download files(avg 7 to 8mb) from server.so is it okay in this case.


-- 
Regards,
Hitendrasinh Gohil

-- 



Re: comparison of Thread vs Asynctask in android?

by Ali Chousein » Fri, 20 May 2011 13:36:06 GMT


 Using Asynctask to download files is fine I think (given that you
handle correctly the error cases; e.g. target server might be down etc
etc).


On May 19, 2:25pm, Hitendrasinh Gohil <hitendra.virtuei...@gmail.com>



-- 



Other Threads

1. Problem with viewflipper animations and drawing cache

Well, I solved the issues, including the image issue, by adding the
following line to the Theme
<item name="android:windowBackground">@android:color/transparent</
item>




-- 

2. Problem with TabActivity and ListActivity

Hi all,
I am having a problem.I want to explain in detail.
1)I am Having an TabActivity with 5 tabs. I loaded content as follows.
   class MainScreen extends TabActivity{
        public static TabHost mTabHost;
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.tab);

           TabHost mTabHost = getTabHost();

            mTabHost.addTab(mTabHost.newTabSpec("excercise")
                                
.setIndicator("excercise",getResources().getDrawable
(R.drawable.exr))
                                .setContent(new Intent(this,Excercise.class)));
            mTabHost.addTab(mTabHost.newTabSpec("graphs")
                                
.setIndicator("graphs",getResources().getDrawable
(R.drawable.graph))
                                .setContent(new Intent(this,Graphs.class)));
            mTabHost.addTab(mTabHost.newTabSpec("gymlocator")
                                .setIndicator("gym 
locator",getResources().getDrawable
(R.drawable.gym))
                                .setContent(new Intent(this,Gymlocator.class)));
            mTabHost.addTab(mTabHost.newTabSpec("my account")
                                .setIndicator("my 
account",getResources().getDrawable
(R.drawable.my))
                                .setContent(new Intent(this,Myaccount.class)));
            mTabHost.addTab(mTabHost.newTabSpec("Music")
                                .setIndicator("Music",getResources().getDrawable
(R.drawable.music))
                                .setContent(new Intent(this,Music.class)));

            mTabHost.setCurrentTab(0);
        }
tab.xml
------------
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical" android:background="@drawable/
innerbg"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs" android:paddingTop="55px"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

        </FrameLayout>
    </LinearLayout>
</TabHost>

------------------------
And the Problem is If i want to start activity which is not specified
in tabhost in above Java code,it is going out of tabactivity.
ie.,It is not coming in tabactivity.

2)But i want to have all the activities under tabActivity.
   Please i nee dthe solution urgent.
  If any one knows please tell me .

I hope you i am clear with my problem.

-- 

3. Motorola Droid, OpenGL,...crash on glBindTexture

4. Problem with sqlite database

5. ParcelFileDescriptor from ZipEntry how??

6. what should take care when call APIs in Surface.java

7. required hardware features