【问题标题】:Only one BroadcastReceiver allowed to receive billing broadcasts for Android in-app billing?只允许一个 BroadcastReceiver 接收 Android 应用内计费的计费广播?
【发布时间】:2011-04-15 22:49:25
【问题描述】:

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

【问题讨论】:

    标签: android manifest broadcastreceiver broadcast billing


    【解决方案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();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      • 2012-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多