根据Google Dungeons示例,当我尝试实施应用内购买时,我似乎遇到了资源泄漏。
当在unbind()函数中调用unbindService()之后,MarketbillingService没有调用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;
}