可以从Android ActivityInstrumentationTestCase2发送sendBroadcast吗?

时间:2012-06-06 13:08:28

标签: android junit

我正在尝试从ActivityInstrumentationTestCase2发送广播,如下所示:

void myTest(){
    getActivity().getBaseContext().sendBroadcast(
        new Intent("com.my.broadcast.intent"));
    sleep(100000);
}

该方法无怨无悔地执行;但是,接收器(inputMethodService)进入ANR状态。接收器方法永远不会使用这种方法执行。使用更直接的方法(从活动中发送广播)进行测试成功。

我的问题是,ActivityInstrumentationTestCase2是否有限制会阻止我发送广播?任何人都可以解释为什么会发生这种错误吗?

1 个答案:

答案 0 :(得分:0)

不要进行睡眠呼叫。还要确保正确设置了IntentFilter。你的sendBroadcast代码很好。

相关问题