7

我收到以下错误

“您是否错过了取消注册接收器的呼叫”

当我点击后退按钮退出我的应用程序时。如何识别导致泄漏的接收器并消除错误?我正在使用来自 Google 的代码“DownLoader”来下载扩展文件。

10-27 22:13:32.818: E/ActivityThread(30744): Activity com.ssowens.groovebasstrial.BassActivity has leaked IntentReceiver com.immersion.android.haptics.HapticFeedbackManager$HapticFeedbackBroadcastReceiver@41d166d0 that was originally registered here. Are you missing a call to unregisterReceiver()?
10-27 22:13:32.818: E/ActivityThread(30744): android.app.IntentReceiverLeaked: Activity com.ssowens.groovebasstrial.BassActivity has leaked IntentReceiver com.immersion.android.haptics.HapticFeedbackManager$HapticFeedbackBroadcastReceiver@41d166d0 that was originally registered here. Are you missing a call to unregisterReceiver()?
10-27 22:13:32.818: E/ActivityThread(30744):    at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:800)
10-27 22:13:32.818: E/ActivityThread(30744):    at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:601)
10-27 22:13:32.818: E/ActivityThread(30744):    at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1650)
10-27 22:13:32.818: E/ActivityThread(30744):    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1630)
10-27 22:13:32.818: E/ActivityThread(30744):    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1624)
10-27 22:13:32.818: E/ActivityThread(30744):    at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:430)
10-27 22:13:32.818: E/ActivityThread(30744):    at com.immersion.android.haptics.HapticFeedbackManager.setupPackageBroadcastReceiver(HapticFeedbackManager.java:564)
10-27 22:13:32.818: E/ActivityThread(30744):    at com.immersion.android.haptics.HapticFeedbackManager.<init>(HapticFeedbackManager.java:108)
10-27 22:13:32.818: E/ActivityThread(30744):    at com.immersion.android.HapticFeedbackManagerProxy.initialize(HapticFeedbackManagerProxy.java:90)
10-27 22:13:32.818: E/ActivityThread(30744):    at com.immersion.android.HapticFeedbackManagerProxy.access$100(HapticFeedbackManagerProxy.java:30)
10-27 22:13:32.818: E/ActivityThread(30744):    at com.immersion.android.HapticFeedbackManagerProxy$1$1.run(HapticFeedbackManagerProxy.java:71)
10-27 22:13:32.818: E/ActivityThread(30744):    at java.lang.Thread.run(Thread.java:856)
4

4 回答 4

10

解决方案 1。

如果您有一个带有 ItemClickListener 的 ListView 您必须在 overrive 方法 onPause 上将侦听器设置为 null。

listView.setOnItemClickListener(exampleListener);

示例:您的听众的声明

private OnItemClickListener exampleListener = new OnItemClickListener() {}....

@Override
    public void onPause() {

        super.onPause();

        listView.setOnItemClickListener(null);

    }

@Override
    public void onResume() {

        super.onResume();
            if(listView != null){
                listView.setOnItemClickListener(exampleListener);
             }
    }

解决方案 2 如果您知道您的广播接收器实例是什么,您必须注销始终取消覆盖方法 onPause。

@Override 受保护的无效 onPause() {

    super.onPause();
    synchronized (this) {
        if(broadcastReceiverInstance != null){
            unregisterReceiver(broadcastReceiverInstance );
        }
    }

}

我知道第二种解决方案对您不起作用,但我将其作为参考。

我希望它对你有帮助。

于 2013-11-05T22:25:03.950 回答
3

这是一个解决方法!我有一个三星标签 7" 4.2.2

问题原因:
1. 4.2.2
2. Layout.xml 中定义的 ListView
3. new ListView(this)

使固定:
1. 不要在 Layout 中声明 ListView,而是声明一个 holder
2. 使用 'getApplication()' 而不是 'this' 'new ListView(getApplication());'
3.addView(你的ListView)

布局文件.xml

    <RelativeLayout
        android:id="@+id/listViewHolder"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    </RelativeLayout>

Activity 中的 ListView

private void displayPostsInListView() {
    RelativeLayout listViewHolder = (RelativeLayout) findViewById(R.id.listViewHolder);
    listView = new ListView(getApplication());
    listViewHolder.addView(listView);
    listView.setOnItemClickListener(lineItemListener);

    adapter = new MyDisplayAdapter(this, listModel.getPostings());

    listView.setAdapter(adapter);
}
于 2013-11-18T09:02:20.520 回答
1

您必须在 Activity 中注册的任何接收器上调用 unregisterReceiver()。这通常在 onPause() 中。

于 2013-10-28T02:50:22.147 回答
1

如何识别导致泄漏的接收器并消除错误?

答案在您发布的 LogCat 中。

Activity com.ssowens.groovebasstrial.BassActivity has leaked IntentReceiver com.immersion.android.haptics.HapticFeedbackManager$HapticFeedbackBroadcastReceiver@41d166d0 that was originally registered here.

您注册了一个HapticFeedbackBroadcastReceiverin BassActivity,在您暂停或关闭应用程序时需要取消注册。正如@svenoaks 所说,您应该Activity.onPause()使用unregisterReceiver(referenceToReceiver);

于 2013-10-28T03:05:15.597 回答