1

I want to run asynctask every second but it works only one time.After it stopped working but handler is running every second.

I am using asynctask for insert data into database.

Runnable mHandlerTask = new Runnable() {
        @Override
        public void run() {
            new PushRawData().execute();
            new PushGraphData().execute();
            mHandler.postDelayed(mHandlerTask, INTERVAL);
        }
    };
Shanmugapriyan M
  • 301
  • 5
  • 17

2 Answers2

1

AsyncTask have limits, Read this

You can try to increase the thread pool size

Jobscheduler does not guarantee to run every second, its purpose is different

You can use content provider and cursor loaders, they run on background thread without affection the ui ie main thread.

Community
  • 1
  • 1
Vikas Rathod
  • 374
  • 2
  • 14
0

Your approach is wrong. Use Service for continuous operations in background.Refer to the below information. https://developer.android.com/reference/android/app/Service.html