0

我有点困惑。AccessibilityService 可以获取所有新的传入通知,并通过广播将信息发送到广播接收器。我的 AccessibilityService 这样做

public void onServiceConnected() {
    // ...
    Communication c = new Communication();
    IntentFilter filter = new IntentFilter();

    filter.addAction("com.cilenco.lockscreen.notification.send");
    registerReceiver(c, filter);
}   

Intent intent=new Intent("com.cilenco.lockscreen.notification.send");

intent.putExtra("string1", string1);
intent.putExtra("string2", string2);

sendBroadcast(intent);

在我发送广播后,AccessibilityService 仍然存在。如果检测到新通知 onServiceConnected 再次被调用,但接收器再次连接在我从未调用过

unregisterReceiver(c);

我必须在哪里称呼这个?

4

2 回答 2

1

You call unregisterReceiver() when you no longer want to receive broadcasts. Convention is that it is called in your onPause(). Or sonner if you have no need for it anymore.

于 2013-03-19T18:22:31.293 回答
0

当您不再需要侦听意图或调用服务的 onDestroy() 时,应调用 unregisterReceiver(),以先到者为准。

于 2013-03-21T18:58:54.993 回答