[안드로이드 공부]/서비스 3

ReceiverCallNotAllowedException: BroadcastReceiver components are not allowed to bind to services

브로드캐스트 리시버에서 또 다른 브로드캐스트 리시버를 등록하려고 할때 발생하는 에러다. android.content.ReceiverCallNotAllowedException: BroadcastReceiver components are not allowed to bind to services 그런데, 이것도 타이밍이 있다. 분명 디스트로이가 된 후에 등록 하려고 했으나, 계속 같은 에러가 발생 할 때가 있다. 왜?명시적으로 이전에 사용했던 서비스를 완전히 죽여 주지 않아서 그렇다. 1. A 리시버에서 B서비스를 생성 하고 사용 한 뒤,2. 다시 A리시버에서 B서비스를 생성 하려고 하면 발생한다. 즉, 1번 이후에 반드시 A에서 생성한 B를 죽여주자.

android.content.ReceiverCallNotAllowedException

리모트 서비스등에서 발생하는 에러로 컨텍스트를 가지고 다니지 못할 때 발생한다. android.content.ReceiverCallNotAllowedException: components are not allowed to register to receive intents위젯, 브로드캐스트, 서비스등과 같이 유령같이 나타나는 얘들은 항상getContext가 아니라 getApplicationContext()를 써서 컨택스트를 들고 다녀야 한다. 스태틱 개념처럼 생각하면 될 듯.

안드로이드 서비스 3단계 과정

안드로이드 서비스(service)를 시작하고, 동작하는지 확인하고 마지막으로 멈추는 간단한 3가지 과정. public static void startSensor(Context context) { if (Tools.isServiceRunning("com.comostudio.service.SensorService", context) == false) { context.startService(new Intent(context, SensorService.class)); } } public static void stopSensor(Context context) { if(Tools.isServiceRunning("com.comostudio.service.SensorService", context)){ context..