在本文中,我们将给您介绍关于为什么Android服务在测试时不是单身?的详细内容,并且为您解答android检测中心的相关问题,此外,我们还将为您提供关于android–为什么API22坚持附加到JD
在本文中,我们将给您介绍关于为什么Android服务在测试时不是单身?的详细内容,并且为您解答android检测中心的相关问题,此外,我们还将为您提供关于android – 为什么API 22坚持附加到JDK 1.6?、android – 为什么app服务重启,而无法重启?、android – 为什么Google图像服务在提供服务时将我的WEBP图像转换为JPG?、android – 在测试购买的情况下,为什么Google应用内结算会返回正确的orderId?的知识。
本文目录一览:- 为什么Android服务在测试时不是单身?(android检测中心)
- android – 为什么API 22坚持附加到JDK 1.6?
- android – 为什么app服务重启,而无法重启?
- android – 为什么Google图像服务在提供服务时将我的WEBP图像转换为JPG?
- android – 在测试购买的情况下,为什么Google应用内结算会返回正确的orderId?
为什么Android服务在测试时不是单身?(android检测中心)
从测试用例调用startService或bindService应该导致第二个onBind或onStartCommand,但是在第一个onDestroy之前不应该导致第二个onCreate.
这是因为单元测试是绕过Zygote吗?如果是这样,我该如何解决这个问题呢?
解决方法
I noticed that one of my Android Services isn’t singleton anymore
无论您是在真实运行环境下还是在仪器测试下启动/绑定,Android服务都是单例.单例,我指的是一个存在于堆中的唯一对象,它可以有多个引用指向它.
Calling startService or bindService from a testcase should result in a second onBind or onStartCommand
这不是正确的,正如官方开发指南中所述:“多个客户端可以同时连接到服务.但是,只有当第一个客户端绑定时,系统才会调用服务的onBind()方法来检索IBinder.系统然后交付与任何其他绑定客户端相同的IBinder,而无需再次调用onBind().“
but should never result in a second onCreate before the first onDestroy
根据官方开发指南:“如果您确实允许启动和绑定您的服务,那么当服务启动时,系统不会在所有客户端解除绑定时销毁服务.相反,您必须明确停止服务,调用stopSelf()或stopService().“
所以幕后的场景是,第一次调用start或bind服务时,调用Service.onCreate()方法((在调用onStartCommand()或onBind()之前)在堆上创建一个唯一的对象和一个引用返回它(引用计数= 1),之后,每次调用start或bind服务时,都会执行Service.onStartCommand()而不在堆上创建新对象(通过调用Service.onCreate()),而是返回同一个对象的第二个引用点(现在引用计数= 2),每次调用unbind时,引用计数减1,直到引用计数达到0,调用Service.onDestroy()方法并最终清理对象堆.
您可以从官方开发指南here找到我在斜体中引用的所有详细信息.
android – 为什么API 22坚持附加到JDK 1.6?
我在build.gradle中有以下内容:
compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 }
我可以使用1.7功能,但对话框一直显示1.6,这让我感到非常不安.我错过了什么吗?
谢谢
解决方法
android – 为什么app服务重启,而无法重启?
它是一个24 * 7的跟踪应用程序.每当它停止我使用START_REDELIVER_INTENT重新启动它,但它不是每次都启动.它在应用程序管理器中显示以下类型响应
请建议.
但是,START_STICKY会在终止后的几秒钟内重新启动服务.
android – 为什么Google图像服务在提供服务时将我的WEBP图像转换为JPG?
在上传到blobstore之前,它看起来像这样:
看起来像这样:
它由服务URL作为JPG提供,因此删除了alpha通道.在App Engine控制台的BlobStore查看器中,它已将content-type设置为application / octet-stream,即使上载的文件具有.webp文件扩展名.
根据Images API documentation,它应该支持WEBP.
上传图片时,我根本没有做任何奇特的事情:
List<BlobKey> blobs = blobstoreService.getUploads(req).get("file"); BlobKey blobKey = blobs.get(0); ImagesService imagesService = ImagesServiceFactory.getimagesService(); ServingUrlOptions servingOptions = ServingUrlOptions.Builder.withBlobKey(blobKey); String servingUrl = imagesService.getServingUrl(servingOptions);
编辑:
这是服务网址的示例:
example serving url
我试图使用Chrome和Android客户端访问它.
这是用于在Android客户端访问它的代码,虽然我不认为它是相关的:
URL url = new URL(Assets.getServingUrl(resourceName)); URLConnection connection = url.openConnection(); connection.connect(); String contentType = connection.getContentType(); String fileExt; if(contentType.contains("webp")) fileExt = ".webp"; else if(contentType.contains("png")) fileExt = ".png"; else if(contentType.contains("jpeg") || contentType.contains("jpg")) fileExt = ".jpg"; // download the file InputStream input = new BufferedInputStream(url.openStream(),8192); OutputStream output = MyApp.getAppContext().openFileOutput(resourceName + fileExt,Activity.MODE_PRIVATE); byte data[] = new byte[1024]; int count; while ((count = input.read(data)) != -1) { output.write(data,count); } output.flush(); output.close(); input.close();
希望通过Google Images API提供图像,因为图像可以动态调整大小.
谁能帮助我指出正确的方向来解决这个问题?
EDIT2:
我尝试直接通过blobstore提供blob,如下所示:blobstoreService.serve(new BlobKey(assetEntity.blobKey),res);而不是通过图像服务,然后它工作正常.但是,这不是一种选择,因为以这种方式服务它们所需的实例小时数会增加.但至少这会将问题缩小到图像服务.
解决方法
http://lh3.ggpht.com/MvNZDvZcBaq_B2MuAj0-Y74sc24WAsOVIQiJzsowu1rVG-ACzGO80xxD9y5OI5dWSCa_Nt41aMmWSSYAbpFE8dW7BhxozH2ikcVLjw=s600-rw
你得到了一个jpeg缩略图,因为这是使用webp时的默认设置,因为所有浏览器尚未完全支持该格式.
android – 在测试购买的情况下,为什么Google应用内结算会返回正确的orderId?
解决方法
如果是测试购买,则JSON响应不应包含orderId.已经确认了几次.确保您用于测试购买的帐户包含在Google Play开发者控制台>中的许可测试帐户中.应用设置>帐户详细信息,然后在“许可证测试”部分.
检查here
When your in-app Billing implementation is ready,you can test
purchasing of your in-app SKUs in two ways:Test purchases,which let your selected license-test users purchase
your in-app products without any resulting charges to the user. Test
purchases can be used in alpha/beta releases only.Real purchases,which let regular users make real purchases of your in-app products with actual charges to the user’s payment instruments.
关于为什么Android服务在测试时不是单身?和android检测中心的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于android – 为什么API 22坚持附加到JDK 1.6?、android – 为什么app服务重启,而无法重启?、android – 为什么Google图像服务在提供服务时将我的WEBP图像转换为JPG?、android – 在测试购买的情况下,为什么Google应用内结算会返回正确的orderId?等相关知识的信息别忘了在本站进行查找喔。
本文标签: