ActivityUtils.java revision 5838b1a067427865c3ec8cc33a5dfa64ba05407f
1/* 2 * Copyright (C) 2013 DroidDriver committers 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.google.android.droiddriver.util; 18 19import android.app.Activity; 20 21/** 22 * Static helper methods for retrieving activities. 23 */ 24public class ActivityUtils { 25 private static Activity runningActivity; 26 27 /** 28 * Sets the running (a.k.a. resumed or foreground) activity. Called from 29 * {@link com.google.android.droiddriver.runner.TestRunner}. If a custom 30 * runner is used, it must call this method at appropriate time, otherwise 31 * {@link com.google.android.droiddriver.instrumentation.InstrumentationDriver} 32 * won't work. 33 */ 34 public static synchronized void setRunningActivity(Activity activity) { 35 runningActivity = activity; 36 } 37 38 /** 39 * Gets the running (a.k.a. resumed or foreground) activity. 40 * 41 * @return the currently running activity, or null if no activity has focus. 42 */ 43 public static synchronized Activity getRunningActivity() { 44 return runningActivity; 45 } 46} 47