首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >浓缩咖啡不适用于NineOldAndroids动画吗?

浓缩咖啡不适用于NineOldAndroids动画吗?
EN

Stack Overflow用户
提问于 2014-02-11 08:50:07
回答 2查看 1.4K关注 0票数 3

我正在尝试测试我的活动(HomeActivity),它具有基于Espresso的NineOldAndroids库的重复动画。我关闭了系统动画,正如描述的这里,但它没有帮助,我得到了一个错误(见下文)。唯一有帮助的是手动删除动画。所以问题是,我是否需要手动关闭动画(使用BuildConfig似乎是免费的),还是我做错了什么?提前谢谢你!

代码语言:javascript
复制
 java.lang.RuntimeException: Could not launch intent Intent {
 act=android.intent.action.MAIN flg=0x14000000
 cmp=com.package.en/com.package.ui.HomeActivity } within 45 seconds.
 Perhaps the main thread has not gone idle within a reasonable amount
 of time? There could be an animation or something constantly
 repainting the screen. Or the activity is doing network calls on
 creation? See the threaddump logs. For your reference the last time
 the event queue was idle before your activity launch request was
 1392052899081 and and now the last time the queue went idle was:
 1392052899081. If these numbers are the same your activity might be hogging the event 
 queue.
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-15 17:17:33

我对9个老机器人不太了解,但是对于Espresso,你应该禁用动画,这样你的测试才能变得可靠,你可能已经做到了。

因此,也许这就是通过添加一些禁用动画的代码来提高应用程序的“可测试性”的情况。例如,您的活动可能有一个禁用动画的方法,例如:

代码语言:javascript
复制
 public void disableAnimations() {
     this.mAnimationsEnabled = false;
 }

在每一个动画之前,你都要检查它们是否启用。一旦测试开始,就会禁用动画:

代码语言:javascript
复制
 public void setUp () {
    super.setUp();
     YourActivity activity = getActivity();
     activity.disableAnimations();
 }

 public void testXYZ() {
     // your test code
 }

我希望这能奏效,因为9岁的机器人将停止干扰Espresso。

票数 1
EN

Stack Overflow用户

发布于 2016-04-15 10:42:08

修正问题:

代码语言:javascript
复制
    @Before
    public void setUp() throws Exception {
        super.setUp();
        injectInstrumentation(InstrumentationRegistry.getInstrumentation());
        Intent intent = getIntent();
        if (intent == null) {
            intent = new Intent();
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        setActivityIntent(intent);
    }

    @SuppressLint("NewApi")
    @Override
    public T getActivity() {
        final T activity = super.getActivity();
        activity.overridePendingTransition(0, 0);
        return activity;
    }

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21697029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档