0

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..

abhijit
  • 11
  • 1
  • 2
  • You are either looking for `AsyncTask` http://stackoverflow.com/questions/9671546/asynctask-android-example or `AsyncTaskLoader` http://stackoverflow.com/a/20279805/2413303 or maybe even `RxJava` if you want to be advanced http://stackoverflow.com/questions/23447077/android-rxjava-non-blocking?rq=1 but you should also look up `IntentService` if it's that long-lasting of an operation. – EpicPandaForce Feb 24 '15 at 12:14

1 Answers1

3

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);
VipulKumar
  • 2,385
  • 1
  • 22
  • 28