How to instantiate android service with a constructor?

后端 未结 6 1980
北海茫月
北海茫月 2021-01-04 09:21

I have a service with an following constructor:

public ShimmerService(Context context, Handler handler) {
    mHandler = handler;
}

I want

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-04 09:46

    You should not construct services (or activities, or broadcast receivers) explicitly. The Android system does that internally. The proper way to construct a service is via startService() with an intent; feel free to add extra parameters to that intent.

    EDIT: or bindService(). Then you have options - either build a custom interface with AIDL, or use raw transact().

提交回复
热议问题