1

我已经让 Google 的示例应用内计费应用程序 (Dungeons) 运行良好。但是,我正在尝试为我正在编写的应用程序注册第二个计费接收方,但我无法这样做。似乎只有我的 AndroidManifest.xml 中声明的第一个接收器是接收广播的接收器,但第一个接收器之后的任何接收器都不会接收广播。在运行时,我已经通过使用 isOrderedBroadcast() 确认广播不是有序广播,所以我并不是在某处中止广播(只能中止有序广播)。对此的任何帮助将不胜感激。

4

1 回答 1

1

也许第一个接收者需要在第二个接收者可以做它试图做的事情之前取消注册。在您的活动中,覆盖 onStop() 方法,以便在活动关闭时取消注册广播接收器。这对我有用。

// Import statements go here.

public class MyActivity extends AppCompatActivity implements IabBroadcastReceiver.IabBroadcastListener {

    // Other variables and methods go here.

    // Unregister the receiver when the activity closes.
    @Override
    protected void onStop()
    {
        try {
            unregisterReceiver(YOUR_BROADCAST_RECEIVER_VARIABLE_NAME_HERE);
        } catch (Exception ex) {
            // Uncomment the following for debugging.
            //ex.printStackTrace();
        }

        // Call the original onStop() method.
        super.onStop();
    }
}
于 2016-08-02T13:55:49.597 回答