blob: 556fdb4e7742daf40a7ea31212a088789249d035 [file] [log] [blame]
Tor Norbyef8b83362015-03-10 19:15:27 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
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 */
16package android.annotation;
17
Tor Norbyef8b83362015-03-10 19:15:27 -070018import static java.lang.annotation.ElementType.CONSTRUCTOR;
19import static java.lang.annotation.ElementType.METHOD;
Matthew Gharritycb436162017-07-17 17:18:00 -070020import static java.lang.annotation.ElementType.PARAMETER;
Tor Norbyef8b83362015-03-10 19:15:27 -070021import static java.lang.annotation.ElementType.TYPE;
22import static java.lang.annotation.RetentionPolicy.SOURCE;
23
Jeff Sharkey6503bd82017-04-19 23:24:18 -060024import android.os.Looper;
25
Jeff Sharkey910e0812017-04-21 16:29:27 -060026import java.lang.annotation.Retention;
27import java.lang.annotation.Target;
28
Tor Norbyef8b83362015-03-10 19:15:27 -070029/**
30 * Denotes that the annotated method should only be called on the main thread.
Jeff Sharkey6503bd82017-04-19 23:24:18 -060031 * If the annotated element is a class, then all methods in the class should be
32 * called on the main thread.
Tor Norbyef8b83362015-03-10 19:15:27 -070033 * <p>
34 * Example:
Jeff Sharkey6503bd82017-04-19 23:24:18 -060035 *
36 * <pre>
37 * <code>
Tor Norbyef8b83362015-03-10 19:15:27 -070038 * &#64;MainThread
39 * public void deliverResult(D data) { ... }
Jeff Sharkey6503bd82017-04-19 23:24:18 -060040 * </code>
41 * </pre>
Tor Norbyef8b83362015-03-10 19:15:27 -070042 *
Jeff Sharkey6503bd82017-04-19 23:24:18 -060043 * @memberDoc This method must be called from the
44 * {@linkplain Looper#getMainLooper() main thread} of your app.
45 * @hide
Tor Norbyef8b83362015-03-10 19:15:27 -070046 */
47@Retention(SOURCE)
Matthew Gharritycb436162017-07-17 17:18:00 -070048@Target({METHOD,CONSTRUCTOR,TYPE,PARAMETER})
Tor Norbyef8b83362015-03-10 19:15:27 -070049public @interface MainThread {
Jeff Sharkey6503bd82017-04-19 23:24:18 -060050}