Skip to content

Instantly share code, notes, and snippets.

@akihito104
Last active July 2, 2016 06:23
Show Gist options
  • Save akihito104/e530894b9818e2438f38fe3197b6d51e to your computer and use it in GitHub Desktop.
Save akihito104/e530894b9818e2438f38fe3197b6d51e to your computer and use it in GitHub Desktop.
android instrumentation test for home button interaction
Intent home = new Intent();
home.setAction(Intent.ACTION_MAIN);
home.addCategory(Intent.CATEGORY_HOME);
home.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent relaunch = new Intent(rule.getActivity(), rule.getActivity().getClass());
relaunch.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
InstrumentationRegistry.getTargetContext().startActivity(home);
Thread.sleep(500); // XXX
rule.getActivity().startActivity(relaunch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment