我正在学习android,并遇到了类似的示例

public static class A extends IntentService {
    public A() {
        super("AppWidget$A");
    }
}


有人可以告诉我为什么我们必须显式调用superclass(IntentService)的构造函数吗?参数字符串表示什么?

最佳答案

仅用于调试。这是使用此方法的IntentService源代码的一部分:

public abstract class IntentService extends Service {

    ...
    private String mName;
    ...

    /**
     * Creates an IntentService.  Invoked by your subclass's constructor.
     *
     * @param name Used to name the worker thread, important only for debugging.
     */
    public IntentService(String name) {
        super();
        mName = name;
    }

    ...

    @Override
    public void onCreate() {
        super.onCreate();
        HandlerThread thread = new HandlerThread("IntentService[" + mName + "]");
        thread.start();

        mServiceLooper = thread.getLooper();
        mServiceHandler = new ServiceHandler(mServiceLooper);
    }

    ...
}

07-28 02:23
查看更多