Activityinstrumentationtestcase2 Issues - Test Hangs Because Of Invalidate() Call In The Code I'm Writing A Test For
I'm implementing a test for some code I've written which I have distilled down into a sample project pasted below. The problem I am having is that the test hangs the test runner an
Solution 1:
Try postInvalidate() instead of invalidate().
I'm not 100% sure what's going on but I suspect there's something in your code that's blocking the UI thread. Using postInvalidate() will return right away and let your code finish, which will unblock the UI thread.
Solution 2:
Problem solved!
the invalidate call is NOT needed.. it screws things up PERIOD!
The trick was to add a method to HelloGallery.java to set the center position and to call setPosition on the super class.
HelloGallery.java
publicvoidsetSelectionToCenter(int position){
mCenterViewPositionIndex = position;
setSelection(mCenterViewPositionIndex);
}
Then in HelloGalleryActivity call the setSelectionToCenter method rather than setSelection.
HelloGalleryActivity
public void onCreate(Bundle savedInstanceState) {
...
((HelloGallery)mGallery).setSelectionToCenter(adapter.MIDDLE);
...
}
The test runs like a charm now! Woot! Thanks goes out to Betsy the mystery developer for tracking this down for me!
Post a Comment for "Activityinstrumentationtestcase2 Issues - Test Hangs Because Of Invalidate() Call In The Code I'm Writing A Test For"