Calling Getsystemservice Inside A Service
I'm trying to write a service that get the heart rate on Gear Live, following the question here Get Heart Rate from 'Sensor' Samsung Gear Live If I put this part Log.d(TAG, 'p
Solution 1:
I figured it out, the reason is that inside getSystemService
, there's a call to this function:
@OverridepublicObjectgetSystemService(String name) {
return mBase.getSystemService(name);
}
which has mBase
as null. This is a Context
object. So I had to put the context of the activity that start the service in onCreate()
. Code below:
publicHeartRateMonitorService(Context context){
super();
mBaseConext = context;
}
@OverridepublicvoidonCreate() {
super.onCreate();
attachBaseContext(mBaseConext);
}
I'm not sure this is the optimal solution, but it is a workaround.
Post a Comment for "Calling Getsystemservice Inside A Service"