shiami
shiami

Reputation: 7264

How should I use Executor insteand of AsyncTask or IntentService for queueing task on Android?

  1. Is it a good solution or not?

  2. How to implement?

  3. When should I shutdown properly? I shutdown it onDestroy() in the Activity, then relaunch my app as soon as possible. It causes a java.util.concurrent.RejectedExecutionException, why? Does anyone know its lifecycle?

Any idea? Thanks.

Upvotes: 0

Views: 1680

Answers (2)

shiami
shiami

Reputation: 7264

I just figure out the AsyncYask already implemented the Java's concurrency executor with core_pool_size 5 and max_pool_size 128. That's great!

Upvotes: 2

Tony
Tony

Reputation: 1576

  1. Yes, I think so. AsyncTask is used for those tasks which will update UI. Sorry I am not familiar with IntentService.
  2. Create an Application object which implements android.app.Application interface. Create Executor in the onCreate method. You can get your Application object using following statement:

    MyApplication app = (MyApplication) context.getApplicationContext();

  3. I am not sure what you mean by "app destory". I think you can shutdown Executor in Application's onTerminate method and onLowMemory method.

Upvotes: 0

Related Questions