Kartik Domadiya
Kartik Domadiya

Reputation: 29968

Threads in Android

I want to display data in my android application from the database in a gap of few seconds and update the UI using threads. So how can i separate the logic for both getting the data from the database and UI?

Upvotes: 1

Views: 374

Answers (3)

bosozoku
bosozoku

Reputation: 77

if you have to kill the Activity before the AsyncTask finish the job , you can recover the it in another Activity using :

1- class code: private class DownloadImageTask extends AsyncTask { .... }

2- instance the class :

        dtdodo = new DownloadImageTask( this, p , codacaovalue);
        dtdodo.execute("wwwkjhdijdh");

3- Kill the Activity (event like rotate the screen).

4- recoveryng the AsyncTask :

onCreate(){
        Object retained = getLastNonConfigurationInstance();
        if ( retained instanceof DownloadImageTask ) {
                dtdodo = (DownloadImageTask) retained;
                dtdodo.setActivity(this);
        } else {
                dtdodo = new DownloadImageTask(this , 1 , codacaovalue);
                dtdodo.execute();
        }
}

I found this in a blog of a anonymous guy, I am justing sharing.

Upvotes: 1

Kartik Domadiya
Kartik Domadiya

Reputation: 29968

Finally i used AsyncTask for managing UI and Background Processing

Upvotes: 1

Related Questions