Code Monkey home page Code Monkey logo

Comments (2)

mcxiaoke avatar mcxiaoke commented on August 30, 2024

@brucewuu520

  1. TaskQueue.getDefault().setExecutor() 这样是可以的,修改的是默认TaskQueue的设置
  2. 如果使用TaskQueue.createNew()就等于是创建了一个新的TaskQueue,你在某个地方保存这个TaskQueue,整个App只使用这个实例也等于是单例,一般都是保存在Application的子类中,

两种用法是等价的,如果整个应用都只用一个TaskQueue,那么随便选一种都可以

例子:

public class MyApp extends Application {
    private TaskQueue mQueue;

    @Override
    public void onCreate() {
        super.onCreate();
        mQueue = TaskQueue.createNew();
        mQueue.setExecutor(Executors.newFixedThreadPool(2));
    }

    public TaskQueue getQueue() {
        return mQueue;
    }
}
// 对于情况一
TaskQueue queue=TaskQueue.getDefault();
// 对于情况二
MyApp app=(MyApp) context.getApplicationContext();
TaskQueue queue=app.getQueue();

from android-next.

mcxiaoke avatar mcxiaoke commented on August 30, 2024

close

from android-next.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.