0

I am using Robotium for testing android applications and am interested in how to detect a situation when an external application activity (e.g. browser, camera, facebook) is being launched by tested app. There are several questions asking how to handle such situation, but all I need is to detect it, for example just log time when it's occurred. Is this possible using Robotium or simple Instrumentation?

BTW, I can't use the solution when system apps are being replaced by fake analogues, I can't even know what application (and when) will be launched, because the tests are random. (Yes, I know, it's a bad approach, but this is a project restriction).

Community
  • 1
  • 1
Roman Petrenko
  • 1,052
  • 1
  • 9
  • 21

2 Answers2

0

See my answer here. The main idea is to detect current top Activity, which is Activity of external application. You can create Service, which will monitor top activities.

Community
  • 1
  • 1
Veaceslav Gaidarji
  • 4,261
  • 3
  • 38
  • 61
  • 1
    Thanks, your solution seems acceptable. I think there may be some possibility to do this using Instrumentation advantages, so I'll give your answer a day or two before accept it. – Roman Petrenko Apr 03 '14 at 08:13
  • If you find same functionality in Instrumentation advantages - it will very useful. mutual assistance ;) – Veaceslav Gaidarji Apr 03 '14 at 08:15
0

Anther way is to check when your activity looses focus. When it looses focus that means that the other external Activity has focus instead.

http://developer.android.com/reference/android/app/Activity.html#hasWindowFocus()

You can use Solo.waitForCondition() in conjunction with hasWindowFocus.

Renas
  • 1,919
  • 1
  • 18
  • 17