Android的,无限重复动画与instrumentation.waitForIdleSync() [英] Android, Infinitely repeating animation vs. instrumentation.waitForIdleSync()

查看:1205
本文介绍了Android的,无限重复动画与instrumentation.waitForIdleSync()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有项目,一个自定义视图这是动画。动画是一个简单的阿尔法褪色其中无限重演。视图是一个光标,它使光标看起来像闪烁。当我开始写功能单元测试项目中,我遇到了这个问题,该 getActivity()方法将在设置挂方法,因为动画。 getActivity()电话 waitForIdleSync()返回之前,自动画开始之初, getActivity()永远不会返回。这其实是我花了相当长的时间来弄明白,我将开始测试,它会坐在那里什么都不做......这也将发生的时间100%。

我不认为这是一个错误,因为在技术上如果动画正在运行,该设备并没有闲着,但是这是一个问题。任何建议或解决方法,让动画运行,从一开始,而且还使用了 waitForIdleSync ActivityInstrumentationTestCase2s 将大大AP preciated。我可以实现一种变通方法不使用 waitForIdleSync()通过等待其他事件,以提供测试操作和应用程序的操作同步,但我还是要叫 getActivity()在一些点。一旦在这种方法中,不会返回具有无限重复动画。另外,动画有 onRestart 方法月底前开工的某个时候。理想的情况下,将有一个 waitForIdle(INT超时)方法。

我开始动画在错误的时间,还是我不开始使用正确的方法的动画?我开始/停止动画编程,因为有必要启动和停止的应用程序的闪烁现象。下面是code,我用它来启动动画。在 startBlinking(上下文)方法是从光标在名为构造...

 公共无效startBlinking(上下文的背景下){
    动画闪烁= AnimationUtils.loadAnimation(背景下,R.anim.cursor_blink);
    blink.setRepeatMode(Animation.RESTART);
    blink.setRepeatCount(Animation.INFINITE);
    startAnimation(眨眼);
}
 

解决方案

我有这个问题,并报告其作为的在AOSP 的错误,但我不希望任何人将任何时间很快修复它。我的解决方法是删除动画(这是具有挑战性的,因为它是不确定的进度视图)。一种选择为你的情况是改变动画的时间在你的测试,因此它不会动画的每一帧。不理想,但比冻结我怀疑更好的。

I have project with a custom view which is animated. The animation is a simple alpha fade which repeats itself infinitely. The view is a cursor, and it makes the cursor look like it is blinking. When I started writing functional unit tests for the project, I ran into the problem that the getActivity() method would hang in the setUp method due to the animation. getActivity() calls waitForIdleSync() before returning, and since the animation is started at the beginning, getActivity() never returns. This actually took me quite a bit of time to figure out, i would start the test and it would sit there doing nothing... This would also happen 100% of the time.

I wouldn't consider this a BUG, because technically if the animation is running, the device isn't idle, however this is an ISSUE. Any suggestions or workarounds to allow the animation to run, from the beginning, but also use the waitForIdleSync during ActivityInstrumentationTestCase2s would be greatly appreciated. I could implement a workaround to not use waitForIdleSync() by waiting for other events to provide synchronization with test actions and app actions, however I still HAVE to call the getActivity() at some point. Once in this method, it never returns with an infinite repeating animation. Also the animation has to start sometime before the end of the onRestart method. Ideally, there would be a waitForIdle(int timeout) method.

I am starting the animation at the wrong time, or am I not starting the animation using the correct methods? I start/stop the animation programmatically because there is a need to start and stop the blinking behavior in the app. below is the code which I use to start the animation. the startBlinking(Context) method is called from within the cursors constructor...

public void startBlinking(Context context){
    Animation blink = AnimationUtils.loadAnimation(context, R.anim.cursor_blink);
    blink.setRepeatMode(Animation.RESTART);
    blink.setRepeatCount(Animation.INFINITE);
    startAnimation(blink);
}

解决方案

I had this issue and reported it as a bug on AOSP, but I don't expect anyone will fix it any time soon. My workaround was to remove the animation (which was challenging, as it was the indefinite progress view). One option for your case would be to change the animation timing in your tests so it doesn't animate every frame. Not ideal, but better than freezing I suspect.

这篇关于Android的,无限重复动画与instrumentation.waitForIdleSync()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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