1

私はアンドロイドを学んでいて、次のような例に出くわしました

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

スーパークラス(IntentService)のコンストラクターを明示的に呼び出す必要がある理由を教えてください。パラメータ文字列は何を意味しますか?

4

2 に答える 2

3

デバッグのみに使用されます。これを使用する 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);
    }

    ...
}
于 2012-06-06T11:36:44.997 に答える