Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
HandlerCompat.java
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package io.flutter.util;
6
7import static io.flutter.Build.API_LEVELS;
8
9import android.os.Build;
10import android.os.Handler;
11import android.os.Looper;
12
13/** Compatability wrapper over {@link Handler}. */
14public final class HandlerCompat {
15 /**
16 * Create a new Handler whose posted messages and runnables are not subject to synchronization
17 * barriers such as display vsync.
18 *
19 * <p>Messages sent to an async handler are guaranteed to be ordered with respect to one another,
20 * but not necessarily with respect to messages from other Handlers. Compatibility behavior:
21 *
22 * <ul>
23 * <li>SDK 28 and above, this method matches platform behavior.
24 * <li>Otherwise, returns a synchronous handler instance.
25 * </ul>
26 *
27 * @param looper the Looper that the new Handler should be bound to
28 * @return a new async Handler instance
29 * @see Handler#createAsync(Looper)
30 */
31 public static Handler createAsyncHandler(Looper looper) {
32 if (Build.VERSION.SDK_INT >= API_LEVELS.API_28) {
33 return Handler.createAsync(looper);
34 }
35 return new Handler(looper);
36 }
37}
static Handler createAsyncHandler(Looper looper)