为什么要在 IMarketBillingService 之上提供另一个服务?
Google 的 market_billing 示例,就像其他这个,连接通过本地服务包装器BillingService
到远程服务IMarketBillingService
。
我知道服务具有在后台执行操作的优点,但是远程 IMarketBillingService
还不够吗?
在洋葱上再加一层有什么好处?
如果我尝试在 UI 线程中直接从主活动连接到远程 IMarketBillingService
,我会失去什么?
如果不建议直接在 UI 线程中连接到远程 IMarketBillingService
,是否可以将本地 BillingService
替换为主活动中的另一个线程?
Google's market_billing sample, just like others as this one, connects to the remote service IMarketBillingService
through a local service wrapper, BillingService
.
I understand that services have the advantage of doing things in the background, but isn't the remote IMarketBillingService
enough?
What is the advantage of adding yet another layer to this onion?
What will I lose if I try to connect to the remote IMarketBillingService
directly from my main activity, in the UI thread?
If it isn't advisable to connect to the remote IMarketBillingService
directly in the UI thread, can the local BillingService
be replaced with just another thread in the main activity?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您的活动未运行时,本地 BillingService 会处理来自 IMarketBillingService 的回调。
参考( http://developer.android.com/reference/android/app/ Activity.html)说:
例如,如果您调用 RESTORE_TRANSACTIONS 计费请求,来自 Android Market 服务的响应可能需要一些时间才能到达。通过使用服务,您知道您将始终在附近处理响应,无论 Activity 生命周期如何
,我尝试编写一个小型测试应用程序,并且确信正在运行的线程可以调用暂停或停止的 Activity 上的方法,即使 Activity 处于运行状态。不在前台运行以下应用程序,按主屏幕停止应用程序 10 秒后返回,看到 TextView 已更改...
The local BillingService handles callbacks from the IMarketBillingService when your activity is not running.
The reference ( http://developer.android.com/reference/android/app/Activity.html) says:
If for example you invoke a RESTORE_TRANSACTIONS billing request, the responses from the Android Market Service may take some time to Arrive. By using a service, you know that you'll always be around to handle responses, regardless of Activity Lifecycle.
Just for fun, I tried to write a small test-app and was sureprised. A running thread can call methods on a paused- or stopped activity. The thread can also modify it's UI even when the activity is not in the foreground. Run the following application, press the home screen to stop the app. Go back after 10 seconds, and see that the TextView has changed...