3

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);
}
Coderji
  • 7,655
  • 5
  • 37
  • 51
phriendtj
  • 96
  • 2
  • 10
  • I think I have the same issue, which I described in [this question](http://stackoverflow.com/questions/20860832/why-does-getactivity-block-during-junit-test-when-custom-imageview-calls-start). Did you ever solve your issue? – Gary Sheppard Dec 31 '13 at 21:08

1 Answers1

1

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.

Steve Pomeroy
  • 10,071
  • 6
  • 34
  • 37