我已经获得了谷歌的应用内应用计费应用程序(Dungeons)工作正常。但是,我正在尝试为我正在编写的应用注册第二个计费接收器,而我无法这样做。似乎只有在我的AndroidManifest.xml中声明的第一个接收器是接收广播的接收器,但是第一个接收器之后的任何接收器都不接收广播。在运行时,我已经通过使用isOrderedBroadcast()确认广播不是有序广播,所以它并不像我在某个地方中止广播(只有有序的广播可以被中止)。对此的任何帮助将不胜感激。
答案 0 :(得分:0)
也许第一个接收器需要在第二个接收器能够做它想做的事情之前取消注册。在您的活动中,覆盖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();
}
}