abhijit
abhijit

Reputation: 11

how to do Android task in background

I am making an Android application that takes data from file i.e phone SD card and according to time,application displays data in html i.e in web browser .This application runs continuously.I have two task, first time calculating and taking data from file which is continuous and second display data on web browser which is also continuous.i want to run first task in background and other task that continuously display data in html.

I don't know how to do this..also i am new in android ..please help me.thank you..

Upvotes: 0

Views: 6397

Answers (1)

VipulKumar
VipulKumar

Reputation: 2395

You are looking for AsyncTask. AysncTask has doInBackground() method to do your time consuming task. All other methods run on main thread. Something like this

new AsyncTask<Void, String, String>() {

            @Override
            protected void onPreExecute() {
                // before executing background task. Like showing a progress dialog
            }

            @Override
            protected String doInBackground(Void... params) {
                // Do background task here
            }

            @Override
            protected void onPostExecute(String msg) {
               // This will be executed when doInBackground() is finished.
               // "msg" is value returned by doInBackground()
            }
        }.execute(null, null, null);

Upvotes: 3

Related Questions