I am trying to send a broadcast from an ActivityInstrumentationTestCase2, as follows:
void myTest(){
getActivity().getBaseContext().sendBroadcast(
new Intent("com.my.broadcast.intent"));
sleep(100000);
}
The method executes without complaint; however, the receiver (an inputMethodService) enters an ANR state. The receiver method never executes using this approach. Testing using a more direct approach (sending a broadcast from within the activity) succeeds.
My question is, is there a limitation on ActivityInstrumentationTestCase2 that would prevent me from sending a broadcast? Can anyone explain why this error occurs?
Dont do the Sleep call. Also make sure you IntentFilter is set correctly. Your sendBroadcast code is fine.