getSystemServices is undefined when called in a Fragment?

前端 未结 7 1798
醉酒成梦
醉酒成梦 2020-12-08 18:59

I want TextViews to display the sensors readings in a Fragment. When trying to initialize the SensorManager the getSystemService

7条回答
  •  粉色の甜心
    2020-12-08 19:23

    sensorManager = (SensorManager) getActivity().getSystemService(Context.NAMEOF_SERVICE);
    

    Fragments cannot directly call System Services , You have to use Activity with which these Fragment is Attached

提交回复
热议问题