你怎么能知道,当一个Android活动完成加载? [英] how can you tell when an Android activity is finished loading?

查看:99
本文介绍了你怎么能知道,当一个Android活动完成加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在工作的一个自动化测试套件为我们的Andr​​oid应用程序,并运行陷入困境等活动,完全加载的过程。我可以打电话getActivity,只是因为它表明我希望看到在我的测试并不似乎总是意味着该活动的组成部分是准备使用的活动(满载)。翻翻活动API并没有把任何东西,和其他方法显得过于侵入并破坏了测试初始状态。有谁知道,如果有一种方法来询问应用程序或虚拟机如果已装入当前的活动?

I'm in the process of working on an automated test suite for our android app, and running into trouble waiting for activities to fully load. I can call getActivity, but just because it shows the activity that I'm hoping to see in my test doesn't always seem to mean that the activity's components are ready for use (fully loaded). Looking through the Activity API didn't turn anything up, and other methods seem too invasive and have spoiled the tests initial state. Does anyone know if there's a way to ask the app or the VM if the current activity is loaded?

推荐答案

我在<一提到href="http://stackoverflow.com/questions/2089489/how-can-you-tell-when-an-android-activity-is-finished-loading#comment-2022516">a评论,您的视图层次应您的来电后工作的setContentView()的onCreate()早 。我从来没有像这样的任何问题,任何活动或测试类。

As I mentioned in a comment, your view hierarchy should be working after your call to setContentView() early in onCreate(). I've never had any problems like this with any activity or test class..

我不知道这是任何帮助,这种特殊情况下,但一般可以通过调用的 getInstrumentation()。waitForIdleSync() 。这将阻塞,直到有没有更多的UI事件的过程。

I'm not sure this is of any help for this specific case, but in general you can determine when the UI event queue is empty by calling getInstrumentation().waitForIdleSync(). That'll block until there's no more UI events to process.

这篇关于你怎么能知道,当一个Android活动完成加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆