开发者

Threads in Android

开发者_JAVA技巧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?


Finally i used AsyncTask for managing UI and Background Processing


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.


Then use TimerThread.

http://developer.android.com/resources/articles/timed-ui-updates.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜