1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119<!DOCTYPE html> 120<html devsite> 121<head> 122 123 124 <meta name="top_category" value="develop" /> 125 126 <meta name="subcategory" value="reference" /> 127 128 129 <meta name="book_path" value="/reference/android/support/test/_book.yaml" /> 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145<title>ActivityTestRule</title> 146 147 148</head> 149 150<body class="gc-documentation develop reference api apilevel-"> 151<div id="doc-api-level" class="" style="display:none"></div> 152 153 154 155 156<div id="naMessage"></div> 157 158<div id="api-info-block"> 159<div class="api-level"> 160 161 162 163 164</div> 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190<div class="sum-details-links"> 191 192Summary: 193 194 195 196 197 198 199 200 201 202 <a href="#pubctors">Ctors</a> 203 204 205 206 207 | <a href="#pubmethods">Methods</a> 208 209 210 211 | <a href="#promethods">Protected Methods</a> 212 213 214 215 | <a href="#inhmethods">Inherited Methods</a> 216 217| <a href="#" onclick="return toggleAllClassInherited()" id="toggleAllClassInherited">[Expand All]</a> 218 219</div><!-- end sum-details-links --> 220</div><!-- end api-info-block --> 221 222<div class="api apilevel-" id="jd-content"> 223 224<!-- ======== START OF CLASS DATA ======== --> 225 226<h1 class="api-title">ActivityTestRule</h1> 227<p> 228<code class="api-signature"> 229 public 230 231 232 233 class 234 ActivityTestRule 235</code> 236<br> 237 238 239<code class="api-signature"> 240 241 242 243</code> 244 245<code class="api-signature"> 246 247 extends <a href="/reference/android/support/test/rule/UiThreadTestRule.html">UiThreadTestRule</a> 248 249 250 251</code> 252 253<code class="api-signature"> 254 255 256 257</code> 258 259</p><table class="jd-inheritance-table"> 260 261 262 <tr> 263 264 <td colspan="3" class="jd-inheritance-class-cell">java.lang.Object 265 </td> 266 </tr> 267 268 269 <tr> 270 271 <td class="jd-inheritance-space"> ↳</td> 272 273 <td colspan="2" class="jd-inheritance-class-cell"><a href="/reference/android/support/test/rule/UiThreadTestRule.html">android.support.test.rule.UiThreadTestRule</a> 274 </td> 275 </tr> 276 277 278 <tr> 279 280 <td class="jd-inheritance-space"> </td> 281 282 <td class="jd-inheritance-space"> ↳</td> 283 284 <td colspan="1" class="jd-inheritance-class-cell">android.support.test.rule.ActivityTestRule<T extends android.app.Activity> 285 </td> 286 </tr> 287 288 289</table> 290 <table class="jd-sumtable jd-sumtable-subclasses"> 291 <tr><td style="border:none;margin:0;padding:0;"> 292 293 <a href="#" onclick="return toggleInherited(this, null)" id="subclasses-direct" class="jd-expando-trigger closed" 294 ><img height="34" id="subclasses-direct-trigger" 295 src="/assets/images/styles/disclosure_down.png" 296 class="jd-expando-trigger-img" /></a>Known Direct Subclasses 297 298 <div id="subclasses-direct"> 299 <div id="subclasses-direct-list" 300 class="jd-inheritedlinks" 301 302 > 303 304 305 <a href="/reference/android/support/test/espresso/intent/rule/IntentsTestRule.html">IntentsTestRule</a><T extends Activity> 306 307 308 </div> 309 <div id="subclasses-direct-summary" 310 style="display: none;" 311 > 312 313 <table class="jd-sumtable-expando"> 314 315 <tr class="alt-color api apilevel-" > 316 <td class="jd-linkcol"><a href="/reference/android/support/test/espresso/intent/rule/IntentsTestRule.html">IntentsTestRule</a><T extends Activity></td> 317 <td class="jd-descrcol" width="100%"> 318 This rule makes it easy to use Espresso-Intents APIs in functional UI tests. 319 320 321 322 </td> 323 </tr> 324 325 326 </table> 327 328 </div> 329 </div> 330 </td></tr> 331 </table> 332 333 334 335 336 337<br><hr> 338 339 340 <p>This rule provides functional testing of a single activity. The activity under test will be 341 launched before each test annotated with 342 <a href="http://junit.org/javadoc/latest/org/junit/Test.html"><code>Test</code></a> and before 343 methods annotated with 344 <a href="http://junit.sourceforge.net/javadoc/org/junit/Before.html"><code>Before</code></a>. It 345 will be terminated after the test is completed and methods annotated with 346 <a href="http://junit.sourceforge.net/javadoc/org/junit/After.html"><code>After</code></a> are 347 finished. During the duration of the test you will be able to manipulate your Activity directly.</p> 348 349 350 351 352 353 354 355<h2 class="api-section">Summary</h2> 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379<!-- ======== CONSTRUCTOR SUMMARY ======== --> 380<table id="pubctors" class="responsive constructors"> 381<tr><th colspan="2"><h3>Public constructors</h3></th></tr> 382 383 384 385 386 <tr class="api apilevel-" > 387 388 389 <td width="100%"> 390 <code> 391 <a href="/reference/android/support/test/rule/ActivityTestRule.html#ActivityTestRule(java.lang.Class<T>)">ActivityTestRule</a>(Class<T> activityClass) 392 </code> 393 394 <p>Similar to <code><a href="/reference/android/support/test/rule/ActivityTestRule.html#ActivityTestRule(java.lang.Class<T>, boolean, boolean)">ActivityTestRule(Class, boolean, boolean)</a></code> but with "touch mode" disabled. 395 396 397</p> 398 399 </td> 400 </tr> 401 402 403 404 <tr class="api apilevel-" > 405 406 407 <td width="100%"> 408 <code> 409 <a href="/reference/android/support/test/rule/ActivityTestRule.html#ActivityTestRule(java.lang.Class<T>, boolean)">ActivityTestRule</a>(Class<T> activityClass, boolean initialTouchMode) 410 </code> 411 412 <p>Similar to <code><a href="/reference/android/support/test/rule/ActivityTestRule.html#ActivityTestRule(java.lang.Class<T>, boolean, boolean)">ActivityTestRule(Class, boolean, boolean)</a></code> but defaults to launch the 413 activity under test once per 414 <a href="http://junit.org/javadoc/latest/org/junit/Test.html"><code>Test</code></a> method. 415 416 417</p> 418 419 </td> 420 </tr> 421 422 423 424 <tr class="api apilevel-" > 425 426 427 <td width="100%"> 428 <code> 429 <a href="/reference/android/support/test/rule/ActivityTestRule.html#ActivityTestRule(java.lang.Class<T>, boolean, boolean)">ActivityTestRule</a>(Class<T> activityClass, boolean initialTouchMode, boolean launchActivity) 430 </code> 431 432 <p>Creates an <code><a href="/reference/android/support/test/rule/ActivityTestRule.html">ActivityTestRule</a></code> for the Activity under test. 433 434 435</p> 436 437 </td> 438 </tr> 439 440 441 442</table> 443 444 445 446 447 448 449<!-- ========== METHOD SUMMARY =========== --> 450<table id="pubmethods" class="responsive methods"> 451<tr><th colspan="2"><h3>Public methods</h3></th></tr> 452 453 454 455 456 <tr class="api apilevel-" > 457 458 459 <td><code> 460 461 462 463 464 465 Statement</code> 466 </td> 467 468 <td width="100%"> 469 <code> 470 <a href="/reference/android/support/test/rule/ActivityTestRule.html#apply(org.junit.runners.model.Statement, org.junit.runner.Description)">apply</a>(Statement base, Description description) 471 </code> 472 473 </td> 474 </tr> 475 476 477 478 <tr class="api apilevel-" > 479 480 481 <td><code> 482 483 484 485 486 487 T</code> 488 </td> 489 490 <td width="100%"> 491 <code> 492 <a href="/reference/android/support/test/rule/ActivityTestRule.html#getActivity()">getActivity</a>() 493 </code> 494 495 </td> 496 </tr> 497 498 499 500 <tr class="api apilevel-" > 501 502 503 <td><code> 504 505 506 507 508 509 T</code> 510 </td> 511 512 <td width="100%"> 513 <code> 514 <a href="/reference/android/support/test/rule/ActivityTestRule.html#launchActivity(android.content.Intent)">launchActivity</a>(Intent startIntent) 515 </code> 516 517 <p>Launches the Activity under test. 518 519 520</p> 521 522 </td> 523 </tr> 524 525 526 527</table> 528 529 530 531 532<!-- ========== METHOD SUMMARY =========== --> 533<table id="promethods" class="reponsive methods"> 534<tr><th colspan="2"><h3>Protected methods</h3></th></tr> 535 536 537 538 539 <tr class="api apilevel-" > 540 541 542 <td><code> 543 544 545 546 547 548 void</code> 549 </td> 550 551 <td width="100%"> 552 <code> 553 <a href="/reference/android/support/test/rule/ActivityTestRule.html#afterActivityFinished()">afterActivityFinished</a>() 554 </code> 555 556 <p>Override this method to execute any code that should run after your <code><a href="/reference/android/app/Activity.html">Activity</a></code> is 557 finished. 558 559 560</p> 561 562 </td> 563 </tr> 564 565 566 567 <tr class="api apilevel-" > 568 569 570 <td><code> 571 572 573 574 575 576 void</code> 577 </td> 578 579 <td width="100%"> 580 <code> 581 <a href="/reference/android/support/test/rule/ActivityTestRule.html#afterActivityLaunched()">afterActivityLaunched</a>() 582 </code> 583 584 <p>Override this method to execute any code that should run after your <code><a href="/reference/android/app/Activity.html">Activity</a></code> is 585 launched, but before any test code is run including any method annotated with 586 <a href="http://junit.sourceforge.net/javadoc/org/junit/Before.html"><code>Before</code></a>. 587 588 589</p> 590 591 </td> 592 </tr> 593 594 595 596 <tr class="api apilevel-" > 597 598 599 <td><code> 600 601 602 603 604 605 void</code> 606 </td> 607 608 <td width="100%"> 609 <code> 610 <a href="/reference/android/support/test/rule/ActivityTestRule.html#beforeActivityLaunched()">beforeActivityLaunched</a>() 611 </code> 612 613 <p>Override this method to execute any code that should run before your <code><a href="/reference/android/app/Activity.html">Activity</a></code> is 614 created and launched. 615 616 617</p> 618 619 </td> 620 </tr> 621 622 623 624 <tr class="api apilevel-" > 625 626 627 <td><code> 628 629 630 631 632 633 Intent</code> 634 </td> 635 636 <td width="100%"> 637 <code> 638 <a href="/reference/android/support/test/rule/ActivityTestRule.html#getActivityIntent()">getActivityIntent</a>() 639 </code> 640 641 <p>Override this method to set up Intent as if supplied to 642 <code><a href="/reference/android/content/Context.html#startActivity(android.content.Intent)">startActivity(Intent)</a></code>. 643 644 645</p> 646 647 </td> 648 </tr> 649 650 651 652</table> 653 654 655 656 657 658<!-- ========== METHOD SUMMARY =========== --> 659<table id="inhmethods" class="methods inhtable"> 660<tr><th><h3>Inherited methods</h3></th></tr> 661 662 663<tr class="api apilevel-" > 664<td colspan="2"> 665 666 <a href="#" onclick="return toggleInherited(this, null)" id="inherited-methods-android.support.test.rule.UiThreadTestRule" class="jd-expando-trigger closed" 667 ><img height="34" id="inherited-methods-android.support.test.rule.UiThreadTestRule-trigger" 668 src="/assets/images/styles/disclosure_down.png" 669 class="jd-expando-trigger-img" /></a>From 670class 671<code> 672 673 <a href="/reference/android/support/test/rule/UiThreadTestRule.html">android.support.test.rule.UiThreadTestRule</a> 674 675</code> 676<div id="inherited-methods-android.support.test.rule.UiThreadTestRule"> 677 <div id="inherited-methods-android.support.test.rule.UiThreadTestRule-list" 678 class="jd-inheritedlinks"> 679 </div> 680 <div id="inherited-methods-android.support.test.rule.UiThreadTestRule-summary" style="display: none;"> 681 <table class="jd-sumtable-expando responsive"> 682 683 684 685 686 <tr class="api apilevel-" > 687 688 689 <td><code> 690 691 692 693 694 695 Statement</code> 696 </td> 697 698 <td width="100%"> 699 <code> 700 <a href="/reference/android/support/test/rule/UiThreadTestRule.html#apply(org.junit.runners.model.Statement, org.junit.runner.Description)">apply</a>(Statement base, Description description) 701 </code> 702 703 </td> 704 </tr> 705 706 707 708 <tr class="api apilevel-" > 709 710 711 <td><code> 712 713 714 715 716 717 void</code> 718 </td> 719 720 <td width="100%"> 721 <code> 722 <a href="/reference/android/support/test/rule/UiThreadTestRule.html#runOnUiThread(java.lang.Runnable)">runOnUiThread</a>(Runnable runnable) 723 </code> 724 725 <p>Helper for running portions of a test on the UI thread. 726 727 728</p> 729 730 </td> 731 </tr> 732 733 734 735 <tr class="api apilevel-" > 736 737 738 <td><code> 739 740 741 742 743 744 boolean</code> 745 </td> 746 747 <td width="100%"> 748 <code> 749 <a href="/reference/android/support/test/rule/UiThreadTestRule.html#shouldRunOnUiThread(org.junit.runner.Description)">shouldRunOnUiThread</a>(Description description) 750 </code> 751 752 </td> 753 </tr> 754 755 756 757 </table> 758 </div> 759</div> 760</td></tr> 761 762 763 764<tr class="api apilevel-" > 765<td colspan="2"> 766 767 <a href="#" onclick="return toggleInherited(this, null)" id="inherited-methods-java.lang.Object" class="jd-expando-trigger closed" 768 ><img height="34" id="inherited-methods-java.lang.Object-trigger" 769 src="/assets/images/styles/disclosure_down.png" 770 class="jd-expando-trigger-img" /></a>From 771class 772<code> 773 774 java.lang.Object 775 776</code> 777<div id="inherited-methods-java.lang.Object"> 778 <div id="inherited-methods-java.lang.Object-list" 779 class="jd-inheritedlinks"> 780 </div> 781 <div id="inherited-methods-java.lang.Object-summary" style="display: none;"> 782 <table class="jd-sumtable-expando responsive"> 783 784 785 786 787 <tr class="api apilevel-" > 788 789 790 <td><code> 791 792 793 794 795 796 Object</code> 797 </td> 798 799 <td width="100%"> 800 <code> 801 clone() 802 </code> 803 804 </td> 805 </tr> 806 807 808 809 <tr class="api apilevel-" > 810 811 812 <td><code> 813 814 815 816 817 818 boolean</code> 819 </td> 820 821 <td width="100%"> 822 <code> 823 equals(Object arg0) 824 </code> 825 826 </td> 827 </tr> 828 829 830 831 <tr class="api apilevel-" > 832 833 834 <td><code> 835 836 837 838 839 840 void</code> 841 </td> 842 843 <td width="100%"> 844 <code> 845 finalize() 846 </code> 847 848 </td> 849 </tr> 850 851 852 853 <tr class="api apilevel-" > 854 855 856 <td><code> 857 858 859 860 final 861 862 Class<?></code> 863 </td> 864 865 <td width="100%"> 866 <code> 867 getClass() 868 </code> 869 870 </td> 871 </tr> 872 873 874 875 <tr class="api apilevel-" > 876 877 878 <td><code> 879 880 881 882 883 884 int</code> 885 </td> 886 887 <td width="100%"> 888 <code> 889 hashCode() 890 </code> 891 892 </td> 893 </tr> 894 895 896 897 <tr class="api apilevel-" > 898 899 900 <td><code> 901 902 903 904 final 905 906 void</code> 907 </td> 908 909 <td width="100%"> 910 <code> 911 notify() 912 </code> 913 914 </td> 915 </tr> 916 917 918 919 <tr class="api apilevel-" > 920 921 922 <td><code> 923 924 925 926 final 927 928 void</code> 929 </td> 930 931 <td width="100%"> 932 <code> 933 notifyAll() 934 </code> 935 936 </td> 937 </tr> 938 939 940 941 <tr class="api apilevel-" > 942 943 944 <td><code> 945 946 947 948 949 950 String</code> 951 </td> 952 953 <td width="100%"> 954 <code> 955 toString() 956 </code> 957 958 </td> 959 </tr> 960 961 962 963 <tr class="api apilevel-" > 964 965 966 <td><code> 967 968 969 970 final 971 972 void</code> 973 </td> 974 975 <td width="100%"> 976 <code> 977 wait(long arg0, int arg1) 978 </code> 979 980 </td> 981 </tr> 982 983 984 985 <tr class="api apilevel-" > 986 987 988 <td><code> 989 990 991 992 final 993 994 void</code> 995 </td> 996 997 <td width="100%"> 998 <code> 999 wait(long arg0) 1000 </code> 1001 1002 </td> 1003 </tr> 1004 1005 1006 1007 <tr class="api apilevel-" > 1008 1009 1010 <td><code> 1011 1012 1013 1014 final 1015 1016 void</code> 1017 </td> 1018 1019 <td width="100%"> 1020 <code> 1021 wait() 1022 </code> 1023 1024 </td> 1025 </tr> 1026 1027 1028 1029 </table> 1030 </div> 1031</div> 1032</td></tr> 1033 1034 1035 1036<tr class="api apilevel-" > 1037<td colspan="2"> 1038 1039 <a href="#" onclick="return toggleInherited(this, null)" id="inherited-methods-org.junit.rules.TestRule" class="jd-expando-trigger closed" 1040 ><img height="34" id="inherited-methods-org.junit.rules.TestRule-trigger" 1041 src="/assets/images/styles/disclosure_down.png" 1042 class="jd-expando-trigger-img" /></a>From 1043interface 1044<code> 1045 1046 org.junit.rules.TestRule 1047 1048</code> 1049<div id="inherited-methods-org.junit.rules.TestRule"> 1050 <div id="inherited-methods-org.junit.rules.TestRule-list" 1051 class="jd-inheritedlinks"> 1052 </div> 1053 <div id="inherited-methods-org.junit.rules.TestRule-summary" style="display: none;"> 1054 <table class="jd-sumtable-expando responsive"> 1055 1056 1057 1058 1059 <tr class="api apilevel-" > 1060 1061 1062 <td><code> 1063 abstract 1064 1065 1066 1067 1068 Statement</code> 1069 </td> 1070 1071 <td width="100%"> 1072 <code> 1073 apply(Statement arg0, Description arg1) 1074 </code> 1075 1076 </td> 1077 </tr> 1078 1079 1080 1081 </table> 1082 </div> 1083</div> 1084</td></tr> 1085 1086 1087</table> 1088 1089 1090 1091<!-- XML Attributes --> 1092 1093 1094<!-- Enum Values --> 1095 1096 1097<!-- Constants --> 1098 1099 1100<!-- Fields --> 1101 1102 1103<!-- Public ctors --> 1104 1105 1106<!-- ========= CONSTRUCTOR DETAIL ======== --> 1107<h2 class="api-section">Public constructors</h2> 1108 1109 1110 1111<A NAME="ActivityTestRule(java.lang.Class<T>)"></A> 1112 1113<div class="api apilevel-"> 1114 <h3 class="api-name">ActivityTestRule</h3> 1115 <div class="api-level"> 1116 <div></div> 1117 1118 1119 1120 </div> 1121<pre class="api-signature no-pretty-print"> 1122ActivityTestRule (Class<T> activityClass)</pre> 1123 1124 1125 1126 1127 <p>Similar to <code><a href="/reference/android/support/test/rule/ActivityTestRule.html#ActivityTestRule(java.lang.Class<T>, boolean, boolean)">ActivityTestRule(Class, boolean, boolean)</a></code> but with "touch mode" disabled.</p> 1128 <table class="responsive"> 1129 <tr><th colspan=2>Parameters</th></tr> 1130 <tr> 1131 <td><code>activityClass</code></td> 1132 <td width="100%"> 1133 <code>Class</code>: 1134 The activity under test. This must be a class in the instrumentation 1135 targetPackage specified in the AndroidManifest.xml</td> 1136 </tr> 1137 </table> 1138 <div> 1139 <p><b>See also:</b></p> 1140 <ul class="nolist"><li><code><a href="/reference/android/support/test/rule/ActivityTestRule.html#ActivityTestRule(java.lang.Class<T>, boolean, boolean)">ActivityTestRule(Class, boolean, boolean)</a></code></li> 1141 </ul> 1142 </div> 1143 1144</div> 1145 1146 1147<A NAME="ActivityTestRule(java.lang.Class<T>, boolean)"></A> 1148 1149<div class="api apilevel-"> 1150 <h3 class="api-name">ActivityTestRule</h3> 1151 <div class="api-level"> 1152 <div></div> 1153 1154 1155 1156 </div> 1157<pre class="api-signature no-pretty-print"> 1158ActivityTestRule (Class<T> activityClass, 1159 boolean initialTouchMode)</pre> 1160 1161 1162 1163 1164 <p>Similar to <code><a href="/reference/android/support/test/rule/ActivityTestRule.html#ActivityTestRule(java.lang.Class<T>, boolean, boolean)">ActivityTestRule(Class, boolean, boolean)</a></code> but defaults to launch the 1165 activity under test once per 1166 <a href="http://junit.org/javadoc/latest/org/junit/Test.html"><code>Test</code></a> method. 1167 It is launched before the first 1168 <a href="http://junit.sourceforge.net/javadoc/org/junit/Before.html"><code>Before</code></a> 1169 method, and terminated after the last 1170 <a href="http://junit.sourceforge.net/javadoc/org/junit/After.html"><code>After</code></a> 1171 method.</p> 1172 <table class="responsive"> 1173 <tr><th colspan=2>Parameters</th></tr> 1174 <tr> 1175 <td><code>activityClass</code></td> 1176 <td width="100%"> 1177 <code>Class</code>: 1178 The activity under test. This must be a class in the instrumentation 1179 targetPackage specified in the AndroidManifest.xml</td> 1180 </tr> 1181 <tr> 1182 <td><code>initialTouchMode</code></td> 1183 <td width="100%"> 1184 <code>boolean</code>: 1185 true if the Activity should be placed into "touch mode" when started</td> 1186 </tr> 1187 </table> 1188 <div> 1189 <p><b>See also:</b></p> 1190 <ul class="nolist"><li><code><a href="/reference/android/support/test/rule/ActivityTestRule.html#ActivityTestRule(java.lang.Class<T>, boolean, boolean)">ActivityTestRule(Class, boolean, boolean)</a></code></li> 1191 </ul> 1192 </div> 1193 1194</div> 1195 1196 1197<A NAME="ActivityTestRule(java.lang.Class<T>, boolean, boolean)"></A> 1198 1199<div class="api apilevel-"> 1200 <h3 class="api-name">ActivityTestRule</h3> 1201 <div class="api-level"> 1202 <div></div> 1203 1204 1205 1206 </div> 1207<pre class="api-signature no-pretty-print"> 1208ActivityTestRule (Class<T> activityClass, 1209 boolean initialTouchMode, 1210 boolean launchActivity)</pre> 1211 1212 1213 1214 1215 <p>Creates an <code><a href="/reference/android/support/test/rule/ActivityTestRule.html">ActivityTestRule</a></code> for the Activity under test.</p> 1216 <table class="responsive"> 1217 <tr><th colspan=2>Parameters</th></tr> 1218 <tr> 1219 <td><code>activityClass</code></td> 1220 <td width="100%"> 1221 <code>Class</code>: 1222 The activity under test. This must be a class in the instrumentation 1223 targetPackage specified in the AndroidManifest.xml</td> 1224 </tr> 1225 <tr> 1226 <td><code>initialTouchMode</code></td> 1227 <td width="100%"> 1228 <code>boolean</code>: 1229 true if the Activity should be placed into "touch mode" when started</td> 1230 </tr> 1231 <tr> 1232 <td><code>launchActivity</code></td> 1233 <td width="100%"> 1234 <code>boolean</code>: 1235 true if the Activity should be launched once per 1236 <a href="http://junit.org/javadoc/latest/org/junit/Test.html"> 1237 <code>Test</code></a> method. It will be launched before the first 1238 <a href="http://junit.sourceforge.net/javadoc/org/junit/Before.html"> 1239 <code>Before</code></a> method, and terminated after the last 1240 <a href="http://junit.sourceforge.net/javadoc/org/junit/After.html"> 1241 <code>After</code></a> method. 1242</td> 1243 </tr> 1244 </table> 1245 1246</div> 1247 1248 1249 1250 1251 1252<!-- ========= CONSTRUCTOR DETAIL ======== --> 1253<!-- Protected ctors --> 1254 1255 1256 1257<!-- ========= METHOD DETAIL ======== --> 1258<!-- Public methdos --> 1259 1260<h2 class="api-section">Public methods</h2> 1261 1262 1263 1264<A NAME="apply(org.junit.runners.model.Statement, org.junit.runner.Description)"></A> 1265 1266<div class="api apilevel-"> 1267 <h3 class="api-name">apply</h3> 1268 <div class="api-level"> 1269 <div></div> 1270 1271 1272 1273 </div> 1274<pre class="api-signature no-pretty-print"> 1275Statement apply (Statement base, 1276 Description description)</pre> 1277 1278 1279 1280 1281 <p></p> 1282 <table class="responsive"> 1283 <tr><th colspan=2>Parameters</th></tr> 1284 <tr> 1285 <td><code>base</code></td> 1286 <td width="100%"> 1287 <code>Statement</code> 1288 <!-- no parameter comment --></td> 1289 </tr> 1290 <tr> 1291 <td><code>description</code></td> 1292 <td width="100%"> 1293 <code>Description</code> 1294 <!-- no parameter comment --></td> 1295 </tr> 1296 </table> 1297 <table class="responsive"> 1298 <tr><th colspan=2>Returns</th></tr> 1299 <tr> 1300 <td><code>Statement</code></td> 1301 <td width="100%"><!-- no returns description in source --></td> 1302 </tr> 1303 </table> 1304 1305</div> 1306 1307 1308<A NAME="getActivity()"></A> 1309 1310<div class="api apilevel-"> 1311 <h3 class="api-name">getActivity</h3> 1312 <div class="api-level"> 1313 <div></div> 1314 1315 1316 1317 </div> 1318<pre class="api-signature no-pretty-print"> 1319T getActivity ()</pre> 1320 1321 1322 1323 1324 <p></p> 1325 <table class="responsive"> 1326 <tr><th colspan=2>Returns</th></tr> 1327 <tr> 1328 <td><code>T</code></td> 1329 <td width="100%">The activity under test. 1330</td> 1331 </tr> 1332 </table> 1333 1334</div> 1335 1336 1337<A NAME="launchActivity(android.content.Intent)"></A> 1338 1339<div class="api apilevel-"> 1340 <h3 class="api-name">launchActivity</h3> 1341 <div class="api-level"> 1342 <div></div> 1343 1344 1345 1346 </div> 1347<pre class="api-signature no-pretty-print"> 1348T launchActivity (Intent startIntent)</pre> 1349 1350 1351 1352 1353 <p>Launches the Activity under test. 1354 <p> 1355 Don't call this method directly, unless you explicitly requested not to lazily launch the 1356 Activity manually using the launchActivity flag in 1357 <code><a href="/reference/android/support/test/rule/ActivityTestRule.html#ActivityTestRule(java.lang.Class<T>, boolean, boolean)">ActivityTestRule(Class, boolean, boolean)</a></code>. 1358 <p> 1359 Usage: 1360 <pre> 1361 @Test 1362 public void customIntentToStartActivity() { 1363 Intent intent = new Intent(Intent.ACTION_PICK); 1364 mActivity = mActivityRule.launchActivity(intent); 1365 } 1366 </pre></p> 1367 <table class="responsive"> 1368 <tr><th colspan=2>Parameters</th></tr> 1369 <tr> 1370 <td><code>startIntent</code></td> 1371 <td width="100%"> 1372 <code>Intent</code>: 1373 The Intent that will be used to start the Activity under test. If 1374 <code>startIntent</code> is null, the Intent returned by 1375 <code><a href="/reference/android/support/test/rule/ActivityTestRule.html#getActivityIntent()">getActivityIntent()</a></code> is used.</td> 1376 </tr> 1377 </table> 1378 <table class="responsive"> 1379 <tr><th colspan=2>Returns</th></tr> 1380 <tr> 1381 <td><code>T</code></td> 1382 <td width="100%">the Activity launched by this rule.</td> 1383 </tr> 1384 </table> 1385 <div> 1386 <p><b>See also:</b></p> 1387 <ul class="nolist"><li><code><a href="/reference/android/support/test/rule/ActivityTestRule.html#getActivityIntent()">getActivityIntent()</a></code></li> 1388 </ul> 1389 </div> 1390 1391</div> 1392 1393 1394 1395 1396 1397<!-- ========= METHOD DETAIL ======== --> 1398 1399<h2 class="api-section">Protected methods</h2> 1400 1401 1402 1403<A NAME="afterActivityFinished()"></A> 1404 1405<div class="api apilevel-"> 1406 <h3 class="api-name">afterActivityFinished</h3> 1407 <div class="api-level"> 1408 <div></div> 1409 1410 1411 1412 </div> 1413<pre class="api-signature no-pretty-print"> 1414void afterActivityFinished ()</pre> 1415 1416 1417 1418 1419 <p>Override this method to execute any code that should run after your <code><a href="/reference/android/app/Activity.html">Activity</a></code> is 1420 finished. 1421 This method is called after each test method, including any method annotated with 1422 <a href="http://junit.sourceforge.net/javadoc/org/junit/After.html"><code>After</code></a>. 1423</p> 1424 1425</div> 1426 1427 1428<A NAME="afterActivityLaunched()"></A> 1429 1430<div class="api apilevel-"> 1431 <h3 class="api-name">afterActivityLaunched</h3> 1432 <div class="api-level"> 1433 <div></div> 1434 1435 1436 1437 </div> 1438<pre class="api-signature no-pretty-print"> 1439void afterActivityLaunched ()</pre> 1440 1441 1442 1443 1444 <p>Override this method to execute any code that should run after your <code><a href="/reference/android/app/Activity.html">Activity</a></code> is 1445 launched, but before any test code is run including any method annotated with 1446 <a href="http://junit.sourceforge.net/javadoc/org/junit/Before.html"><code>Before</code></a>. 1447 <p> 1448 Prefer 1449 <a href="http://junit.sourceforge.net/javadoc/org/junit/Before.html"><code>Before</code></a> 1450 over this method. This method should usually not be overwritten directly in tests and only be 1451 used by subclasses of ActivityTestRule to get notified when the activity is created and 1452 visible but test runs. 1453</p> 1454 1455</div> 1456 1457 1458<A NAME="beforeActivityLaunched()"></A> 1459 1460<div class="api apilevel-"> 1461 <h3 class="api-name">beforeActivityLaunched</h3> 1462 <div class="api-level"> 1463 <div></div> 1464 1465 1466 1467 </div> 1468<pre class="api-signature no-pretty-print"> 1469void beforeActivityLaunched ()</pre> 1470 1471 1472 1473 1474 <p>Override this method to execute any code that should run before your <code><a href="/reference/android/app/Activity.html">Activity</a></code> is 1475 created and launched. 1476 This method is called before each test method, including any method annotated with 1477 <a href="http://junit.sourceforge.net/javadoc/org/junit/Before.html"><code>Before</code></a>. 1478</p> 1479 1480</div> 1481 1482 1483<A NAME="getActivityIntent()"></A> 1484 1485<div class="api apilevel-"> 1486 <h3 class="api-name">getActivityIntent</h3> 1487 <div class="api-level"> 1488 <div></div> 1489 1490 1491 1492 </div> 1493<pre class="api-signature no-pretty-print"> 1494Intent getActivityIntent ()</pre> 1495 1496 1497 1498 1499 <p>Override this method to set up Intent as if supplied to 1500 <code><a href="/reference/android/content/Context.html#startActivity(android.content.Intent)">startActivity(Intent)</a></code>. 1501 <p> 1502 The default Intent (if this method returns null or is not overwritten) is: 1503 action = <code><a href="/reference/android/content/Intent.html#ACTION_MAIN">ACTION_MAIN</a></code> 1504 flags = <code><a href="/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK">FLAG_ACTIVITY_NEW_TASK</a></code> 1505 All other intent fields are null or empty.</p> 1506 <table class="responsive"> 1507 <tr><th colspan=2>Returns</th></tr> 1508 <tr> 1509 <td><code>Intent</code></td> 1510 <td width="100%">The Intent as if supplied to <code><a href="/reference/android/content/Context.html#startActivity(android.content.Intent)">startActivity(Intent)</a></code>. 1511</td> 1512 </tr> 1513 </table> 1514 1515</div> 1516 1517 1518 1519 1520 1521<!-- ========= END OF CLASS DATA ========= --> 1522 1523</div><!-- end jd-content --> 1524 1525 1526 1527<div class="data-reference-resources-wrapper"> 1528 1529 <ul data-reference-resources> 1530 1531 1532 1533 <li><h2>Classes</h2> 1534 <ul> 1535 <li class="selected api apilevel-"><a href="/reference/android/support/test/rule/ActivityTestRule.html">ActivityTestRule</a></li> 1536 <li class="api apilevel-"><a href="/reference/android/support/test/rule/DisableOnAndroidDebug.html">DisableOnAndroidDebug</a></li> 1537 <li class="api apilevel-"><a href="/reference/android/support/test/rule/ServiceTestRule.html">ServiceTestRule</a></li> 1538 <li class="api apilevel-"><a href="/reference/android/support/test/rule/UiThreadTestRule.html">UiThreadTestRule</a></li> 1539 </ul> 1540 </li> 1541 1542 1543 1544 </ul> 1545 1546</div> 1547 1548 1549 1550</body> 1551</html> 1552