未从 MarketBillingService 获取 onServiceDisconnected
当我尝试根据 Google Dungeons 示例实现应用内购买时,似乎出现了资源泄漏。
当 MarketbillingService 在 unbind() 函数中调用 unbindService() 后没有调用 onServiceDisconnected() 时(所有这些都在 BillingService 类中),就会出现问题。
所以我的问题是:如何将 ServiceConnection 发布到 MarketBillingService?
/**
* This class sends messages to Android Market on behalf of the application by
* connecting (binding) to the MarketBillingService. The application
* creates an instance of this class and invokes billing requests through this service.
*
* The {@link BillingReceiver} class starts this service to process commands
* that it receives from Android Market.
*
* You should modify and obfuscate this code before using it.
*/
public class BillingService extends Service implements ServiceConnection {
[...]
/**
* Unbinds from the MarketBillingService. Call this when the application
* terminates to avoid leaking a ServiceConnection.
*/
public void unbind() {
try {
unbindService(this);
} catch (IllegalArgumentException e) {
// This might happen if the service was disconnected
}
}
/**
* This is called when we are disconnected from the MarketBillingService.
*/
public void onServiceDisconnected(ComponentName name) {
Log.w(TAG, "Billing service disconnected");
mService = null;
}
It seems that I get a resource leak when I try to implement in-app purchase according to the Google Dungeons example.
The problem arises when the MarketbillingService does not call onServiceDisconnected() after a call to unbindService() in the unbind() function (All of which are in the BillingService class).
So my problem is this: How do I release the ServiceConnection to the MarketBillingService?
/**
* This class sends messages to Android Market on behalf of the application by
* connecting (binding) to the MarketBillingService. The application
* creates an instance of this class and invokes billing requests through this service.
*
* The {@link BillingReceiver} class starts this service to process commands
* that it receives from Android Market.
*
* You should modify and obfuscate this code before using it.
*/
public class BillingService extends Service implements ServiceConnection {
[...]
/**
* Unbinds from the MarketBillingService. Call this when the application
* terminates to avoid leaking a ServiceConnection.
*/
public void unbind() {
try {
unbindService(this);
} catch (IllegalArgumentException e) {
// This might happen if the service was disconnected
}
}
/**
* This is called when we are disconnected from the MarketBillingService.
*/
public void onServiceDisconnected(ComponentName name) {
Log.w(TAG, "Billing service disconnected");
mService = null;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论