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>InstrumentationRegistry</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<div class="sum-details-links"> 177 178Summary: 179 180 181 182 183 184 185 186 187 188 189 190 <a href="#pubmethods">Methods</a> 191 192 193 194 195 | <a href="#inhmethods">Inherited Methods</a> 196 197| <a href="#" onclick="return toggleAllClassInherited()" id="toggleAllClassInherited">[Expand All]</a> 198 199</div><!-- end sum-details-links --> 200</div><!-- end api-info-block --> 201 202<div class="api apilevel-" id="jd-content"> 203 204<!-- ======== START OF CLASS DATA ======== --> 205 206<h1 class="api-title">InstrumentationRegistry</h1> 207<p> 208<code class="api-signature"> 209 public 210 211 final 212 213 class 214 InstrumentationRegistry 215</code> 216<br> 217 218 219<code class="api-signature"> 220 221 extends Object 222 223 224 225</code> 226 227<code class="api-signature"> 228 229 230 231</code> 232 233</p><table class="jd-inheritance-table"> 234 235 236 <tr> 237 238 <td colspan="2" class="jd-inheritance-class-cell">java.lang.Object 239 </td> 240 </tr> 241 242 243 <tr> 244 245 <td class="jd-inheritance-space"> ↳</td> 246 247 <td colspan="1" class="jd-inheritance-class-cell">android.support.test.InstrumentationRegistry 248 </td> 249 </tr> 250 251 252</table> 253 254 255 256 257<br><hr> 258 259 260 <p>An exposed registry instance that holds a reference to the instrumentation running in the 261 process and it's arguments. Also provides an easy way for callers to get a hold of 262 instrumentation, application context and instrumentation arguments Bundle. 263</p> 264 265 266 267 268 269 270 271<h2 class="api-section">Summary</h2> 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299<!-- ========== METHOD SUMMARY =========== --> 300<table id="pubmethods" class="responsive methods"> 301<tr><th colspan="2"><h3>Public methods</h3></th></tr> 302 303 304 305 306 <tr class="api apilevel-" > 307 308 309 <td><code> 310 311 312 static 313 314 315 Bundle</code> 316 </td> 317 318 <td width="100%"> 319 <code> 320 <a href="/reference/android/support/test/InstrumentationRegistry.html#getArguments()">getArguments</a>() 321 </code> 322 323 <p>Returns a copy of instrumentation arguments Bundle. 324 325 326</p> 327 328 </td> 329 </tr> 330 331 332 333 <tr class="api apilevel-" > 334 335 336 <td><code> 337 338 339 static 340 341 342 Context</code> 343 </td> 344 345 <td width="100%"> 346 <code> 347 <a href="/reference/android/support/test/InstrumentationRegistry.html#getContext()">getContext</a>() 348 </code> 349 350 <p>Return the Context of this instrumentation's package. 351 352 353</p> 354 355 </td> 356 </tr> 357 358 359 360 <tr class="api apilevel-" > 361 362 363 <td><code> 364 365 366 static 367 368 369 Instrumentation</code> 370 </td> 371 372 <td width="100%"> 373 <code> 374 <a href="/reference/android/support/test/InstrumentationRegistry.html#getInstrumentation()">getInstrumentation</a>() 375 </code> 376 377 <p>Returns the instrumentation currently running. 378 379 380</p> 381 382 </td> 383 </tr> 384 385 386 387 <tr class="api apilevel-" > 388 389 390 <td><code> 391 392 393 static 394 395 396 Context</code> 397 </td> 398 399 <td width="100%"> 400 <code> 401 <a href="/reference/android/support/test/InstrumentationRegistry.html#getTargetContext()">getTargetContext</a>() 402 </code> 403 404 <p>Return a Context for the target application being instrumented. 405 406 407</p> 408 409 </td> 410 </tr> 411 412 413 414 <tr class="api apilevel-" > 415 416 417 <td><code> 418 419 420 static 421 422 423 void</code> 424 </td> 425 426 <td width="100%"> 427 <code> 428 <a href="/reference/android/support/test/InstrumentationRegistry.html#registerInstance(android.app.Instrumentation, android.os.Bundle)">registerInstance</a>(Instrumentation instrumentation, Bundle arguments) 429 </code> 430 431 <p>Records/exposes the instrumentation currently running and stores a copy of the 432 instrumentation arguments Bundle in the registry. 433 434 435</p> 436 437 </td> 438 </tr> 439 440 441 442</table> 443 444 445 446 447 448 449 450<!-- ========== METHOD SUMMARY =========== --> 451<table id="inhmethods" class="methods inhtable"> 452<tr><th><h3>Inherited methods</h3></th></tr> 453 454 455<tr class="api apilevel-" > 456<td colspan="2"> 457 458 <a href="#" onclick="return toggleInherited(this, null)" id="inherited-methods-java.lang.Object" class="jd-expando-trigger closed" 459 ><img height="34" id="inherited-methods-java.lang.Object-trigger" 460 src="/assets/images/styles/disclosure_down.png" 461 class="jd-expando-trigger-img" /></a>From 462class 463<code> 464 465 java.lang.Object 466 467</code> 468<div id="inherited-methods-java.lang.Object"> 469 <div id="inherited-methods-java.lang.Object-list" 470 class="jd-inheritedlinks"> 471 </div> 472 <div id="inherited-methods-java.lang.Object-summary" style="display: none;"> 473 <table class="jd-sumtable-expando responsive"> 474 475 476 477 478 <tr class="api apilevel-" > 479 480 481 <td><code> 482 483 484 485 486 487 Object</code> 488 </td> 489 490 <td width="100%"> 491 <code> 492 clone() 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 boolean</code> 510 </td> 511 512 <td width="100%"> 513 <code> 514 equals(Object arg0) 515 </code> 516 517 </td> 518 </tr> 519 520 521 522 <tr class="api apilevel-" > 523 524 525 <td><code> 526 527 528 529 530 531 void</code> 532 </td> 533 534 <td width="100%"> 535 <code> 536 finalize() 537 </code> 538 539 </td> 540 </tr> 541 542 543 544 <tr class="api apilevel-" > 545 546 547 <td><code> 548 549 550 551 final 552 553 Class<?></code> 554 </td> 555 556 <td width="100%"> 557 <code> 558 getClass() 559 </code> 560 561 </td> 562 </tr> 563 564 565 566 <tr class="api apilevel-" > 567 568 569 <td><code> 570 571 572 573 574 575 int</code> 576 </td> 577 578 <td width="100%"> 579 <code> 580 hashCode() 581 </code> 582 583 </td> 584 </tr> 585 586 587 588 <tr class="api apilevel-" > 589 590 591 <td><code> 592 593 594 595 final 596 597 void</code> 598 </td> 599 600 <td width="100%"> 601 <code> 602 notify() 603 </code> 604 605 </td> 606 </tr> 607 608 609 610 <tr class="api apilevel-" > 611 612 613 <td><code> 614 615 616 617 final 618 619 void</code> 620 </td> 621 622 <td width="100%"> 623 <code> 624 notifyAll() 625 </code> 626 627 </td> 628 </tr> 629 630 631 632 <tr class="api apilevel-" > 633 634 635 <td><code> 636 637 638 639 640 641 String</code> 642 </td> 643 644 <td width="100%"> 645 <code> 646 toString() 647 </code> 648 649 </td> 650 </tr> 651 652 653 654 <tr class="api apilevel-" > 655 656 657 <td><code> 658 659 660 661 final 662 663 void</code> 664 </td> 665 666 <td width="100%"> 667 <code> 668 wait(long arg0, int arg1) 669 </code> 670 671 </td> 672 </tr> 673 674 675 676 <tr class="api apilevel-" > 677 678 679 <td><code> 680 681 682 683 final 684 685 void</code> 686 </td> 687 688 <td width="100%"> 689 <code> 690 wait(long arg0) 691 </code> 692 693 </td> 694 </tr> 695 696 697 698 <tr class="api apilevel-" > 699 700 701 <td><code> 702 703 704 705 final 706 707 void</code> 708 </td> 709 710 <td width="100%"> 711 <code> 712 wait() 713 </code> 714 715 </td> 716 </tr> 717 718 719 720 </table> 721 </div> 722</div> 723</td></tr> 724 725 726</table> 727 728 729 730<!-- XML Attributes --> 731 732 733<!-- Enum Values --> 734 735 736<!-- Constants --> 737 738 739<!-- Fields --> 740 741 742<!-- Public ctors --> 743 744 745 746<!-- ========= CONSTRUCTOR DETAIL ======== --> 747<!-- Protected ctors --> 748 749 750 751<!-- ========= METHOD DETAIL ======== --> 752<!-- Public methdos --> 753 754<h2 class="api-section">Public methods</h2> 755 756 757 758<A NAME="getArguments()"></A> 759 760<div class="api apilevel-"> 761 <h3 class="api-name">getArguments</h3> 762 <div class="api-level"> 763 <div></div> 764 765 766 767 </div> 768<pre class="api-signature no-pretty-print"> 769Bundle getArguments ()</pre> 770 771 772 773 774 <p>Returns a copy of instrumentation arguments Bundle. Use this to get a <code><a href="/reference/android/os/Bundle.html">Bundle</a></code> 775 containing the command line arguments passed to <code><a href="/reference/android/app/Instrumentation.html">Instrumentation</a></code> into your test. 776 <p> 777 This Bundle is not guaranteed to be present under all instrumentations. 778 </p></p> 779 <table class="responsive"> 780 <tr><th colspan=2>Returns</th></tr> 781 <tr> 782 <td><code>Bundle</code></td> 783 <td width="100%">Bundle the arguments for this instrumentation.</td> 784 </tr> 785 </table> 786 <table class="responsive"> 787 <tr><th colspan=2>Throws</th></tr> 788 <tr> 789 <td><code>IllegalStateException</code></td> 790 <td width="100%">if no argument Bundle has been registered. 791</td> 792 </tr> 793 </table> 794 795 796</div> 797 798 799<A NAME="getContext()"></A> 800 801<div class="api apilevel-"> 802 <h3 class="api-name">getContext</h3> 803 <div class="api-level"> 804 <div></div> 805 806 807 808 </div> 809<pre class="api-signature no-pretty-print"> 810Context getContext ()</pre> 811 812 813 814 815 <p>Return the Context of this instrumentation's package. Use this to get a 816 <code><a href="/reference/android/content/Context.html">Context</a></code> representing <code><a href="/reference/android/app/Instrumentation.html#getContext()">getContext()</a></code> into your test. 817</p> 818 <table class="responsive"> 819 <tr><th colspan=2>Returns</th></tr> 820 <tr> 821 <td><code>Context</code></td> 822 <td width="100%"><!-- no returns description in source --></td> 823 </tr> 824 </table> 825 826</div> 827 828 829<A NAME="getInstrumentation()"></A> 830 831<div class="api apilevel-"> 832 <h3 class="api-name">getInstrumentation</h3> 833 <div class="api-level"> 834 <div></div> 835 836 837 838 </div> 839<pre class="api-signature no-pretty-print"> 840Instrumentation getInstrumentation ()</pre> 841 842 843 844 845 <p>Returns the instrumentation currently running. Use this to get an <code><a href="/reference/android/app/Instrumentation.html">Instrumentation</a></code> 846 into your test.</p> 847 <table class="responsive"> 848 <tr><th colspan=2>Returns</th></tr> 849 <tr> 850 <td><code>Instrumentation</code></td> 851 <td width="100%"><!-- no returns description in source --></td> 852 </tr> 853 </table> 854 <table class="responsive"> 855 <tr><th colspan=2>Throws</th></tr> 856 <tr> 857 <td><code>IllegalStateException</code></td> 858 <td width="100%">if instrumentation hasn't been registered 859</td> 860 </tr> 861 </table> 862 863 864</div> 865 866 867<A NAME="getTargetContext()"></A> 868 869<div class="api apilevel-"> 870 <h3 class="api-name">getTargetContext</h3> 871 <div class="api-level"> 872 <div></div> 873 874 875 876 </div> 877<pre class="api-signature no-pretty-print"> 878Context getTargetContext ()</pre> 879 880 881 882 883 <p>Return a Context for the target application being instrumented. Use this to get a 884 <code><a href="/reference/android/content/Context.html">Context</a></code> representing <code><a href="/reference/android/app/Instrumentation.html#getTargetContext()">getTargetContext()</a></code> into your test. 885</p> 886 <table class="responsive"> 887 <tr><th colspan=2>Returns</th></tr> 888 <tr> 889 <td><code>Context</code></td> 890 <td width="100%"><!-- no returns description in source --></td> 891 </tr> 892 </table> 893 894</div> 895 896 897<A NAME="registerInstance(android.app.Instrumentation, android.os.Bundle)"></A> 898 899<div class="api apilevel-"> 900 <h3 class="api-name">registerInstance</h3> 901 <div class="api-level"> 902 <div></div> 903 904 905 906 </div> 907<pre class="api-signature no-pretty-print"> 908void registerInstance (Instrumentation instrumentation, 909 Bundle arguments)</pre> 910 911 912 913 914 <p>Records/exposes the instrumentation currently running and stores a copy of the 915 instrumentation arguments Bundle in the registry. 916 <p> 917 This is a global registry - so be aware of the impact of calling this method! 918 </p></p> 919 <table class="responsive"> 920 <tr><th colspan=2>Parameters</th></tr> 921 <tr> 922 <td><code>instrumentation</code></td> 923 <td width="100%"> 924 <code>Instrumentation</code>: 925 the instrumentation currently running.</td> 926 </tr> 927 <tr> 928 <td><code>arguments</code></td> 929 <td width="100%"> 930 <code>Bundle</code>: 931 the arguments for this application. Null deregisters any existing arguments. 932</td> 933 </tr> 934 </table> 935 936</div> 937 938 939 940 941 942<!-- ========= METHOD DETAIL ======== --> 943 944 945 946<!-- ========= END OF CLASS DATA ========= --> 947 948</div><!-- end jd-content --> 949 950 951 952<div class="data-reference-resources-wrapper"> 953 954 <ul data-reference-resources> 955 956 957 958 <li><h2>Classes</h2> 959 <ul> 960 <li class="selected api apilevel-"><a href="/reference/android/support/test/InstrumentationRegistry.html">InstrumentationRegistry</a></li> 961 </ul> 962 </li> 963 964 965 966 </ul> 967 968</div> 969 970 971 972</body> 973</html> 974