The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 19 | import static android.Manifest.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS; |
Felipe Leme | 0c6b23d | 2019-01-15 17:02:49 -0800 | [diff] [blame] | 20 | import static android.os.Process.myUid; |
Felipe Leme | 5b32ebe | 2018-02-15 12:52:19 -0800 | [diff] [blame] | 21 | |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 22 | import static java.lang.Character.MIN_VALUE; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 23 | |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 24 | import android.annotation.CallSuper; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 25 | import android.annotation.DrawableRes; |
| 26 | import android.annotation.IdRes; |
| 27 | import android.annotation.IntDef; |
| 28 | import android.annotation.LayoutRes; |
Tor Norbye | 83c6896 | 2015-03-10 20:55:31 -0700 | [diff] [blame] | 29 | import android.annotation.MainThread; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 30 | import android.annotation.NonNull; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 31 | import android.annotation.Nullable; |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 32 | import android.annotation.RequiresPermission; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 33 | import android.annotation.StyleRes; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 34 | import android.annotation.SystemApi; |
Tiger Huang | fc21845 | 2018-09-27 00:38:50 +0800 | [diff] [blame] | 35 | import android.annotation.TestApi; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 36 | import android.annotation.UnsupportedAppUsage; |
Amith Yamasani | eeed06c | 2016-05-03 15:07:03 -0700 | [diff] [blame] | 37 | import android.app.VoiceInteractor.Request; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 38 | import android.app.admin.DevicePolicyManager; |
Dianne Hackborn | 69c6adc | 2015-06-02 10:52:59 -0700 | [diff] [blame] | 39 | import android.app.assist.AssistContent; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 40 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.content.ComponentName; |
| 42 | import android.content.ContentResolver; |
| 43 | import android.content.Context; |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 44 | import android.content.CursorLoader; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 45 | import android.content.IIntentSender; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 46 | import android.content.Intent; |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 47 | import android.content.IntentSender; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.content.SharedPreferences; |
| 49 | import android.content.pm.ActivityInfo; |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 50 | import android.content.pm.ApplicationInfo; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 51 | import android.content.pm.PackageManager; |
| 52 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.content.res.Configuration; |
| 54 | import android.content.res.Resources; |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 55 | import android.content.res.TypedArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.database.Cursor; |
| 57 | import android.graphics.Bitmap; |
| 58 | import android.graphics.Canvas; |
Winson | 2d47683 | 2016-02-17 14:53:46 -0800 | [diff] [blame] | 59 | import android.graphics.Color; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 60 | import android.graphics.Rect; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.graphics.drawable.Drawable; |
| 62 | import android.media.AudioManager; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 63 | import android.media.session.MediaController; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.net.Uri; |
Adam Powell | d3c63a6 | 2016-06-09 12:36:16 -0700 | [diff] [blame] | 65 | import android.os.BadParcelableException; |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 66 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.os.Bundle; |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 68 | import android.os.CancellationSignal; |
Tim Van Patten | ddc4391 | 2018-12-18 17:47:52 -0700 | [diff] [blame] | 69 | import android.os.GraphicsEnvironment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.os.Handler; |
| 71 | import android.os.IBinder; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 72 | import android.os.Looper; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 73 | import android.os.Parcelable; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 74 | import android.os.PersistableBundle; |
Nicholas Sauer | 28348ed74 | 2019-02-15 11:58:32 -0800 | [diff] [blame] | 75 | import android.os.Process; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 76 | import android.os.RemoteException; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 77 | import android.os.ServiceManager.ServiceNotFoundException; |
Brad Fitzpatrick | 7580357 | 2011-01-13 14:21:03 -0800 | [diff] [blame] | 78 | import android.os.StrictMode; |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 79 | import android.os.Trace; |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 80 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | import android.text.Selection; |
| 82 | import android.text.SpannableStringBuilder; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 83 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import android.text.method.TextKeyListener; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 85 | import android.transition.Scene; |
| 86 | import android.transition.TransitionManager; |
| 87 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | import android.util.AttributeSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | import android.util.EventLog; |
| 90 | import android.util.Log; |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 91 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 92 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | import android.util.SparseArray; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 94 | import android.util.SuperNotCalledException; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 95 | import android.view.ActionMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.view.ContextMenu; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 97 | import android.view.ContextMenu.ContextMenuInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import android.view.ContextThemeWrapper; |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 99 | import android.view.DragAndDropPermissions; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 100 | import android.view.DragEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | import android.view.KeyEvent; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 102 | import android.view.KeyboardShortcutGroup; |
| 103 | import android.view.KeyboardShortcutInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | import android.view.LayoutInflater; |
| 105 | import android.view.Menu; |
| 106 | import android.view.MenuInflater; |
| 107 | import android.view.MenuItem; |
| 108 | import android.view.MotionEvent; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 109 | import android.view.RemoteAnimationDefinition; |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 110 | import android.view.SearchEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | import android.view.View; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 112 | import android.view.View.OnCreateContextMenuListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.ViewGroup; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 114 | import android.view.ViewGroup.LayoutParams; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | import android.view.ViewManager; |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 116 | import android.view.ViewRootImpl; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 117 | import android.view.ViewRootImpl.ActivityConfigCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | import android.view.Window; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 119 | import android.view.Window.WindowControllerCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 121 | import android.view.WindowManagerGlobal; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 122 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 123 | import android.view.autofill.AutofillId; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 124 | import android.view.autofill.AutofillManager; |
Felipe Leme | bb567ae | 2017-10-04 09:56:21 -0700 | [diff] [blame] | 125 | import android.view.autofill.AutofillManager.AutofillClient; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 126 | import android.view.autofill.AutofillPopupWindow; |
| 127 | import android.view.autofill.IAutofillWindowPresenter; |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 128 | import android.view.contentcapture.ContentCaptureManager; |
Felipe Leme | cbf7f26 | 2019-04-17 13:57:59 -0700 | [diff] [blame] | 129 | import android.view.contentcapture.ContentCaptureManager.ContentCaptureClient; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | import android.widget.AdapterView; |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 131 | import android.widget.Toast; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 132 | import android.widget.Toolbar; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 133 | |
Adrian Roos | 4c86459 | 2019-04-10 14:47:57 +0200 | [diff] [blame] | 134 | import com.android.internal.R; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 135 | import com.android.internal.annotations.GuardedBy; |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 136 | import com.android.internal.annotations.VisibleForTesting; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 137 | import com.android.internal.app.IVoiceInteractor; |
| 138 | import com.android.internal.app.ToolbarActionBar; |
| 139 | import com.android.internal.app.WindowDecorActionBar; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 140 | import com.android.internal.policy.PhoneWindow; |
| 141 | |
Mathieu Chartier | 63e14c1 | 2019-03-07 09:05:44 -0800 | [diff] [blame] | 142 | import dalvik.system.VMRuntime; |
| 143 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 144 | import java.io.FileDescriptor; |
| 145 | import java.io.PrintWriter; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 146 | import java.lang.annotation.Retention; |
| 147 | import java.lang.annotation.RetentionPolicy; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 148 | import java.util.ArrayList; |
Felipe Leme | 5b32ebe | 2018-02-15 12:52:19 -0800 | [diff] [blame] | 149 | import java.util.Arrays; |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 150 | import java.util.Collections; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 151 | import java.util.HashMap; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 152 | import java.util.List; |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 153 | import java.util.concurrent.Executor; |
| 154 | import java.util.function.Consumer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | |
Bryce Lee | e83f34cd | 2017-10-31 19:50:54 -0700 | [diff] [blame] | 156 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | /** |
| 158 | * An activity is a single, focused thing that the user can do. Almost all |
| 159 | * activities interact with the user, so the Activity class takes care of |
| 160 | * creating a window for you in which you can place your UI with |
| 161 | * {@link #setContentView}. While activities are often presented to the user |
| 162 | * as full-screen windows, they can also be used in other ways: as floating |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 163 | * windows (via a theme with {@link android.R.attr#windowIsFloating} set), |
| 164 | * <a href="https://developer.android.com/guide/topics/ui/multi-window"> |
| 165 | * Multi-Window mode</a> or embedded into other windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | * |
| 167 | * There are two methods almost all subclasses of Activity will implement: |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 168 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | * <ul> |
| 170 | * <li> {@link #onCreate} is where you initialize your activity. Most |
| 171 | * importantly, here you will usually call {@link #setContentView(int)} |
| 172 | * with a layout resource defining your UI, and using {@link #findViewById} |
| 173 | * to retrieve the widgets in that UI that you need to interact with |
| 174 | * programmatically. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 175 | * |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 176 | * <li> {@link #onPause} is where you deal with the user pausing active |
| 177 | * interaction with the activity. Any changes made by the user should at |
| 178 | * this point be committed (usually to the |
| 179 | * {@link android.content.ContentProvider} holding the data). In this |
| 180 | * state the activity is still visible on screen. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | * </ul> |
| 182 | * |
| 183 | * <p>To be of use with {@link android.content.Context#startActivity Context.startActivity()}, all |
| 184 | * activity classes must have a corresponding |
| 185 | * {@link android.R.styleable#AndroidManifestActivity <activity>} |
| 186 | * declaration in their package's <code>AndroidManifest.xml</code>.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 187 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | * <p>Topics covered here: |
| 189 | * <ol> |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 190 | * <li><a href="#Fragments">Fragments</a> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | * <li><a href="#ActivityLifecycle">Activity Lifecycle</a> |
| 192 | * <li><a href="#ConfigurationChanges">Configuration Changes</a> |
| 193 | * <li><a href="#StartingActivities">Starting Activities and Getting Results</a> |
| 194 | * <li><a href="#SavingPersistentState">Saving Persistent State</a> |
| 195 | * <li><a href="#Permissions">Permissions</a> |
| 196 | * <li><a href="#ProcessLifecycle">Process Lifecycle</a> |
| 197 | * </ol> |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 198 | * |
| 199 | * <div class="special reference"> |
| 200 | * <h3>Developer Guides</h3> |
| 201 | * <p>The Activity class is an important part of an application's overall lifecycle, |
| 202 | * and the way activities are launched and put together is a fundamental |
| 203 | * part of the platform's application model. For a detailed perspective on the structure of an |
| 204 | * Android application and how activities behave, please read the |
| 205 | * <a href="{@docRoot}guide/topics/fundamentals.html">Application Fundamentals</a> and |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 206 | * <a href="{@docRoot}guide/components/tasks-and-back-stack.html">Tasks and Back Stack</a> |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 207 | * developer guides.</p> |
| 208 | * |
| 209 | * <p>You can also find a detailed discussion about how to create activities in the |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 210 | * <a href="{@docRoot}guide/components/activities.html">Activities</a> |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 211 | * developer guide.</p> |
| 212 | * </div> |
| 213 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 214 | * <a name="Fragments"></a> |
| 215 | * <h3>Fragments</h3> |
| 216 | * |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 217 | * <p>The {@link android.support.v4.app.FragmentActivity} subclass |
| 218 | * can make use of the {@link android.support.v4.app.Fragment} class to better |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 219 | * modularize their code, build more sophisticated user interfaces for larger |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 220 | * screens, and help scale their application between small and large screens.</p> |
| 221 | * |
| 222 | * <p>For more information about using fragments, read the |
| 223 | * <a href="{@docRoot}guide/components/fragments.html">Fragments</a> developer guide.</p> |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 224 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | * <a name="ActivityLifecycle"></a> |
| 226 | * <h3>Activity Lifecycle</h3> |
| 227 | * |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 228 | * <p>Activities in the system are managed as |
| 229 | * <a href="https://developer.android.com/guide/components/activities/tasks-and-back-stack"> |
| 230 | * activity stacks</a>. When a new activity is started, it is usually placed on the top of the |
| 231 | * current stack and becomes the running activity -- the previous activity always remains |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | * below it in the stack, and will not come to the foreground again until |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 233 | * the new activity exits. There can be one or multiple activity stacks visible |
| 234 | * on screen.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 235 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | * <p>An activity has essentially four states:</p> |
| 237 | * <ul> |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 238 | * <li>If an activity is in the foreground of the screen (at the highest position of the topmost |
| 239 | * stack), it is <em>active</em> or <em>running</em>. This is usually the activity that the |
| 240 | * user is currently interacting with.</li> |
| 241 | * <li>If an activity has lost focus but is still presented to the user, it is <em>visible</em>. |
| 242 | * It is possible if a new non-full-sized or transparent activity has focus on top of your |
| 243 | * activity, another activity has higher position in multi-window mode, or the activity |
| 244 | * itself is not focusable in current windowing mode. Such activity is completely alive (it |
| 245 | * maintains all state and member information and remains attached to the window manager). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | * <li>If an activity is completely obscured by another activity, |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 247 | * it is <em>stopped</em> or <em>hidden</em>. It still retains all state and member |
| 248 | * information, however, it is no longer visible to the user so its window is hidden |
| 249 | * and it will often be killed by the system when memory is needed elsewhere.</li> |
| 250 | * <li>The system can drop the activity from memory by either asking it to finish, |
| 251 | * or simply killing its process, making it <em>destroyed</em>. When it is displayed again |
| 252 | * to the user, it must be completely restarted and restored to its previous state.</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | * </ul> |
| 254 | * |
| 255 | * <p>The following diagram shows the important state paths of an Activity. |
| 256 | * The square rectangles represent callback methods you can implement to |
| 257 | * perform operations when the Activity moves between states. The colored |
| 258 | * ovals are major states the Activity can be in.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 259 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | * <p><img src="../../../images/activity_lifecycle.png" |
| 261 | * alt="State diagram for an Android Activity Lifecycle." border="0" /></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 262 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | * <p>There are three key loops you may be interested in monitoring within your |
| 264 | * activity: |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 265 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | * <ul> |
| 267 | * <li>The <b>entire lifetime</b> of an activity happens between the first call |
| 268 | * to {@link android.app.Activity#onCreate} through to a single final call |
| 269 | * to {@link android.app.Activity#onDestroy}. An activity will do all setup |
| 270 | * of "global" state in onCreate(), and release all remaining resources in |
| 271 | * onDestroy(). For example, if it has a thread running in the background |
| 272 | * to download data from the network, it may create that thread in onCreate() |
| 273 | * and then stop the thread in onDestroy(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 274 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | * <li>The <b>visible lifetime</b> of an activity happens between a call to |
| 276 | * {@link android.app.Activity#onStart} until a corresponding call to |
| 277 | * {@link android.app.Activity#onStop}. During this time the user can see the |
| 278 | * activity on-screen, though it may not be in the foreground and interacting |
| 279 | * with the user. Between these two methods you can maintain resources that |
| 280 | * are needed to show the activity to the user. For example, you can register |
| 281 | * a {@link android.content.BroadcastReceiver} in onStart() to monitor for changes |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 282 | * that impact your UI, and unregister it in onStop() when the user no |
| 283 | * longer sees what you are displaying. The onStart() and onStop() methods |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | * can be called multiple times, as the activity becomes visible and hidden |
| 285 | * to the user. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 286 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | * <li>The <b>foreground lifetime</b> of an activity happens between a call to |
| 288 | * {@link android.app.Activity#onResume} until a corresponding call to |
| 289 | * {@link android.app.Activity#onPause}. During this time the activity is |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 290 | * in visible, active and interacting with the user. An activity |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | * can frequently go between the resumed and paused states -- for example when |
| 292 | * the device goes to sleep, when an activity result is delivered, when a new |
| 293 | * intent is delivered -- so the code in these methods should be fairly |
| 294 | * lightweight. |
| 295 | * </ul> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 296 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | * <p>The entire lifecycle of an activity is defined by the following |
| 298 | * Activity methods. All of these are hooks that you can override |
| 299 | * to do appropriate work when the activity changes state. All |
| 300 | * activities will implement {@link android.app.Activity#onCreate} |
| 301 | * to do their initial setup; many will also implement |
| 302 | * {@link android.app.Activity#onPause} to commit changes to data and |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 303 | * prepare to pause interacting with the user, and {@link android.app.Activity#onStop} |
| 304 | * to handle no longer being visible on screen. You should always |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | * call up to your superclass when implementing these methods.</p> |
| 306 | * |
| 307 | * </p> |
| 308 | * <pre class="prettyprint"> |
| 309 | * public class Activity extends ApplicationContext { |
| 310 | * protected void onCreate(Bundle savedInstanceState); |
| 311 | * |
| 312 | * protected void onStart(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 313 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | * protected void onRestart(); |
| 315 | * |
| 316 | * protected void onResume(); |
| 317 | * |
| 318 | * protected void onPause(); |
| 319 | * |
| 320 | * protected void onStop(); |
| 321 | * |
| 322 | * protected void onDestroy(); |
| 323 | * } |
| 324 | * </pre> |
| 325 | * |
| 326 | * <p>In general the movement through an activity's lifecycle looks like |
| 327 | * this:</p> |
| 328 | * |
| 329 | * <table border="2" width="85%" align="center" frame="hsides" rules="rows"> |
| 330 | * <colgroup align="left" span="3" /> |
| 331 | * <colgroup align="left" /> |
| 332 | * <colgroup align="center" /> |
| 333 | * <colgroup align="center" /> |
| 334 | * |
| 335 | * <thead> |
| 336 | * <tr><th colspan="3">Method</th> <th>Description</th> <th>Killable?</th> <th>Next</th></tr> |
| 337 | * </thead> |
| 338 | * |
| 339 | * <tbody> |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 340 | * <tr><td colspan="3" align="left" border="0">{@link android.app.Activity#onCreate onCreate()}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | * <td>Called when the activity is first created. |
| 342 | * This is where you should do all of your normal static set up: |
| 343 | * create views, bind data to lists, etc. This method also |
| 344 | * provides you with a Bundle containing the activity's previously |
| 345 | * frozen state, if there was one. |
| 346 | * <p>Always followed by <code>onStart()</code>.</td> |
| 347 | * <td align="center">No</td> |
| 348 | * <td align="center"><code>onStart()</code></td> |
| 349 | * </tr> |
| 350 | * |
| 351 | * <tr><td rowspan="5" style="border-left: none; border-right: none;"> </td> |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 352 | * <td colspan="2" align="left" border="0">{@link android.app.Activity#onRestart onRestart()}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | * <td>Called after your activity has been stopped, prior to it being |
| 354 | * started again. |
| 355 | * <p>Always followed by <code>onStart()</code></td> |
| 356 | * <td align="center">No</td> |
| 357 | * <td align="center"><code>onStart()</code></td> |
| 358 | * </tr> |
| 359 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 360 | * <tr><td colspan="2" align="left" border="0">{@link android.app.Activity#onStart onStart()}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | * <td>Called when the activity is becoming visible to the user. |
| 362 | * <p>Followed by <code>onResume()</code> if the activity comes |
| 363 | * to the foreground, or <code>onStop()</code> if it becomes hidden.</td> |
| 364 | * <td align="center">No</td> |
| 365 | * <td align="center"><code>onResume()</code> or <code>onStop()</code></td> |
| 366 | * </tr> |
| 367 | * |
| 368 | * <tr><td rowspan="2" style="border-left: none;"> </td> |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 369 | * <td align="left" border="0">{@link android.app.Activity#onResume onResume()}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | * <td>Called when the activity will start |
| 371 | * interacting with the user. At this point your activity is at |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 372 | * the top of its activity stack, with user input going to it. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | * <p>Always followed by <code>onPause()</code>.</td> |
| 374 | * <td align="center">No</td> |
| 375 | * <td align="center"><code>onPause()</code></td> |
| 376 | * </tr> |
| 377 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 378 | * <tr><td align="left" border="0">{@link android.app.Activity#onPause onPause()}</td> |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 379 | * <td>Called when the activity loses foreground state, is no longer focusable or before |
| 380 | * transition to stopped/hidden or destroyed state. The activity is still visible to |
| 381 | * user, so it's recommended to keep it visually active and continue updating the UI. |
| 382 | * Implementations of this method must be very quick because |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | * the next activity will not be resumed until this method returns. |
| 384 | * <p>Followed by either <code>onResume()</code> if the activity |
| 385 | * returns back to the front, or <code>onStop()</code> if it becomes |
| 386 | * invisible to the user.</td> |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 387 | * <td align="center"><font color="#800000"><strong>Pre-{@link android.os.Build.VERSION_CODES#HONEYCOMB}</strong></font></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | * <td align="center"><code>onResume()</code> or<br> |
| 389 | * <code>onStop()</code></td> |
| 390 | * </tr> |
| 391 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 392 | * <tr><td colspan="2" align="left" border="0">{@link android.app.Activity#onStop onStop()}</td> |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 393 | * <td>Called when the activity is no longer visible to the user. This may happen either |
| 394 | * because a new activity is being started on top, an existing one is being brought in |
| 395 | * front of this one, or this one is being destroyed. This is typically used to stop |
| 396 | * animations and refreshing the UI, etc. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | * <p>Followed by either <code>onRestart()</code> if |
| 398 | * this activity is coming back to interact with the user, or |
| 399 | * <code>onDestroy()</code> if this activity is going away.</td> |
| 400 | * <td align="center"><font color="#800000"><strong>Yes</strong></font></td> |
| 401 | * <td align="center"><code>onRestart()</code> or<br> |
| 402 | * <code>onDestroy()</code></td> |
| 403 | * </tr> |
| 404 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 405 | * <tr><td colspan="3" align="left" border="0">{@link android.app.Activity#onDestroy onDestroy()}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | * <td>The final call you receive before your |
| 407 | * activity is destroyed. This can happen either because the |
| 408 | * activity is finishing (someone called {@link Activity#finish} on |
kopriva | fdb0bff | 2018-09-29 15:22:41 -0700 | [diff] [blame] | 409 | * it), or because the system is temporarily destroying this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | * instance of the activity to save space. You can distinguish |
| 411 | * between these two scenarios with the {@link |
| 412 | * Activity#isFinishing} method.</td> |
| 413 | * <td align="center"><font color="#800000"><strong>Yes</strong></font></td> |
| 414 | * <td align="center"><em>nothing</em></td> |
| 415 | * </tr> |
| 416 | * </tbody> |
| 417 | * </table> |
| 418 | * |
| 419 | * <p>Note the "Killable" column in the above table -- for those methods that |
| 420 | * are marked as being killable, after that method returns the process hosting the |
Kris Giesing | 8b6216d | 2014-12-16 17:23:15 -0800 | [diff] [blame] | 421 | * activity may be killed by the system <em>at any time</em> without another line |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | * of its code being executed. Because of this, you should use the |
| 423 | * {@link #onPause} method to write any persistent data (such as user edits) |
| 424 | * to storage. In addition, the method |
| 425 | * {@link #onSaveInstanceState(Bundle)} is called before placing the activity |
| 426 | * in such a background state, allowing you to save away any dynamic instance |
| 427 | * state in your activity into the given Bundle, to be later received in |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 428 | * {@link #onCreate} if the activity needs to be re-created. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | * See the <a href="#ProcessLifecycle">Process Lifecycle</a> |
| 430 | * section for more information on how the lifecycle of a process is tied |
| 431 | * to the activities it is hosting. Note that it is important to save |
| 432 | * persistent data in {@link #onPause} instead of {@link #onSaveInstanceState} |
Daisuke Miyakawa | 5c40f3f | 2011-02-15 13:24:36 -0800 | [diff] [blame] | 433 | * because the latter is not part of the lifecycle callbacks, so will not |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | * be called in every situation as described in its documentation.</p> |
| 435 | * |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 436 | * <p class="note">Be aware that these semantics will change slightly between |
| 437 | * applications targeting platforms starting with {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 438 | * vs. those targeting prior platforms. Starting with Honeycomb, an application |
| 439 | * is not in the killable state until its {@link #onStop} has returned. This |
| 440 | * impacts when {@link #onSaveInstanceState(Bundle)} may be called (it may be |
Joshua Baxter | 9a841a6 | 2018-03-27 14:42:03 -0700 | [diff] [blame] | 441 | * safely called after {@link #onPause()}) and allows an application to safely |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 442 | * wait until {@link #onStop()} to save persistent state.</p> |
| 443 | * |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 444 | * <p class="note">For applications targeting platforms starting with |
| 445 | * {@link android.os.Build.VERSION_CODES#P} {@link #onSaveInstanceState(Bundle)} |
| 446 | * will always be called after {@link #onStop}, so an application may safely |
| 447 | * perform fragment transactions in {@link #onStop} and will be able to save |
| 448 | * persistent state later.</p> |
| 449 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | * <p>For those methods that are not marked as being killable, the activity's |
| 451 | * process will not be killed by the system starting from the time the method |
| 452 | * is called and continuing after it returns. Thus an activity is in the killable |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 453 | * state, for example, between after <code>onStop()</code> to the start of |
| 454 | * <code>onResume()</code>. Keep in mind that under extreme memory pressure the |
| 455 | * system can kill the application process at any time.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | * |
| 457 | * <a name="ConfigurationChanges"></a> |
| 458 | * <h3>Configuration Changes</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 459 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | * <p>If the configuration of the device (as defined by the |
| 461 | * {@link Configuration Resources.Configuration} class) changes, |
| 462 | * then anything displaying a user interface will need to update to match that |
| 463 | * configuration. Because Activity is the primary mechanism for interacting |
| 464 | * with the user, it includes special support for handling configuration |
| 465 | * changes.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 466 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | * <p>Unless you specify otherwise, a configuration change (such as a change |
| 468 | * in screen orientation, language, input devices, etc) will cause your |
| 469 | * current activity to be <em>destroyed</em>, going through the normal activity |
| 470 | * lifecycle process of {@link #onPause}, |
| 471 | * {@link #onStop}, and {@link #onDestroy} as appropriate. If the activity |
| 472 | * had been in the foreground or visible to the user, once {@link #onDestroy} is |
| 473 | * called in that instance then a new instance of the activity will be |
| 474 | * created, with whatever savedInstanceState the previous instance had generated |
| 475 | * from {@link #onSaveInstanceState}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 476 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | * <p>This is done because any application resource, |
| 478 | * including layout files, can change based on any configuration value. Thus |
| 479 | * the only safe way to handle a configuration change is to re-retrieve all |
| 480 | * resources, including layouts, drawables, and strings. Because activities |
| 481 | * must already know how to save their state and re-create themselves from |
| 482 | * that state, this is a convenient way to have an activity restart itself |
| 483 | * with a new configuration.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 484 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | * <p>In some special cases, you may want to bypass restarting of your |
| 486 | * activity based on one or more types of configuration changes. This is |
| 487 | * done with the {@link android.R.attr#configChanges android:configChanges} |
| 488 | * attribute in its manifest. For any types of configuration changes you say |
| 489 | * that you handle there, you will receive a call to your current activity's |
| 490 | * {@link #onConfigurationChanged} method instead of being restarted. If |
| 491 | * a configuration change involves any that you do not handle, however, the |
| 492 | * activity will still be restarted and {@link #onConfigurationChanged} |
| 493 | * will not be called.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 494 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | * <a name="StartingActivities"></a> |
| 496 | * <h3>Starting Activities and Getting Results</h3> |
| 497 | * |
| 498 | * <p>The {@link android.app.Activity#startActivity} |
| 499 | * method is used to start a |
| 500 | * new activity, which will be placed at the top of the activity stack. It |
| 501 | * takes a single argument, an {@link android.content.Intent Intent}, |
| 502 | * which describes the activity |
| 503 | * to be executed.</p> |
| 504 | * |
| 505 | * <p>Sometimes you want to get a result back from an activity when it |
| 506 | * ends. For example, you may start an activity that lets the user pick |
| 507 | * a person in a list of contacts; when it ends, it returns the person |
| 508 | * that was selected. To do this, you call the |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 509 | * {@link android.app.Activity#startActivityForResult(Intent, int)} |
| 510 | * version with a second integer parameter identifying the call. The result |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | * will come back through your {@link android.app.Activity#onActivityResult} |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 512 | * method.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | * |
| 514 | * <p>When an activity exits, it can call |
| 515 | * {@link android.app.Activity#setResult(int)} |
| 516 | * to return data back to its parent. It must always supply a result code, |
| 517 | * which can be the standard results RESULT_CANCELED, RESULT_OK, or any |
| 518 | * custom values starting at RESULT_FIRST_USER. In addition, it can optionally |
| 519 | * return back an Intent containing any additional data it wants. All of this |
| 520 | * information appears back on the |
| 521 | * parent's <code>Activity.onActivityResult()</code>, along with the integer |
| 522 | * identifier it originally supplied.</p> |
| 523 | * |
| 524 | * <p>If a child activity fails for any reason (such as crashing), the parent |
| 525 | * activity will receive a result with the code RESULT_CANCELED.</p> |
| 526 | * |
| 527 | * <pre class="prettyprint"> |
| 528 | * public class MyActivity extends Activity { |
| 529 | * ... |
| 530 | * |
| 531 | * static final int PICK_CONTACT_REQUEST = 0; |
| 532 | * |
Michael Wright | 5438e4e | 2014-07-25 14:05:42 -0700 | [diff] [blame] | 533 | * public boolean onKeyDown(int keyCode, KeyEvent event) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 534 | * if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { |
| 535 | * // When the user center presses, let them pick a contact. |
| 536 | * startActivityForResult( |
| 537 | * new Intent(Intent.ACTION_PICK, |
| 538 | * new Uri("content://contacts")), |
| 539 | * PICK_CONTACT_REQUEST); |
| 540 | * return true; |
| 541 | * } |
| 542 | * return false; |
| 543 | * } |
| 544 | * |
| 545 | * protected void onActivityResult(int requestCode, int resultCode, |
| 546 | * Intent data) { |
| 547 | * if (requestCode == PICK_CONTACT_REQUEST) { |
| 548 | * if (resultCode == RESULT_OK) { |
| 549 | * // A contact was picked. Here we will just display it |
| 550 | * // to the user. |
| 551 | * startActivity(new Intent(Intent.ACTION_VIEW, data)); |
| 552 | * } |
| 553 | * } |
| 554 | * } |
| 555 | * } |
| 556 | * </pre> |
| 557 | * |
| 558 | * <a name="SavingPersistentState"></a> |
| 559 | * <h3>Saving Persistent State</h3> |
| 560 | * |
kopriva | fc3949e | 2018-09-17 11:35:13 -0700 | [diff] [blame] | 561 | * <p>There are generally two kinds of persistent state that an activity |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | * will deal with: shared document-like data (typically stored in a SQLite |
| 563 | * database using a {@linkplain android.content.ContentProvider content provider}) |
| 564 | * and internal state such as user preferences.</p> |
| 565 | * |
kopriva | fc3949e | 2018-09-17 11:35:13 -0700 | [diff] [blame] | 566 | * <p>For content provider data, we suggest that activities use an |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | * "edit in place" user model. That is, any edits a user makes are effectively |
| 568 | * made immediately without requiring an additional confirmation step. |
| 569 | * Supporting this model is generally a simple matter of following two rules:</p> |
| 570 | * |
| 571 | * <ul> |
| 572 | * <li> <p>When creating a new document, the backing database entry or file for |
| 573 | * it is created immediately. For example, if the user chooses to write |
Andrew Solovay | ab8ea9f | 2017-10-06 19:02:28 -0700 | [diff] [blame] | 574 | * a new email, a new entry for that email is created as soon as they |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | * start entering data, so that if they go to any other activity after |
Andrew Solovay | ab8ea9f | 2017-10-06 19:02:28 -0700 | [diff] [blame] | 576 | * that point this email will now appear in the list of drafts.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 577 | * <li> <p>When an activity's <code>onPause()</code> method is called, it should |
| 578 | * commit to the backing content provider or file any changes the user |
| 579 | * has made. This ensures that those changes will be seen by any other |
| 580 | * activity that is about to run. You will probably want to commit |
| 581 | * your data even more aggressively at key times during your |
| 582 | * activity's lifecycle: for example before starting a new |
| 583 | * activity, before finishing your own activity, when the user |
| 584 | * switches between input fields, etc.</p> |
| 585 | * </ul> |
| 586 | * |
| 587 | * <p>This model is designed to prevent data loss when a user is navigating |
| 588 | * between activities, and allows the system to safely kill an activity (because |
| 589 | * system resources are needed somewhere else) at any time after it has been |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 590 | * stopped (or paused on platform versions before {@link android.os.Build.VERSION_CODES#HONEYCOMB}). |
| 591 | * Note this implies that the user pressing BACK from your activity does <em>not</em> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 592 | * mean "cancel" -- it means to leave the activity with its current contents |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 593 | * saved away. Canceling edits in an activity must be provided through |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | * some other mechanism, such as an explicit "revert" or "undo" option.</p> |
| 595 | * |
| 596 | * <p>See the {@linkplain android.content.ContentProvider content package} for |
| 597 | * more information about content providers. These are a key aspect of how |
| 598 | * different activities invoke and propagate data between themselves.</p> |
| 599 | * |
| 600 | * <p>The Activity class also provides an API for managing internal persistent state |
| 601 | * associated with an activity. This can be used, for example, to remember |
| 602 | * the user's preferred initial display in a calendar (day view or week view) |
| 603 | * or the user's default home page in a web browser.</p> |
| 604 | * |
| 605 | * <p>Activity persistent state is managed |
| 606 | * with the method {@link #getPreferences}, |
| 607 | * allowing you to retrieve and |
| 608 | * modify a set of name/value pairs associated with the activity. To use |
| 609 | * preferences that are shared across multiple application components |
| 610 | * (activities, receivers, services, providers), you can use the underlying |
| 611 | * {@link Context#getSharedPreferences Context.getSharedPreferences()} method |
| 612 | * to retrieve a preferences |
| 613 | * object stored under a specific name. |
| 614 | * (Note that it is not possible to share settings data across application |
| 615 | * packages -- for that you will need a content provider.)</p> |
| 616 | * |
| 617 | * <p>Here is an excerpt from a calendar activity that stores the user's |
| 618 | * preferred view mode in its persistent settings:</p> |
| 619 | * |
| 620 | * <pre class="prettyprint"> |
| 621 | * public class CalendarActivity extends Activity { |
| 622 | * ... |
| 623 | * |
| 624 | * static final int DAY_VIEW_MODE = 0; |
| 625 | * static final int WEEK_VIEW_MODE = 1; |
| 626 | * |
| 627 | * private SharedPreferences mPrefs; |
| 628 | * private int mCurViewMode; |
| 629 | * |
| 630 | * protected void onCreate(Bundle savedInstanceState) { |
| 631 | * super.onCreate(savedInstanceState); |
| 632 | * |
| 633 | * SharedPreferences mPrefs = getSharedPreferences(); |
Quddus Chong | 3fa98cb | 2012-04-13 11:17:24 -0700 | [diff] [blame] | 634 | * mCurViewMode = mPrefs.getInt("view_mode", DAY_VIEW_MODE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | * } |
| 636 | * |
| 637 | * protected void onPause() { |
| 638 | * super.onPause(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 639 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | * SharedPreferences.Editor ed = mPrefs.edit(); |
| 641 | * ed.putInt("view_mode", mCurViewMode); |
| 642 | * ed.commit(); |
| 643 | * } |
| 644 | * } |
| 645 | * </pre> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 646 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | * <a name="Permissions"></a> |
| 648 | * <h3>Permissions</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 649 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 650 | * <p>The ability to start a particular Activity can be enforced when it is |
| 651 | * declared in its |
| 652 | * manifest's {@link android.R.styleable#AndroidManifestActivity <activity>} |
| 653 | * tag. By doing so, other applications will need to declare a corresponding |
| 654 | * {@link android.R.styleable#AndroidManifestUsesPermission <uses-permission>} |
| 655 | * element in their own manifest to be able to start that activity. |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 656 | * |
| 657 | * <p>When starting an Activity you can set {@link Intent#FLAG_GRANT_READ_URI_PERMISSION |
| 658 | * Intent.FLAG_GRANT_READ_URI_PERMISSION} and/or {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 659 | * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} on the Intent. This will grant the |
| 660 | * Activity access to the specific URIs in the Intent. Access will remain |
| 661 | * until the Activity has finished (it will remain across the hosting |
| 662 | * process being killed and other temporary destruction). As of |
| 663 | * {@link android.os.Build.VERSION_CODES#GINGERBREAD}, if the Activity |
| 664 | * was already created and a new Intent is being delivered to |
| 665 | * {@link #onNewIntent(Intent)}, any newly granted URI permissions will be added |
| 666 | * to the existing ones it holds. |
| 667 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | * <p>See the <a href="{@docRoot}guide/topics/security/security.html">Security and Permissions</a> |
| 669 | * document for more information on permissions and security in general. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 670 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 671 | * <a name="ProcessLifecycle"></a> |
| 672 | * <h3>Process Lifecycle</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 673 | * |
kopriva | 4dddc63 | 2018-03-19 14:13:08 -0700 | [diff] [blame] | 674 | * <p>The Android system attempts to keep an application process around for as |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | * long as possible, but eventually will need to remove old processes when |
kopriva | 4dddc63 | 2018-03-19 14:13:08 -0700 | [diff] [blame] | 676 | * memory runs low. As described in <a href="#ActivityLifecycle">Activity |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | * Lifecycle</a>, the decision about which process to remove is intimately |
kopriva | 4dddc63 | 2018-03-19 14:13:08 -0700 | [diff] [blame] | 678 | * tied to the state of the user's interaction with it. In general, there |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | * are four states a process can be in based on the activities running in it, |
kopriva | 4dddc63 | 2018-03-19 14:13:08 -0700 | [diff] [blame] | 680 | * listed here in order of importance. The system will kill less important |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 681 | * processes (the last ones) before it resorts to killing more important |
| 682 | * processes (the first ones). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 683 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | * <ol> |
| 685 | * <li> <p>The <b>foreground activity</b> (the activity at the top of the screen |
| 686 | * that the user is currently interacting with) is considered the most important. |
| 687 | * Its process will only be killed as a last resort, if it uses more memory |
| 688 | * than is available on the device. Generally at this point the device has |
| 689 | * reached a memory paging state, so this is required in order to keep the user |
| 690 | * interface responsive. |
| 691 | * <li> <p>A <b>visible activity</b> (an activity that is visible to the user |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 692 | * but not in the foreground, such as one sitting behind a foreground dialog |
| 693 | * or next to other activities in multi-window mode) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | * is considered extremely important and will not be killed unless that is |
| 695 | * required to keep the foreground activity running. |
| 696 | * <li> <p>A <b>background activity</b> (an activity that is not visible to |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 697 | * the user and has been stopped) is no longer critical, so the system may |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 698 | * safely kill its process to reclaim memory for other foreground or |
| 699 | * visible processes. If its process needs to be killed, when the user navigates |
| 700 | * back to the activity (making it visible on the screen again), its |
| 701 | * {@link #onCreate} method will be called with the savedInstanceState it had previously |
| 702 | * supplied in {@link #onSaveInstanceState} so that it can restart itself in the same |
| 703 | * state as the user last left it. |
| 704 | * <li> <p>An <b>empty process</b> is one hosting no activities or other |
| 705 | * application components (such as {@link Service} or |
| 706 | * {@link android.content.BroadcastReceiver} classes). These are killed very |
| 707 | * quickly by the system as memory becomes low. For this reason, any |
| 708 | * background operation you do outside of an activity must be executed in the |
| 709 | * context of an activity BroadcastReceiver or Service to ensure that the system |
| 710 | * knows it needs to keep your process around. |
| 711 | * </ol> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 712 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | * <p>Sometimes an Activity may need to do a long-running operation that exists |
| 714 | * independently of the activity lifecycle itself. An example may be a camera |
| 715 | * application that allows you to upload a picture to a web site. The upload |
| 716 | * may take a long time, and the application should allow the user to leave |
Trevor Johns | 682c24e | 2016-04-12 10:13:47 -0700 | [diff] [blame] | 717 | * the application while it is executing. To accomplish this, your Activity |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 718 | * should start a {@link Service} in which the upload takes place. This allows |
| 719 | * the system to properly prioritize your process (considering it to be more |
| 720 | * important than other non-visible applications) for the duration of the |
| 721 | * upload, independent of whether the original activity is paused, stopped, |
| 722 | * or finished. |
| 723 | */ |
| 724 | public class Activity extends ContextThemeWrapper |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 725 | implements LayoutInflater.Factory2, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | Window.Callback, KeyEvent.Callback, |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 727 | OnCreateContextMenuListener, ComponentCallbacks2, |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 728 | Window.OnWindowDismissedCallback, WindowControllerCallback, |
Felipe Leme | cbf7f26 | 2019-04-17 13:57:59 -0700 | [diff] [blame] | 729 | AutofillManager.AutofillClient, ContentCaptureManager.ContentCaptureClient { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 730 | private static final String TAG = "Activity"; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 731 | private static final boolean DEBUG_LIFECYCLE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 732 | |
| 733 | /** Standard activity result: operation canceled. */ |
| 734 | public static final int RESULT_CANCELED = 0; |
| 735 | /** Standard activity result: operation succeeded. */ |
| 736 | public static final int RESULT_OK = -1; |
| 737 | /** Start of user-defined activity results. */ |
| 738 | public static final int RESULT_FIRST_USER = 1; |
| 739 | |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 740 | /** @hide Task isn't finished when activity is finished */ |
| 741 | public static final int DONT_FINISH_TASK_WITH_ACTIVITY = 0; |
Filip Gruszczynski | c29ecc8 | 2015-10-08 11:08:44 -0700 | [diff] [blame] | 742 | /** |
| 743 | * @hide Task is finished if the finishing activity is the root of the task. To preserve the |
| 744 | * past behavior the task is also removed from recents. |
| 745 | */ |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 746 | public static final int FINISH_TASK_WITH_ROOT_ACTIVITY = 1; |
Filip Gruszczynski | c29ecc8 | 2015-10-08 11:08:44 -0700 | [diff] [blame] | 747 | /** |
| 748 | * @hide Task is finished along with the finishing activity, but it is not removed from |
| 749 | * recents. |
| 750 | */ |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 751 | public static final int FINISH_TASK_WITH_ACTIVITY = 2; |
| 752 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 753 | @UnsupportedAppUsage |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 754 | static final String FRAGMENTS_TAG = "android:fragments"; |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 755 | private static final String LAST_AUTOFILL_ID = "android:lastAutofillId"; |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 756 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 757 | private static final String AUTOFILL_RESET_NEEDED = "@android:autofillResetNeeded"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 758 | private static final String WINDOW_HIERARCHY_TAG = "android:viewHierarchyState"; |
| 759 | private static final String SAVED_DIALOG_IDS_KEY = "android:savedDialogIds"; |
| 760 | private static final String SAVED_DIALOGS_TAG = "android:savedDialogs"; |
| 761 | private static final String SAVED_DIALOG_KEY_PREFIX = "android:dialog_"; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 762 | private static final String SAVED_DIALOG_ARGS_KEY_PREFIX = "android:dialog_args_"; |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 763 | private static final String HAS_CURENT_PERMISSIONS_REQUEST_KEY = |
| 764 | "android:hasCurrentPermissionsRequest"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 765 | |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 766 | private static final String REQUEST_PERMISSIONS_WHO_PREFIX = "@android:requestPermissions:"; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 767 | private static final String AUTO_FILL_AUTH_WHO_PREFIX = "@android:autoFillAuth:"; |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 768 | |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 769 | private static final String KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME = "com.android.systemui"; |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 770 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 771 | private static final int LOG_AM_ON_CREATE_CALLED = 30057; |
| 772 | private static final int LOG_AM_ON_START_CALLED = 30059; |
| 773 | private static final int LOG_AM_ON_RESUME_CALLED = 30022; |
| 774 | private static final int LOG_AM_ON_PAUSE_CALLED = 30021; |
| 775 | private static final int LOG_AM_ON_STOP_CALLED = 30049; |
| 776 | private static final int LOG_AM_ON_RESTART_CALLED = 30058; |
| 777 | private static final int LOG_AM_ON_DESTROY_CALLED = 30060; |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 778 | private static final int LOG_AM_ON_ACTIVITY_RESULT_CALLED = 30062; |
Andrii Kulian | 8602401 | 2019-04-18 19:41:23 -0700 | [diff] [blame] | 779 | private static final int LOG_AM_ON_TOP_RESUMED_GAINED_CALLED = 30064; |
| 780 | private static final int LOG_AM_ON_TOP_RESUMED_LOST_CALLED = 30065; |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 781 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 782 | private static class ManagedDialog { |
| 783 | Dialog mDialog; |
| 784 | Bundle mArgs; |
| 785 | } |
| 786 | private SparseArray<ManagedDialog> mManagedDialogs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | |
| 788 | // set by the thread after the constructor and before onCreate(Bundle savedInstanceState) is called. |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 789 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 790 | private Instrumentation mInstrumentation; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 791 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 792 | private IBinder mToken; |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 793 | private IBinder mAssistToken; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 794 | @UnsupportedAppUsage |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 795 | private int mIdent; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 796 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | /*package*/ String mEmbeddedID; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 798 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | private Application mApplication; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 800 | @UnsupportedAppUsage |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 801 | /*package*/ Intent mIntent; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 802 | @UnsupportedAppUsage |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 803 | /*package*/ String mReferrer; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 804 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 805 | private ComponentName mComponent; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 806 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | /*package*/ ActivityInfo mActivityInfo; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 808 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | /*package*/ ActivityThread mMainThread; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 810 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 811 | Activity mParent; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 812 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | boolean mCalled; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 814 | @UnsupportedAppUsage |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 815 | /*package*/ boolean mResumed; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 816 | @UnsupportedAppUsage |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 817 | /*package*/ boolean mStopped; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 818 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | boolean mFinished; |
| 820 | boolean mStartedActivity; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 821 | @UnsupportedAppUsage |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 822 | private boolean mDestroyed; |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 823 | private boolean mDoReportFullyDrawn = true; |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 824 | private boolean mRestoredFromBundle; |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 825 | |
| 826 | /** {@code true} if the activity lifecycle is in a state which supports picture-in-picture. |
| 827 | * This only affects the client-side exception, the actual state check still happens in AMS. */ |
| 828 | private boolean mCanEnterPictureInPicture = false; |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 829 | /** true if the activity is being destroyed in order to recreate it with a new configuration */ |
| 830 | /*package*/ boolean mChangingConfigurations = false; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 831 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | /*package*/ int mConfigChangeFlags; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 833 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | /*package*/ Configuration mCurrentConfig; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 835 | private SearchManager mSearchManager; |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 836 | private MenuInflater mMenuInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 838 | /** The autofill manager. Always access via {@link #getAutofillManager()}. */ |
| 839 | @Nullable private AutofillManager mAutofillManager; |
| 840 | |
Adam He | 43c0699 | 2019-04-15 15:41:49 -0700 | [diff] [blame] | 841 | /** The content capture manager. Access via {@link #getContentCaptureManager()}. */ |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 842 | @Nullable private ContentCaptureManager mContentCaptureManager; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 843 | |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 844 | private final ArrayList<Application.ActivityLifecycleCallbacks> mActivityLifecycleCallbacks = |
| 845 | new ArrayList<Application.ActivityLifecycleCallbacks>(); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 846 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 847 | static final class NonConfigurationInstances { |
| 848 | Object activity; |
| 849 | HashMap<String, Object> children; |
Adam Powell | 44ba79e | 2016-02-04 16:20:37 -0800 | [diff] [blame] | 850 | FragmentManagerNonConfig fragments; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 851 | ArrayMap<String, LoaderManager> loaders; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 852 | VoiceInteractor voiceInteractor; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 853 | } |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 854 | @UnsupportedAppUsage |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 855 | /* package */ NonConfigurationInstances mLastNonConfigurationInstances; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 856 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 857 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 858 | private Window mWindow; |
| 859 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 860 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | private WindowManager mWindowManager; |
| 862 | /*package*/ View mDecor = null; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 863 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | /*package*/ boolean mWindowAdded = false; |
| 865 | /*package*/ boolean mVisibleFromServer = false; |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 866 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 867 | /*package*/ boolean mVisibleFromClient = true; |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 868 | /*package*/ ActionBar mActionBar = null; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 869 | private boolean mEnableDefaultActionBarUp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 870 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 871 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 872 | VoiceInteractor mVoiceInteractor; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 873 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 874 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 875 | private CharSequence mTitle; |
| 876 | private int mTitleColor = 0; |
| 877 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 878 | // we must have a handler before the FragmentController is constructed |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 879 | @UnsupportedAppUsage |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 880 | final Handler mHandler = new Handler(); |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 881 | @UnsupportedAppUsage |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 882 | final FragmentController mFragments = FragmentController.createController(new HostCallbacks()); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 883 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | private static final class ManagedCursor { |
| 885 | ManagedCursor(Cursor cursor) { |
| 886 | mCursor = cursor; |
| 887 | mReleased = false; |
| 888 | mUpdated = false; |
| 889 | } |
| 890 | |
| 891 | private final Cursor mCursor; |
| 892 | private boolean mReleased; |
| 893 | private boolean mUpdated; |
| 894 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 895 | |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 896 | @GuardedBy("mManagedCursors") |
| 897 | private final ArrayList<ManagedCursor> mManagedCursors = new ArrayList<>(); |
| 898 | |
| 899 | @GuardedBy("this") |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 900 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | int mResultCode = RESULT_CANCELED; |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 902 | @GuardedBy("this") |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 903 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 904 | Intent mResultData = null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 905 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 906 | private TranslucentConversionListener mTranslucentCallback; |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 907 | private boolean mChangeCanvasToTranslucent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 908 | |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 909 | private SearchEvent mSearchEvent; |
| 910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 911 | private boolean mTitleReady = false; |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 912 | private int mActionModeTypeStarting = ActionMode.TYPE_PRIMARY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | |
| 914 | private int mDefaultKeyMode = DEFAULT_KEYS_DISABLE; |
| 915 | private SpannableStringBuilder mDefaultKeySsb = null; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 916 | |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 917 | private ActivityManager.TaskDescription mTaskDescription = |
| 918 | new ActivityManager.TaskDescription(); |
| 919 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | protected static final int[] FOCUSED_STATE_SET = {com.android.internal.R.attr.state_focused}; |
| 921 | |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 922 | @SuppressWarnings("unused") |
Jeff Brown | 7e44283 | 2011-06-10 18:00:16 -0700 | [diff] [blame] | 923 | private final Object mInstanceTracker = StrictMode.trackActivity(this); |
| 924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | private Thread mUiThread; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 926 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 927 | @UnsupportedAppUsage |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 928 | ActivityTransitionState mActivityTransitionState = new ActivityTransitionState(); |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 929 | SharedElementCallback mEnterTransitionListener = SharedElementCallback.NULL_CALLBACK; |
| 930 | SharedElementCallback mExitTransitionListener = SharedElementCallback.NULL_CALLBACK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 931 | |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 932 | private boolean mHasCurrentPermissionsRequest; |
| 933 | |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 934 | private boolean mAutoFillResetNeeded; |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 935 | private boolean mAutoFillIgnoreFirstResumePause; |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 936 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 937 | /** The last autofill id that was returned from {@link #getNextAutofillId()} */ |
| 938 | private int mLastAutofillId = View.LAST_APP_AUTOFILL_ID; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 939 | |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 940 | private AutofillPopupWindow mAutofillPopupWindow; |
| 941 | |
chaviw | feb2e1e | 2018-12-19 17:24:11 -0800 | [diff] [blame] | 942 | /** @hide */ |
| 943 | boolean mEnterAnimationComplete; |
| 944 | |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 945 | private static native String getDlWarning(); |
| 946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | /** Return the intent that started this activity. */ |
| 948 | public Intent getIntent() { |
| 949 | return mIntent; |
| 950 | } |
| 951 | |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 952 | /** |
| 953 | * Change the intent returned by {@link #getIntent}. This holds a |
| 954 | * reference to the given intent; it does not copy it. Often used in |
| 955 | * conjunction with {@link #onNewIntent}. |
| 956 | * |
| 957 | * @param newIntent The new Intent object to return from getIntent |
| 958 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 959 | * @see #getIntent |
| 960 | * @see #onNewIntent |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 961 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | public void setIntent(Intent newIntent) { |
| 963 | mIntent = newIntent; |
| 964 | } |
| 965 | |
| 966 | /** Return the application that owns this activity. */ |
| 967 | public final Application getApplication() { |
| 968 | return mApplication; |
| 969 | } |
| 970 | |
| 971 | /** Is this activity embedded inside of another activity? */ |
| 972 | public final boolean isChild() { |
| 973 | return mParent != null; |
| 974 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 975 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 976 | /** Return the parent activity if this view is an embedded child. */ |
| 977 | public final Activity getParent() { |
| 978 | return mParent; |
| 979 | } |
| 980 | |
| 981 | /** Retrieve the window manager for showing custom windows. */ |
| 982 | public WindowManager getWindowManager() { |
| 983 | return mWindowManager; |
| 984 | } |
| 985 | |
| 986 | /** |
| 987 | * Retrieve the current {@link android.view.Window} for the activity. |
| 988 | * This can be used to directly access parts of the Window API that |
| 989 | * are not available through Activity/Screen. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 990 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | * @return Window The current window, or null if the activity is not |
| 992 | * visual. |
| 993 | */ |
| 994 | public Window getWindow() { |
| 995 | return mWindow; |
| 996 | } |
| 997 | |
| 998 | /** |
Mark Doliner | 9525f2a | 2014-01-02 11:17:47 -0800 | [diff] [blame] | 999 | * Return the LoaderManager for this activity, creating it if needed. |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 1000 | * |
| 1001 | * @deprecated Use {@link android.support.v4.app.FragmentActivity#getSupportLoaderManager()} |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 1002 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 1003 | @Deprecated |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 1004 | public LoaderManager getLoaderManager() { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 1005 | return mFragments.getLoaderManager(); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 1006 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1007 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 1008 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | * Calls {@link android.view.Window#getCurrentFocus} on the |
| 1010 | * Window of this Activity to return the currently focused view. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1011 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | * @return View The current View with focus or null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1013 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1014 | * @see #getWindow |
| 1015 | * @see android.view.Window#getCurrentFocus |
| 1016 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1017 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | public View getCurrentFocus() { |
| 1019 | return mWindow != null ? mWindow.getCurrentFocus() : null; |
| 1020 | } |
| 1021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1022 | /** |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1023 | * (Creates, sets and) returns the autofill manager |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1024 | * |
| 1025 | * @return The autofill manager |
| 1026 | */ |
| 1027 | @NonNull private AutofillManager getAutofillManager() { |
| 1028 | if (mAutofillManager == null) { |
| 1029 | mAutofillManager = getSystemService(AutofillManager.class); |
| 1030 | } |
| 1031 | |
| 1032 | return mAutofillManager; |
| 1033 | } |
| 1034 | |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1035 | /** |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 1036 | * (Creates, sets, and ) returns the content capture manager |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1037 | * |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 1038 | * @return The content capture manager |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1039 | */ |
Adam He | b66babb | 2019-01-08 15:43:53 -0800 | [diff] [blame] | 1040 | @Nullable private ContentCaptureManager getContentCaptureManager() { |
| 1041 | // ContextCapture disabled for system apps |
Felipe Leme | 0c6b23d | 2019-01-15 17:02:49 -0800 | [diff] [blame] | 1042 | if (!UserHandle.isApp(myUid())) return null; |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 1043 | if (mContentCaptureManager == null) { |
| 1044 | mContentCaptureManager = getSystemService(ContentCaptureManager.class); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1045 | } |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 1046 | return mContentCaptureManager; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1047 | } |
| 1048 | |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 1049 | /** @hide */ private static final int CONTENT_CAPTURE_START = 1; |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 1050 | /** @hide */ private static final int CONTENT_CAPTURE_RESUME = 2; |
| 1051 | /** @hide */ private static final int CONTENT_CAPTURE_PAUSE = 3; |
| 1052 | /** @hide */ private static final int CONTENT_CAPTURE_STOP = 4; |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 1053 | |
| 1054 | /** @hide */ |
| 1055 | @IntDef(prefix = { "CONTENT_CAPTURE_" }, value = { |
| 1056 | CONTENT_CAPTURE_START, |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 1057 | CONTENT_CAPTURE_RESUME, |
| 1058 | CONTENT_CAPTURE_PAUSE, |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 1059 | CONTENT_CAPTURE_STOP |
| 1060 | }) |
| 1061 | @Retention(RetentionPolicy.SOURCE) |
| 1062 | @interface ContentCaptureNotificationType{} |
| 1063 | |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1064 | private String getContentCaptureTypeAsString(@ContentCaptureNotificationType int type) { |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 1065 | switch (type) { |
| 1066 | case CONTENT_CAPTURE_START: |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1067 | return "START"; |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 1068 | case CONTENT_CAPTURE_RESUME: |
| 1069 | return "RESUME"; |
| 1070 | case CONTENT_CAPTURE_PAUSE: |
| 1071 | return "PAUSE"; |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 1072 | case CONTENT_CAPTURE_STOP: |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1073 | return "STOP"; |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 1074 | default: |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1075 | return "UNKNOW-" + type; |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | private void notifyContentCaptureManagerIfNeeded(@ContentCaptureNotificationType int type) { |
| 1080 | if (Trace.isTagEnabled(Trace.TRACE_TAG_ACTIVITY_MANAGER)) { |
| 1081 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, |
| 1082 | "notifyContentCapture(" + getContentCaptureTypeAsString(type) + ") for " |
| 1083 | + mComponent.toShortString()); |
| 1084 | } |
| 1085 | try { |
| 1086 | final ContentCaptureManager cm = getContentCaptureManager(); |
| 1087 | if (cm == null) return; |
| 1088 | |
| 1089 | switch (type) { |
| 1090 | case CONTENT_CAPTURE_START: |
| 1091 | //TODO(b/111276913): decide whether the InteractionSessionId should be |
| 1092 | // saved / restored in the activity bundle - probably not |
Adam He | 43c0699 | 2019-04-15 15:41:49 -0700 | [diff] [blame] | 1093 | final Window window = getWindow(); |
| 1094 | if (window != null) { |
| 1095 | cm.updateWindowAttributes(window.getAttributes()); |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1096 | } |
Adam He | 43c0699 | 2019-04-15 15:41:49 -0700 | [diff] [blame] | 1097 | cm.onActivityCreated(mToken, getComponentName()); |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 1098 | break; |
| 1099 | case CONTENT_CAPTURE_RESUME: |
| 1100 | cm.onActivityResumed(); |
| 1101 | break; |
| 1102 | case CONTENT_CAPTURE_PAUSE: |
| 1103 | cm.onActivityPaused(); |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1104 | break; |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1105 | case CONTENT_CAPTURE_STOP: |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 1106 | cm.onActivityDestroyed(); |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1107 | break; |
| 1108 | default: |
| 1109 | Log.wtf(TAG, "Invalid @ContentCaptureNotificationType: " + type); |
| 1110 | } |
| 1111 | } finally { |
| 1112 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | |
Felipe Leme | bb567ae | 2017-10-04 09:56:21 -0700 | [diff] [blame] | 1116 | @Override |
| 1117 | protected void attachBaseContext(Context newBase) { |
| 1118 | super.attachBaseContext(newBase); |
Felipe Leme | d247de8 | 2018-05-14 17:51:58 -0700 | [diff] [blame] | 1119 | if (newBase != null) { |
| 1120 | newBase.setAutofillClient(this); |
Felipe Leme | 326f15a | 2019-02-19 09:42:24 -0800 | [diff] [blame] | 1121 | newBase.setContentCaptureOptions(getContentCaptureOptions()); |
Felipe Leme | d247de8 | 2018-05-14 17:51:58 -0700 | [diff] [blame] | 1122 | } |
Felipe Leme | bb567ae | 2017-10-04 09:56:21 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | /** @hide */ |
| 1126 | @Override |
| 1127 | public final AutofillClient getAutofillClient() { |
| 1128 | return this; |
| 1129 | } |
| 1130 | |
Felipe Leme | cbf7f26 | 2019-04-17 13:57:59 -0700 | [diff] [blame] | 1131 | /** @hide */ |
| 1132 | @Override |
| 1133 | public final ContentCaptureClient getContentCaptureClient() { |
| 1134 | return this; |
| 1135 | } |
| 1136 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1137 | /** |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 1138 | * Register an {@link Application.ActivityLifecycleCallbacks} instance that receives |
| 1139 | * lifecycle callbacks for only this Activity. |
| 1140 | * <p> |
| 1141 | * In relation to any |
| 1142 | * {@link Application#registerActivityLifecycleCallbacks Application registered callbacks}, |
| 1143 | * the callbacks registered here will always occur nested within those callbacks. This means: |
| 1144 | * <ul> |
| 1145 | * <li>Pre events will first be sent to Application registered callbacks, then to callbacks |
| 1146 | * registered here.</li> |
| 1147 | * <li>{@link Application.ActivityLifecycleCallbacks#onActivityCreated(Activity, Bundle)}, |
| 1148 | * {@link Application.ActivityLifecycleCallbacks#onActivityStarted(Activity)}, and |
| 1149 | * {@link Application.ActivityLifecycleCallbacks#onActivityResumed(Activity)} will |
| 1150 | * be sent first to Application registered callbacks, then to callbacks registered here. |
| 1151 | * For all other events, callbacks registered here will be sent first.</li> |
| 1152 | * <li>Post events will first be sent to callbacks registered here, then to |
| 1153 | * Application registered callbacks.</li> |
| 1154 | * </ul> |
| 1155 | * <p> |
| 1156 | * If multiple callbacks are registered here, they receive events in a first in (up through |
| 1157 | * {@link Application.ActivityLifecycleCallbacks#onActivityPostResumed}, last out |
| 1158 | * ordering. |
| 1159 | * <p> |
| 1160 | * It is strongly recommended to register this in the constructor of your Activity to ensure |
| 1161 | * you get all available callbacks. As this callback is associated with only this Activity, |
| 1162 | * it is not usually necessary to {@link #unregisterActivityLifecycleCallbacks unregister} it |
| 1163 | * unless you specifically do not want to receive further lifecycle callbacks. |
| 1164 | * |
| 1165 | * @param callback The callback instance to register |
| 1166 | */ |
| 1167 | public void registerActivityLifecycleCallbacks( |
| 1168 | @NonNull Application.ActivityLifecycleCallbacks callback) { |
| 1169 | synchronized (mActivityLifecycleCallbacks) { |
| 1170 | mActivityLifecycleCallbacks.add(callback); |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | /** |
| 1175 | * Unregister an {@link Application.ActivityLifecycleCallbacks} previously registered |
| 1176 | * with {@link #registerActivityLifecycleCallbacks}. It will not receive any further |
| 1177 | * callbacks. |
| 1178 | * |
| 1179 | * @param callback The callback instance to unregister |
| 1180 | * @see #registerActivityLifecycleCallbacks |
| 1181 | */ |
| 1182 | public void unregisterActivityLifecycleCallbacks( |
| 1183 | @NonNull Application.ActivityLifecycleCallbacks callback) { |
| 1184 | synchronized (mActivityLifecycleCallbacks) { |
| 1185 | mActivityLifecycleCallbacks.remove(callback); |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | private void dispatchActivityPreCreated(@Nullable Bundle savedInstanceState) { |
| 1190 | getApplication().dispatchActivityPreCreated(this, savedInstanceState); |
| 1191 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1192 | if (callbacks != null) { |
| 1193 | for (int i = 0; i < callbacks.length; i++) { |
| 1194 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPreCreated(this, |
| 1195 | savedInstanceState); |
| 1196 | } |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | private void dispatchActivityCreated(@Nullable Bundle savedInstanceState) { |
| 1201 | getApplication().dispatchActivityCreated(this, savedInstanceState); |
| 1202 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1203 | if (callbacks != null) { |
| 1204 | for (int i = 0; i < callbacks.length; i++) { |
| 1205 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityCreated(this, |
| 1206 | savedInstanceState); |
| 1207 | } |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | private void dispatchActivityPostCreated(@Nullable Bundle savedInstanceState) { |
| 1212 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1213 | if (callbacks != null) { |
| 1214 | for (int i = 0; i < callbacks.length; i++) { |
| 1215 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPostCreated(this, |
| 1216 | savedInstanceState); |
| 1217 | } |
| 1218 | } |
| 1219 | getApplication().dispatchActivityPostCreated(this, savedInstanceState); |
| 1220 | } |
| 1221 | |
| 1222 | private void dispatchActivityPreStarted() { |
| 1223 | getApplication().dispatchActivityPreStarted(this); |
| 1224 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1225 | if (callbacks != null) { |
| 1226 | for (int i = 0; i < callbacks.length; i++) { |
| 1227 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPreStarted(this); |
| 1228 | } |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | private void dispatchActivityStarted() { |
| 1233 | getApplication().dispatchActivityStarted(this); |
| 1234 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1235 | if (callbacks != null) { |
| 1236 | for (int i = 0; i < callbacks.length; i++) { |
| 1237 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityStarted(this); |
| 1238 | } |
| 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | private void dispatchActivityPostStarted() { |
| 1243 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1244 | if (callbacks != null) { |
| 1245 | for (int i = 0; i < callbacks.length; i++) { |
| 1246 | ((Application.ActivityLifecycleCallbacks) callbacks[i]) |
| 1247 | .onActivityPostStarted(this); |
| 1248 | } |
| 1249 | } |
| 1250 | getApplication().dispatchActivityPostStarted(this); |
| 1251 | } |
| 1252 | |
| 1253 | private void dispatchActivityPreResumed() { |
| 1254 | getApplication().dispatchActivityPreResumed(this); |
| 1255 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1256 | if (callbacks != null) { |
| 1257 | for (int i = 0; i < callbacks.length; i++) { |
| 1258 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPreResumed(this); |
| 1259 | } |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | private void dispatchActivityResumed() { |
| 1264 | getApplication().dispatchActivityResumed(this); |
| 1265 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1266 | if (callbacks != null) { |
| 1267 | for (int i = 0; i < callbacks.length; i++) { |
| 1268 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityResumed(this); |
| 1269 | } |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | private void dispatchActivityPostResumed() { |
| 1274 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1275 | if (callbacks != null) { |
| 1276 | for (int i = 0; i < callbacks.length; i++) { |
| 1277 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPostResumed(this); |
| 1278 | } |
| 1279 | } |
| 1280 | getApplication().dispatchActivityPostResumed(this); |
| 1281 | } |
| 1282 | |
| 1283 | private void dispatchActivityPrePaused() { |
| 1284 | getApplication().dispatchActivityPrePaused(this); |
| 1285 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1286 | if (callbacks != null) { |
| 1287 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1288 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPrePaused(this); |
| 1289 | } |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | private void dispatchActivityPaused() { |
| 1294 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1295 | if (callbacks != null) { |
| 1296 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1297 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPaused(this); |
| 1298 | } |
| 1299 | } |
| 1300 | getApplication().dispatchActivityPaused(this); |
| 1301 | } |
| 1302 | |
| 1303 | private void dispatchActivityPostPaused() { |
| 1304 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1305 | if (callbacks != null) { |
| 1306 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1307 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPostPaused(this); |
| 1308 | } |
| 1309 | } |
| 1310 | getApplication().dispatchActivityPostPaused(this); |
| 1311 | } |
| 1312 | |
| 1313 | private void dispatchActivityPreStopped() { |
| 1314 | getApplication().dispatchActivityPreStopped(this); |
| 1315 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1316 | if (callbacks != null) { |
| 1317 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1318 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPreStopped(this); |
| 1319 | } |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | private void dispatchActivityStopped() { |
| 1324 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1325 | if (callbacks != null) { |
| 1326 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1327 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityStopped(this); |
| 1328 | } |
| 1329 | } |
| 1330 | getApplication().dispatchActivityStopped(this); |
| 1331 | } |
| 1332 | |
| 1333 | private void dispatchActivityPostStopped() { |
| 1334 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1335 | if (callbacks != null) { |
| 1336 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1337 | ((Application.ActivityLifecycleCallbacks) callbacks[i]) |
| 1338 | .onActivityPostStopped(this); |
| 1339 | } |
| 1340 | } |
| 1341 | getApplication().dispatchActivityPostStopped(this); |
| 1342 | } |
| 1343 | |
| 1344 | private void dispatchActivityPreSaveInstanceState(@NonNull Bundle outState) { |
| 1345 | getApplication().dispatchActivityPreSaveInstanceState(this, outState); |
| 1346 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1347 | if (callbacks != null) { |
| 1348 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1349 | ((Application.ActivityLifecycleCallbacks) callbacks[i]) |
| 1350 | .onActivityPreSaveInstanceState(this, outState); |
| 1351 | } |
| 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | private void dispatchActivitySaveInstanceState(@NonNull Bundle outState) { |
| 1356 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1357 | if (callbacks != null) { |
| 1358 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1359 | ((Application.ActivityLifecycleCallbacks) callbacks[i]) |
| 1360 | .onActivitySaveInstanceState(this, outState); |
| 1361 | } |
| 1362 | } |
| 1363 | getApplication().dispatchActivitySaveInstanceState(this, outState); |
| 1364 | } |
| 1365 | |
| 1366 | private void dispatchActivityPostSaveInstanceState(@NonNull Bundle outState) { |
| 1367 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1368 | if (callbacks != null) { |
| 1369 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1370 | ((Application.ActivityLifecycleCallbacks) callbacks[i]) |
| 1371 | .onActivityPostSaveInstanceState(this, outState); |
| 1372 | } |
| 1373 | } |
| 1374 | getApplication().dispatchActivityPostSaveInstanceState(this, outState); |
| 1375 | } |
| 1376 | |
| 1377 | private void dispatchActivityPreDestroyed() { |
| 1378 | getApplication().dispatchActivityPreDestroyed(this); |
| 1379 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1380 | if (callbacks != null) { |
| 1381 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1382 | ((Application.ActivityLifecycleCallbacks) callbacks[i]) |
| 1383 | .onActivityPreDestroyed(this); |
| 1384 | } |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | private void dispatchActivityDestroyed() { |
| 1389 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1390 | if (callbacks != null) { |
| 1391 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1392 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityDestroyed(this); |
| 1393 | } |
| 1394 | } |
| 1395 | getApplication().dispatchActivityDestroyed(this); |
| 1396 | } |
| 1397 | |
| 1398 | private void dispatchActivityPostDestroyed() { |
| 1399 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1400 | if (callbacks != null) { |
| 1401 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1402 | ((Application.ActivityLifecycleCallbacks) callbacks[i]) |
| 1403 | .onActivityPostDestroyed(this); |
| 1404 | } |
| 1405 | } |
| 1406 | getApplication().dispatchActivityPostDestroyed(this); |
| 1407 | } |
| 1408 | |
| 1409 | private Object[] collectActivityLifecycleCallbacks() { |
| 1410 | Object[] callbacks = null; |
| 1411 | synchronized (mActivityLifecycleCallbacks) { |
| 1412 | if (mActivityLifecycleCallbacks.size() > 0) { |
| 1413 | callbacks = mActivityLifecycleCallbacks.toArray(); |
| 1414 | } |
| 1415 | } |
| 1416 | return callbacks; |
| 1417 | } |
| 1418 | |
| 1419 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1420 | * Called when the activity is starting. This is where most initialization |
| 1421 | * should go: calling {@link #setContentView(int)} to inflate the |
| 1422 | * activity's UI, using {@link #findViewById} to programmatically interact |
| 1423 | * with widgets in the UI, calling |
| 1424 | * {@link #managedQuery(android.net.Uri , String[], String, String[], String)} to retrieve |
| 1425 | * cursors for data being displayed, etc. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1426 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | * <p>You can call {@link #finish} from within this function, in |
Bryce Lee | 476edc8 | 2018-03-12 10:06:23 -0700 | [diff] [blame] | 1428 | * which case onDestroy() will be immediately called after {@link #onCreate} without any of the |
| 1429 | * rest of the activity lifecycle ({@link #onStart}, {@link #onResume}, {@link #onPause}, etc) |
| 1430 | * executing. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1431 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | * <p><em>Derived classes must call through to the super class's |
| 1433 | * implementation of this method. If they do not, an exception will be |
| 1434 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1435 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1436 | * @param savedInstanceState If the activity is being re-initialized after |
| 1437 | * previously being shut down then this Bundle contains the data it most |
| 1438 | * recently supplied in {@link #onSaveInstanceState}. <b><i>Note: Otherwise it is null.</i></b> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1439 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1440 | * @see #onStart |
| 1441 | * @see #onSaveInstanceState |
| 1442 | * @see #onRestoreInstanceState |
| 1443 | * @see #onPostCreate |
| 1444 | */ |
Tor Norbye | 83c6896 | 2015-03-10 20:55:31 -0700 | [diff] [blame] | 1445 | @MainThread |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1446 | @CallSuper |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1447 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1448 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState); |
Bryce Lee | 3979159 | 2017-04-26 09:29:12 -0700 | [diff] [blame] | 1449 | |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 1450 | if (mLastNonConfigurationInstances != null) { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 1451 | mFragments.restoreLoaderNonConfig(mLastNonConfigurationInstances.loaders); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 1452 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 1453 | if (mActivityInfo.parentActivityName != null) { |
| 1454 | if (mActionBar == null) { |
| 1455 | mEnableDefaultActionBarUp = true; |
| 1456 | } else { |
| 1457 | mActionBar.setDefaultDisplayHomeAsUpEnabled(true); |
| 1458 | } |
| 1459 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1460 | if (savedInstanceState != null) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1461 | mAutoFillResetNeeded = savedInstanceState.getBoolean(AUTOFILL_RESET_NEEDED, false); |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 1462 | mLastAutofillId = savedInstanceState.getInt(LAST_AUTOFILL_ID, |
| 1463 | View.LAST_APP_AUTOFILL_ID); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1464 | |
| 1465 | if (mAutoFillResetNeeded) { |
| 1466 | getAutofillManager().onCreate(savedInstanceState); |
| 1467 | } |
| 1468 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1469 | Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG); |
| 1470 | mFragments.restoreAllState(p, mLastNonConfigurationInstances != null |
| 1471 | ? mLastNonConfigurationInstances.fragments : null); |
| 1472 | } |
| 1473 | mFragments.dispatchCreate(); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 1474 | dispatchActivityCreated(savedInstanceState); |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 1475 | if (mVoiceInteractor != null) { |
| 1476 | mVoiceInteractor.attachActivity(this); |
| 1477 | } |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 1478 | mRestoredFromBundle = savedInstanceState != null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | mCalled = true; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1484 | * Same as {@link #onCreate(android.os.Bundle)} but called for those activities created with |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 1485 | * the attribute {@link android.R.attr#persistableMode} set to |
| 1486 | * <code>persistAcrossReboots</code>. |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1487 | * |
| 1488 | * @param savedInstanceState if the activity is being re-initialized after |
| 1489 | * previously being shut down then this Bundle contains the data it most |
| 1490 | * recently supplied in {@link #onSaveInstanceState}. |
| 1491 | * <b><i>Note: Otherwise it is null.</i></b> |
| 1492 | * @param persistentState if the activity is being re-initialized after |
| 1493 | * previously being shut down or powered off then this Bundle contains the data it most |
| 1494 | * recently supplied to outPersistentState in {@link #onSaveInstanceState}. |
| 1495 | * <b><i>Note: Otherwise it is null.</i></b> |
| 1496 | * |
| 1497 | * @see #onCreate(android.os.Bundle) |
| 1498 | * @see #onStart |
| 1499 | * @see #onSaveInstanceState |
| 1500 | * @see #onRestoreInstanceState |
| 1501 | * @see #onPostCreate |
| 1502 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1503 | public void onCreate(@Nullable Bundle savedInstanceState, |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1504 | @Nullable PersistableBundle persistentState) { |
| 1505 | onCreate(savedInstanceState); |
| 1506 | } |
| 1507 | |
| 1508 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1509 | * The hook for {@link ActivityThread} to restore the state of this activity. |
| 1510 | * |
| 1511 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} and |
| 1512 | * {@link #restoreManagedDialogs(android.os.Bundle)}. |
| 1513 | * |
| 1514 | * @param savedInstanceState contains the saved state |
| 1515 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 1516 | final void performRestoreInstanceState(@NonNull Bundle savedInstanceState) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | onRestoreInstanceState(savedInstanceState); |
| 1518 | restoreManagedDialogs(savedInstanceState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1522 | * The hook for {@link ActivityThread} to restore the state of this activity. |
| 1523 | * |
| 1524 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} and |
| 1525 | * {@link #restoreManagedDialogs(android.os.Bundle)}. |
| 1526 | * |
| 1527 | * @param savedInstanceState contains the saved state |
| 1528 | * @param persistentState contains the persistable saved state |
| 1529 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 1530 | final void performRestoreInstanceState(@Nullable Bundle savedInstanceState, |
| 1531 | @Nullable PersistableBundle persistentState) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1532 | onRestoreInstanceState(savedInstanceState, persistentState); |
| 1533 | if (savedInstanceState != null) { |
| 1534 | restoreManagedDialogs(savedInstanceState); |
| 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1539 | * This method is called after {@link #onStart} when the activity is |
| 1540 | * being re-initialized from a previously saved state, given here in |
Mike LeBeau | 305de9d | 2010-03-11 09:21:08 -0800 | [diff] [blame] | 1541 | * <var>savedInstanceState</var>. Most implementations will simply use {@link #onCreate} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1542 | * to restore their state, but it is sometimes convenient to do it here |
| 1543 | * after all of the initialization has been done or to allow subclasses to |
| 1544 | * decide whether to use your default implementation. The default |
| 1545 | * implementation of this method performs a restore of any view state that |
| 1546 | * had previously been frozen by {@link #onSaveInstanceState}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1547 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1548 | * <p>This method is called between {@link #onStart} and |
Kevin Hufnagle | 4fbcec1 | 2019-07-18 21:37:36 +0000 | [diff] [blame] | 1549 | * {@link #onPostCreate}. This method is called only when recreating |
| 1550 | * an activity; the method isn't invoked if {@link #onStart} is called for |
| 1551 | * any other reason.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1552 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1553 | * @param savedInstanceState the data most recently supplied in {@link #onSaveInstanceState}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1554 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1555 | * @see #onCreate |
| 1556 | * @see #onPostCreate |
| 1557 | * @see #onResume |
| 1558 | * @see #onSaveInstanceState |
| 1559 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 1560 | protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1561 | if (mWindow != null) { |
| 1562 | Bundle windowState = savedInstanceState.getBundle(WINDOW_HIERARCHY_TAG); |
| 1563 | if (windowState != null) { |
| 1564 | mWindow.restoreHierarchyState(windowState); |
| 1565 | } |
| 1566 | } |
| 1567 | } |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1568 | |
| 1569 | /** |
| 1570 | * This is the same as {@link #onRestoreInstanceState(Bundle)} but is called for activities |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 1571 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 1572 | * <code>persistAcrossReboots</code>. The {@link android.os.PersistableBundle} passed |
| 1573 | * came from the restored PersistableBundle first |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1574 | * saved in {@link #onSaveInstanceState(Bundle, PersistableBundle)}. |
| 1575 | * |
| 1576 | * <p>This method is called between {@link #onStart} and |
| 1577 | * {@link #onPostCreate}. |
| 1578 | * |
| 1579 | * <p>If this method is called {@link #onRestoreInstanceState(Bundle)} will not be called. |
| 1580 | * |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 1581 | * <p>At least one of {@code savedInstanceState} or {@code persistentState} will not be null. |
| 1582 | * |
| 1583 | * @param savedInstanceState the data most recently supplied in {@link #onSaveInstanceState} |
| 1584 | * or null. |
| 1585 | * @param persistentState the data most recently supplied in {@link #onSaveInstanceState} |
| 1586 | * or null. |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1587 | * |
| 1588 | * @see #onRestoreInstanceState(Bundle) |
| 1589 | * @see #onCreate |
| 1590 | * @see #onPostCreate |
| 1591 | * @see #onResume |
| 1592 | * @see #onSaveInstanceState |
| 1593 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 1594 | public void onRestoreInstanceState(@Nullable Bundle savedInstanceState, |
| 1595 | @Nullable PersistableBundle persistentState) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1596 | if (savedInstanceState != null) { |
| 1597 | onRestoreInstanceState(savedInstanceState); |
| 1598 | } |
| 1599 | } |
| 1600 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1601 | /** |
| 1602 | * Restore the state of any saved managed dialogs. |
| 1603 | * |
| 1604 | * @param savedInstanceState The bundle to restore from. |
| 1605 | */ |
| 1606 | private void restoreManagedDialogs(Bundle savedInstanceState) { |
| 1607 | final Bundle b = savedInstanceState.getBundle(SAVED_DIALOGS_TAG); |
| 1608 | if (b == null) { |
| 1609 | return; |
| 1610 | } |
| 1611 | |
| 1612 | final int[] ids = b.getIntArray(SAVED_DIALOG_IDS_KEY); |
| 1613 | final int numDialogs = ids.length; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1614 | mManagedDialogs = new SparseArray<ManagedDialog>(numDialogs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1615 | for (int i = 0; i < numDialogs; i++) { |
| 1616 | final Integer dialogId = ids[i]; |
| 1617 | Bundle dialogState = b.getBundle(savedDialogKeyFor(dialogId)); |
| 1618 | if (dialogState != null) { |
Romain Guy | e35c235 | 2009-06-19 13:18:12 -0700 | [diff] [blame] | 1619 | // Calling onRestoreInstanceState() below will invoke dispatchOnCreate |
| 1620 | // so tell createDialog() not to do it, otherwise we get an exception |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1621 | final ManagedDialog md = new ManagedDialog(); |
| 1622 | md.mArgs = b.getBundle(savedDialogArgsKeyFor(dialogId)); |
| 1623 | md.mDialog = createDialog(dialogId, dialogState, md.mArgs); |
| 1624 | if (md.mDialog != null) { |
| 1625 | mManagedDialogs.put(dialogId, md); |
| 1626 | onPrepareDialog(dialogId, md.mDialog, md.mArgs); |
| 1627 | md.mDialog.onRestoreInstanceState(dialogState); |
| 1628 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1629 | } |
| 1630 | } |
| 1631 | } |
| 1632 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1633 | private Dialog createDialog(Integer dialogId, Bundle state, Bundle args) { |
| 1634 | final Dialog dialog = onCreateDialog(dialogId, args); |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1635 | if (dialog == null) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1636 | return null; |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1637 | } |
Romain Guy | 6de4aed | 2009-07-08 10:54:45 -0700 | [diff] [blame] | 1638 | dialog.dispatchOnCreate(state); |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1639 | return dialog; |
| 1640 | } |
| 1641 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1642 | private static String savedDialogKeyFor(int key) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1643 | return SAVED_DIALOG_KEY_PREFIX + key; |
| 1644 | } |
| 1645 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1646 | private static String savedDialogArgsKeyFor(int key) { |
| 1647 | return SAVED_DIALOG_ARGS_KEY_PREFIX + key; |
| 1648 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1649 | |
| 1650 | /** |
| 1651 | * Called when activity start-up is complete (after {@link #onStart} |
| 1652 | * and {@link #onRestoreInstanceState} have been called). Applications will |
| 1653 | * generally not implement this method; it is intended for system |
| 1654 | * classes to do final initialization after application code has run. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1655 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1656 | * <p><em>Derived classes must call through to the super class's |
| 1657 | * implementation of this method. If they do not, an exception will be |
| 1658 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1659 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1660 | * @param savedInstanceState If the activity is being re-initialized after |
| 1661 | * previously being shut down then this Bundle contains the data it most |
| 1662 | * recently supplied in {@link #onSaveInstanceState}. <b><i>Note: Otherwise it is null.</i></b> |
| 1663 | * @see #onCreate |
| 1664 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1665 | @CallSuper |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1666 | protected void onPostCreate(@Nullable Bundle savedInstanceState) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1667 | if (!isChild()) { |
| 1668 | mTitleReady = true; |
| 1669 | onTitleChanged(getTitle(), getTitleColor()); |
| 1670 | } |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 1671 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1672 | mCalled = true; |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 1673 | |
| 1674 | notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_START); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1678 | * This is the same as {@link #onPostCreate(Bundle)} but is called for activities |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 1679 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 1680 | * <code>persistAcrossReboots</code>. |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1681 | * |
| 1682 | * @param savedInstanceState The data most recently supplied in {@link #onSaveInstanceState} |
| 1683 | * @param persistentState The data caming from the PersistableBundle first |
| 1684 | * saved in {@link #onSaveInstanceState(Bundle, PersistableBundle)}. |
| 1685 | * |
| 1686 | * @see #onCreate |
| 1687 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1688 | public void onPostCreate(@Nullable Bundle savedInstanceState, |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1689 | @Nullable PersistableBundle persistentState) { |
| 1690 | onPostCreate(savedInstanceState); |
| 1691 | } |
| 1692 | |
| 1693 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1694 | * Called after {@link #onCreate} — or after {@link #onRestart} when |
| 1695 | * the activity had been stopped, but is now again being displayed to the |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 1696 | * user. It will usually be followed by {@link #onResume}. This is a good place to begin |
| 1697 | * drawing visual elements, running animations, etc. |
| 1698 | * |
| 1699 | * <p>You can call {@link #finish} from within this function, in |
| 1700 | * which case {@link #onStop} will be immediately called after {@link #onStart} without the |
| 1701 | * lifecycle transitions in-between ({@link #onResume}, {@link #onPause}, etc) executing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1702 | * |
| 1703 | * <p><em>Derived classes must call through to the super class's |
| 1704 | * implementation of this method. If they do not, an exception will be |
| 1705 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1706 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1707 | * @see #onCreate |
| 1708 | * @see #onStop |
| 1709 | * @see #onResume |
| 1710 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1711 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1712 | protected void onStart() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1713 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onStart " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1714 | mCalled = true; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1715 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 1716 | mFragments.doLoaderStart(); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1717 | |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 1718 | dispatchActivityStarted(); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1719 | |
| 1720 | if (mAutoFillResetNeeded) { |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 1721 | getAutofillManager().onVisibleForAutofill(); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1722 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | /** |
| 1726 | * Called after {@link #onStop} when the current activity is being |
| 1727 | * re-displayed to the user (the user has navigated back to it). It will |
| 1728 | * be followed by {@link #onStart} and then {@link #onResume}. |
| 1729 | * |
| 1730 | * <p>For activities that are using raw {@link Cursor} objects (instead of |
| 1731 | * creating them through |
| 1732 | * {@link #managedQuery(android.net.Uri , String[], String, String[], String)}, |
| 1733 | * this is usually the place |
| 1734 | * where the cursor should be requeried (because you had deactivated it in |
| 1735 | * {@link #onStop}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1736 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1737 | * <p><em>Derived classes must call through to the super class's |
| 1738 | * implementation of this method. If they do not, an exception will be |
| 1739 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1740 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1741 | * @see #onStop |
| 1742 | * @see #onStart |
| 1743 | * @see #onResume |
| 1744 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1745 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1746 | protected void onRestart() { |
| 1747 | mCalled = true; |
| 1748 | } |
| 1749 | |
| 1750 | /** |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 1751 | * Called when an {@link #onResume} is coming up, prior to other pre-resume callbacks |
| 1752 | * such as {@link #onNewIntent} and {@link #onActivityResult}. This is primarily intended |
| 1753 | * to give the activity a hint that its state is no longer saved -- it will generally |
| 1754 | * be called after {@link #onSaveInstanceState} and prior to the activity being |
| 1755 | * resumed/started again. |
Sergey Vasilinets | 0de0eca | 2018-08-23 19:28:57 -0700 | [diff] [blame] | 1756 | * |
| 1757 | * @deprecated starting with {@link android.os.Build.VERSION_CODES#P} onSaveInstanceState is |
| 1758 | * called after {@link #onStop}, so this hint isn't accurate anymore: you should consider your |
| 1759 | * state not saved in between {@code onStart} and {@code onStop} callbacks inclusively. |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 1760 | */ |
Sergey Vasilinets | 0de0eca | 2018-08-23 19:28:57 -0700 | [diff] [blame] | 1761 | @Deprecated |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 1762 | public void onStateNotSaved() { |
| 1763 | } |
| 1764 | |
| 1765 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1766 | * Called after {@link #onRestoreInstanceState}, {@link #onRestart}, or |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 1767 | * {@link #onPause}, for your activity to start interacting with the user. This is an indicator |
| 1768 | * that the activity became active and ready to receive input. It is on top of an activity stack |
| 1769 | * and visible to user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1770 | * |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 1771 | * <p>On platform versions prior to {@link android.os.Build.VERSION_CODES#Q} this is also a good |
| 1772 | * place to try to open exclusive-access devices or to get access to singleton resources. |
| 1773 | * Starting with {@link android.os.Build.VERSION_CODES#Q} there can be multiple resumed |
| 1774 | * activities in the system simultaneously, so {@link #onTopResumedActivityChanged(boolean)} |
| 1775 | * should be used for that purpose instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1776 | * |
| 1777 | * <p><em>Derived classes must call through to the super class's |
| 1778 | * implementation of this method. If they do not, an exception will be |
| 1779 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1780 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1781 | * @see #onRestoreInstanceState |
| 1782 | * @see #onRestart |
| 1783 | * @see #onPostResume |
| 1784 | * @see #onPause |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 1785 | * @see #onTopResumedActivityChanged(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1786 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1787 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1788 | protected void onResume() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1789 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onResume " + this); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 1790 | dispatchActivityResumed(); |
Sunny Goyal | 64643f6 | 2019-01-31 15:15:33 -0800 | [diff] [blame] | 1791 | mActivityTransitionState.onResume(this); |
Felipe Leme | ce40498 | 2018-09-17 09:46:13 -0700 | [diff] [blame] | 1792 | enableAutofillCompatibilityIfNeeded(); |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 1793 | if (mAutoFillResetNeeded) { |
| 1794 | if (!mAutoFillIgnoreFirstResumePause) { |
| 1795 | View focus = getCurrentFocus(); |
Ben Lin | e55cd3e | 2018-12-07 20:26:37 +0000 | [diff] [blame] | 1796 | if (focus != null && focus.canNotifyAutofillEnterExitEvent()) { |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 1797 | // TODO: in Activity killed/recreated case, i.e. SessionLifecycleTest# |
| 1798 | // testDatasetVisibleWhileAutofilledAppIsLifecycled: the View's initial |
| 1799 | // window visibility after recreation is INVISIBLE in onResume() and next frame |
| 1800 | // ViewRootImpl.performTraversals() changes window visibility to VISIBLE. |
| 1801 | // So we cannot call View.notifyEnterOrExited() which will do nothing |
| 1802 | // when View.isVisibleToUser() is false. |
| 1803 | getAutofillManager().notifyViewEntered(focus); |
| 1804 | } |
| 1805 | } |
| 1806 | } |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 1807 | |
| 1808 | notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_RESUME); |
| 1809 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1810 | mCalled = true; |
| 1811 | } |
| 1812 | |
| 1813 | /** |
| 1814 | * Called when activity resume is complete (after {@link #onResume} has |
| 1815 | * been called). Applications will generally not implement this method; |
| 1816 | * it is intended for system classes to do final setup after application |
| 1817 | * resume code has run. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1818 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1819 | * <p><em>Derived classes must call through to the super class's |
| 1820 | * implementation of this method. If they do not, an exception will be |
| 1821 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1822 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1823 | * @see #onResume |
| 1824 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1825 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1826 | protected void onPostResume() { |
| 1827 | final Window win = getWindow(); |
| 1828 | if (win != null) win.makeActive(); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 1829 | if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1830 | mCalled = true; |
| 1831 | } |
| 1832 | |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 1833 | /** |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 1834 | * Called when activity gets or loses the top resumed position in the system. |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 1835 | * |
| 1836 | * <p>Starting with {@link android.os.Build.VERSION_CODES#Q} multiple activities can be resumed |
| 1837 | * at the same time in multi-window and multi-display modes. This callback should be used |
| 1838 | * instead of {@link #onResume()} as an indication that the activity can try to open |
| 1839 | * exclusive-access devices like camera.</p> |
| 1840 | * |
| 1841 | * <p>It will always be delivered after the activity was resumed and before it is paused. In |
| 1842 | * some cases it might be skipped and activity can go straight from {@link #onResume()} to |
| 1843 | * {@link #onPause()} without receiving the top resumed state.</p> |
| 1844 | * |
| 1845 | * @param isTopResumedActivity {@code true} if it's the topmost resumed activity in the system, |
| 1846 | * {@code false} otherwise. A call with this as {@code true} will |
| 1847 | * always be followed by another one with {@code false}. |
| 1848 | * |
| 1849 | * @see #onResume() |
| 1850 | * @see #onPause() |
| 1851 | * @see #onWindowFocusChanged(boolean) |
| 1852 | */ |
| 1853 | public void onTopResumedActivityChanged(boolean isTopResumedActivity) { |
| 1854 | } |
| 1855 | |
Andrii Kulian | 8602401 | 2019-04-18 19:41:23 -0700 | [diff] [blame] | 1856 | final void performTopResumedActivityChanged(boolean isTopResumedActivity, String reason) { |
| 1857 | onTopResumedActivityChanged(isTopResumedActivity); |
| 1858 | |
| 1859 | writeEventLog(isTopResumedActivity |
| 1860 | ? LOG_AM_ON_TOP_RESUMED_GAINED_CALLED : LOG_AM_ON_TOP_RESUMED_LOST_CALLED, reason); |
| 1861 | } |
| 1862 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1863 | void setVoiceInteractor(IVoiceInteractor voiceInteractor) { |
Amith Yamasani | eeed06c | 2016-05-03 15:07:03 -0700 | [diff] [blame] | 1864 | if (mVoiceInteractor != null) { |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 1865 | final Request[] requests = mVoiceInteractor.getActiveRequests(); |
| 1866 | if (requests != null) { |
| 1867 | for (Request activeRequest : mVoiceInteractor.getActiveRequests()) { |
| 1868 | activeRequest.cancel(); |
| 1869 | activeRequest.clear(); |
| 1870 | } |
Amith Yamasani | eeed06c | 2016-05-03 15:07:03 -0700 | [diff] [blame] | 1871 | } |
| 1872 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1873 | if (voiceInteractor == null) { |
| 1874 | mVoiceInteractor = null; |
| 1875 | } else { |
| 1876 | mVoiceInteractor = new VoiceInteractor(voiceInteractor, this, this, |
| 1877 | Looper.myLooper()); |
| 1878 | } |
| 1879 | } |
| 1880 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1881 | /** |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1882 | * Gets the next autofill ID. |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1883 | * |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1884 | * <p>All IDs will be bigger than {@link View#LAST_APP_AUTOFILL_ID}. All IDs returned |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1885 | * will be unique. |
| 1886 | * |
| 1887 | * @return A ID that is unique in the activity |
| 1888 | * |
| 1889 | * {@hide} |
| 1890 | */ |
Felipe Leme | 42b9793 | 2018-02-20 13:04:31 -0800 | [diff] [blame] | 1891 | @Override |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1892 | public int getNextAutofillId() { |
| 1893 | if (mLastAutofillId == Integer.MAX_VALUE - 1) { |
| 1894 | mLastAutofillId = View.LAST_APP_AUTOFILL_ID; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1897 | mLastAutofillId++; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1898 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1899 | return mLastAutofillId; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | /** |
Felipe Leme | 42b9793 | 2018-02-20 13:04:31 -0800 | [diff] [blame] | 1903 | * @hide |
| 1904 | */ |
| 1905 | @Override |
| 1906 | public AutofillId autofillClientGetNextAutofillId() { |
Felipe Leme | 305fd40 | 2018-09-11 18:20:42 +0000 | [diff] [blame] | 1907 | return new AutofillId(getNextAutofillId()); |
Felipe Leme | 42b9793 | 2018-02-20 13:04:31 -0800 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | /** |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1911 | * Check whether this activity is running as part of a voice interaction with the user. |
| 1912 | * If true, it should perform its interaction with the user through the |
| 1913 | * {@link VoiceInteractor} returned by {@link #getVoiceInteractor}. |
| 1914 | */ |
| 1915 | public boolean isVoiceInteraction() { |
| 1916 | return mVoiceInteractor != null; |
| 1917 | } |
| 1918 | |
| 1919 | /** |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 1920 | * Like {@link #isVoiceInteraction}, but only returns true if this is also the root |
| 1921 | * of a voice interaction. That is, returns true if this activity was directly |
| 1922 | * started by the voice interaction service as the initiation of a voice interaction. |
| 1923 | * Otherwise, for example if it was started by another activity while under voice |
| 1924 | * interaction, returns false. |
| 1925 | */ |
| 1926 | public boolean isVoiceInteractionRoot() { |
| 1927 | try { |
| 1928 | return mVoiceInteractor != null |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1929 | && ActivityTaskManager.getService().isRootVoiceInteraction(mToken); |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 1930 | } catch (RemoteException e) { |
| 1931 | } |
| 1932 | return false; |
| 1933 | } |
| 1934 | |
| 1935 | /** |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1936 | * Retrieve the active {@link VoiceInteractor} that the user is going through to |
| 1937 | * interact with this activity. |
| 1938 | */ |
| 1939 | public VoiceInteractor getVoiceInteractor() { |
| 1940 | return mVoiceInteractor; |
| 1941 | } |
| 1942 | |
| 1943 | /** |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1944 | * Queries whether the currently enabled voice interaction service supports returning |
| 1945 | * a voice interactor for use by the activity. This is valid only for the duration of the |
| 1946 | * activity. |
| 1947 | * |
| 1948 | * @return whether the current voice interaction service supports local voice interaction |
| 1949 | */ |
| 1950 | public boolean isLocalVoiceInteractionSupported() { |
| 1951 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1952 | return ActivityTaskManager.getService().supportsLocalVoiceInteraction(); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1953 | } catch (RemoteException re) { |
| 1954 | } |
| 1955 | return false; |
| 1956 | } |
| 1957 | |
| 1958 | /** |
| 1959 | * Starts a local voice interaction session. When ready, |
| 1960 | * {@link #onLocalVoiceInteractionStarted()} is called. You can pass a bundle of private options |
| 1961 | * to the registered voice interaction service. |
| 1962 | * @param privateOptions a Bundle of private arguments to the current voice interaction service |
| 1963 | */ |
| 1964 | public void startLocalVoiceInteraction(Bundle privateOptions) { |
| 1965 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1966 | ActivityTaskManager.getService().startLocalVoiceInteraction(mToken, privateOptions); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1967 | } catch (RemoteException re) { |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | /** |
| 1972 | * Callback to indicate that {@link #startLocalVoiceInteraction(Bundle)} has resulted in a |
| 1973 | * voice interaction session being started. You can now retrieve a voice interactor using |
| 1974 | * {@link #getVoiceInteractor()}. |
| 1975 | */ |
| 1976 | public void onLocalVoiceInteractionStarted() { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | /** |
Amith Yamasani | d8d967e | 2016-04-08 09:57:01 -0700 | [diff] [blame] | 1980 | * Callback to indicate that the local voice interaction has stopped either |
| 1981 | * because it was requested through a call to {@link #stopLocalVoiceInteraction()} |
| 1982 | * or because it was canceled by the user. The previously acquired {@link VoiceInteractor} |
| 1983 | * is no longer valid after this. |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1984 | */ |
| 1985 | public void onLocalVoiceInteractionStopped() { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | /** |
| 1989 | * Request to terminate the current voice interaction that was previously started |
Amith Yamasani | d8d967e | 2016-04-08 09:57:01 -0700 | [diff] [blame] | 1990 | * using {@link #startLocalVoiceInteraction(Bundle)}. When the interaction is |
| 1991 | * terminated, {@link #onLocalVoiceInteractionStopped()} will be called. |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1992 | */ |
| 1993 | public void stopLocalVoiceInteraction() { |
| 1994 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1995 | ActivityTaskManager.getService().stopLocalVoiceInteraction(mToken); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1996 | } catch (RemoteException re) { |
| 1997 | } |
| 1998 | } |
| 1999 | |
| 2000 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2001 | * This is called for activities that set launchMode to "singleTop" in |
| 2002 | * their package, or if a client used the {@link Intent#FLAG_ACTIVITY_SINGLE_TOP} |
| 2003 | * flag when calling {@link #startActivity}. In either case, when the |
| 2004 | * activity is re-launched while at the top of the activity stack instead |
| 2005 | * of a new instance of the activity being started, onNewIntent() will be |
| 2006 | * called on the existing instance with the Intent that was used to |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2007 | * re-launch it. |
| 2008 | * |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 2009 | * <p>An activity can never receive a new intent in the resumed state. You can count on |
| 2010 | * {@link #onResume} being called after this method, though not necessarily immediately after |
| 2011 | * the completion this callback. If the activity was resumed, it will be paused and new intent |
| 2012 | * will be delivered, followed by {@link #onResume}. If the activity wasn't in the resumed |
| 2013 | * state, then new intent can be delivered immediately, with {@link #onResume()} called |
| 2014 | * sometime later when activity becomes active again. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2015 | * |
| 2016 | * <p>Note that {@link #getIntent} still returns the original Intent. You |
| 2017 | * can use {@link #setIntent} to update it to this new Intent. |
| 2018 | * |
| 2019 | * @param intent The new intent that was started for the activity. |
| 2020 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2021 | * @see #getIntent |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2022 | * @see #setIntent |
| 2023 | * @see #onResume |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2024 | */ |
| 2025 | protected void onNewIntent(Intent intent) { |
| 2026 | } |
| 2027 | |
| 2028 | /** |
| 2029 | * The hook for {@link ActivityThread} to save the state of this activity. |
| 2030 | * |
| 2031 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} |
| 2032 | * and {@link #saveManagedDialogs(android.os.Bundle)}. |
| 2033 | * |
| 2034 | * @param outState The bundle to save the state to. |
| 2035 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 2036 | final void performSaveInstanceState(@NonNull Bundle outState) { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2037 | dispatchActivityPreSaveInstanceState(outState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2038 | onSaveInstanceState(outState); |
| 2039 | saveManagedDialogs(outState); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 2040 | mActivityTransitionState.saveState(outState); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 2041 | storeHasCurrentPermissionRequest(outState); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2042 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onSaveInstanceState " + this + ": " + outState); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2043 | dispatchActivityPostSaveInstanceState(outState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2047 | * The hook for {@link ActivityThread} to save the state of this activity. |
| 2048 | * |
| 2049 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} |
| 2050 | * and {@link #saveManagedDialogs(android.os.Bundle)}. |
| 2051 | * |
| 2052 | * @param outState The bundle to save the state to. |
| 2053 | * @param outPersistentState The bundle to save persistent state to. |
| 2054 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 2055 | final void performSaveInstanceState(@NonNull Bundle outState, |
| 2056 | @NonNull PersistableBundle outPersistentState) { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2057 | dispatchActivityPreSaveInstanceState(outState); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2058 | onSaveInstanceState(outState, outPersistentState); |
| 2059 | saveManagedDialogs(outState); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 2060 | storeHasCurrentPermissionRequest(outState); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2061 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onSaveInstanceState " + this + ": " + outState + |
| 2062 | ", " + outPersistentState); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2063 | dispatchActivityPostSaveInstanceState(outState); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2067 | * Called to retrieve per-instance state from an activity before being killed |
| 2068 | * so that the state can be restored in {@link #onCreate} or |
| 2069 | * {@link #onRestoreInstanceState} (the {@link Bundle} populated by this method |
| 2070 | * will be passed to both). |
| 2071 | * |
| 2072 | * <p>This method is called before an activity may be killed so that when it |
| 2073 | * comes back some time in the future it can restore its state. For example, |
| 2074 | * if activity B is launched in front of activity A, and at some point activity |
| 2075 | * A is killed to reclaim resources, activity A will have a chance to save the |
| 2076 | * current state of its user interface via this method so that when the user |
| 2077 | * returns to activity A, the state of the user interface can be restored |
| 2078 | * via {@link #onCreate} or {@link #onRestoreInstanceState}. |
| 2079 | * |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 2080 | * <p>Do not confuse this method with activity lifecycle callbacks such as {@link #onPause}, |
| 2081 | * which is always called when the user no longer actively interacts with an activity, or |
| 2082 | * {@link #onStop} which is called when activity becomes invisible. One example of when |
| 2083 | * {@link #onPause} and {@link #onStop} is called and not this method is when a user navigates |
| 2084 | * back from activity B to activity A: there is no need to call {@link #onSaveInstanceState} |
| 2085 | * on B because that particular instance will never be restored, |
| 2086 | * so the system avoids calling it. An example when {@link #onPause} is called and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2087 | * not {@link #onSaveInstanceState} is when activity B is launched in front of activity A: |
| 2088 | * the system may avoid calling {@link #onSaveInstanceState} on activity A if it isn't |
| 2089 | * killed during the lifetime of B since the state of the user interface of |
| 2090 | * A will stay intact. |
| 2091 | * |
| 2092 | * <p>The default implementation takes care of most of the UI per-instance |
| 2093 | * state for you by calling {@link android.view.View#onSaveInstanceState()} on each |
| 2094 | * view in the hierarchy that has an id, and by saving the id of the currently |
| 2095 | * focused view (all of which is restored by the default implementation of |
| 2096 | * {@link #onRestoreInstanceState}). If you override this method to save additional |
| 2097 | * information not captured by each individual view, you will likely want to |
| 2098 | * call through to the default implementation, otherwise be prepared to save |
| 2099 | * all of the state of each view yourself. |
| 2100 | * |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 2101 | * <p>If called, this method will occur after {@link #onStop} for applications |
| 2102 | * targeting platforms starting with {@link android.os.Build.VERSION_CODES#P}. |
| 2103 | * For applications targeting earlier platform versions this method will occur |
| 2104 | * before {@link #onStop} and there are no guarantees about whether it will |
| 2105 | * occur before or after {@link #onPause}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2106 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | * @param outState Bundle in which to place your saved state. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2108 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2109 | * @see #onCreate |
| 2110 | * @see #onRestoreInstanceState |
| 2111 | * @see #onPause |
| 2112 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 2113 | protected void onSaveInstanceState(@NonNull Bundle outState) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2114 | outState.putBundle(WINDOW_HIERARCHY_TAG, mWindow.saveHierarchyState()); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 2115 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 2116 | outState.putInt(LAST_AUTOFILL_ID, mLastAutofillId); |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2117 | Parcelable p = mFragments.saveAllState(); |
| 2118 | if (p != null) { |
| 2119 | outState.putParcelable(FRAGMENTS_TAG, p); |
| 2120 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 2121 | if (mAutoFillResetNeeded) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 2122 | outState.putBoolean(AUTOFILL_RESET_NEEDED, true); |
| 2123 | getAutofillManager().onSaveInstanceState(outState); |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 2124 | } |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2125 | dispatchActivitySaveInstanceState(outState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2129 | * This is the same as {@link #onSaveInstanceState} but is called for activities |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 2130 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 2131 | * <code>persistAcrossReboots</code>. The {@link android.os.PersistableBundle} passed |
| 2132 | * in will be saved and presented in {@link #onCreate(Bundle, PersistableBundle)} |
| 2133 | * the first time that this activity is restarted following the next device reboot. |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2134 | * |
| 2135 | * @param outState Bundle in which to place your saved state. |
| 2136 | * @param outPersistentState State which will be saved across reboots. |
| 2137 | * |
| 2138 | * @see #onSaveInstanceState(Bundle) |
| 2139 | * @see #onCreate |
| 2140 | * @see #onRestoreInstanceState(Bundle, PersistableBundle) |
| 2141 | * @see #onPause |
| 2142 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 2143 | public void onSaveInstanceState(@NonNull Bundle outState, |
| 2144 | @NonNull PersistableBundle outPersistentState) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2145 | onSaveInstanceState(outState); |
| 2146 | } |
| 2147 | |
| 2148 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2149 | * Save the state of any managed dialogs. |
| 2150 | * |
| 2151 | * @param outState place to store the saved state. |
| 2152 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2153 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2154 | private void saveManagedDialogs(Bundle outState) { |
| 2155 | if (mManagedDialogs == null) { |
| 2156 | return; |
| 2157 | } |
| 2158 | |
| 2159 | final int numDialogs = mManagedDialogs.size(); |
| 2160 | if (numDialogs == 0) { |
| 2161 | return; |
| 2162 | } |
| 2163 | |
| 2164 | Bundle dialogState = new Bundle(); |
| 2165 | |
| 2166 | int[] ids = new int[mManagedDialogs.size()]; |
| 2167 | |
| 2168 | // save each dialog's bundle, gather the ids |
| 2169 | for (int i = 0; i < numDialogs; i++) { |
| 2170 | final int key = mManagedDialogs.keyAt(i); |
| 2171 | ids[i] = key; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2172 | final ManagedDialog md = mManagedDialogs.valueAt(i); |
| 2173 | dialogState.putBundle(savedDialogKeyFor(key), md.mDialog.onSaveInstanceState()); |
| 2174 | if (md.mArgs != null) { |
| 2175 | dialogState.putBundle(savedDialogArgsKeyFor(key), md.mArgs); |
| 2176 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | dialogState.putIntArray(SAVED_DIALOG_IDS_KEY, ids); |
| 2180 | outState.putBundle(SAVED_DIALOGS_TAG, dialogState); |
| 2181 | } |
| 2182 | |
| 2183 | |
| 2184 | /** |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 2185 | * Called as part of the activity lifecycle when the user no longer actively interacts with the |
| 2186 | * activity, but it is still visible on screen. The counterpart to {@link #onResume}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2187 | * |
| 2188 | * <p>When activity B is launched in front of activity A, this callback will |
| 2189 | * be invoked on A. B will not be created until A's {@link #onPause} returns, |
| 2190 | * so be sure to not do anything lengthy here. |
| 2191 | * |
| 2192 | * <p>This callback is mostly used for saving any persistent state the |
| 2193 | * activity is editing, to present a "edit in place" model to the user and |
| 2194 | * making sure nothing is lost if there are not enough resources to start |
| 2195 | * the new activity without first killing this one. This is also a good |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 2196 | * place to stop things that consume a noticeable amount of CPU in order to |
| 2197 | * make the switch to the next activity as fast as possible. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2198 | * |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 2199 | * <p>On platform versions prior to {@link android.os.Build.VERSION_CODES#Q} this is also a good |
| 2200 | * place to try to close exclusive-access devices or to release access to singleton resources. |
| 2201 | * Starting with {@link android.os.Build.VERSION_CODES#Q} there can be multiple resumed |
| 2202 | * activities in the system at the same time, so {@link #onTopResumedActivityChanged(boolean)} |
| 2203 | * should be used for that purpose instead. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2204 | * |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 2205 | * <p>If an activity is launched on top, after receiving this call you will usually receive a |
| 2206 | * following call to {@link #onStop} (after the next activity has been resumed and displayed |
| 2207 | * above). However in some cases there will be a direct call back to {@link #onResume} without |
| 2208 | * going through the stopped state. An activity can also rest in paused state in some cases when |
| 2209 | * in multi-window mode, still visible to user. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2210 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2211 | * <p><em>Derived classes must call through to the super class's |
| 2212 | * implementation of this method. If they do not, an exception will be |
| 2213 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2214 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2215 | * @see #onResume |
| 2216 | * @see #onSaveInstanceState |
| 2217 | * @see #onStop |
| 2218 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 2219 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2220 | protected void onPause() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2221 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onPause " + this); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2222 | dispatchActivityPaused(); |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 2223 | if (mAutoFillResetNeeded) { |
| 2224 | if (!mAutoFillIgnoreFirstResumePause) { |
| 2225 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "autofill notifyViewExited " + this); |
| 2226 | View focus = getCurrentFocus(); |
| 2227 | if (focus != null && focus.canNotifyAutofillEnterExitEvent()) { |
| 2228 | getAutofillManager().notifyViewExited(focus); |
| 2229 | } |
| 2230 | } else { |
| 2231 | // reset after first pause() |
| 2232 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "autofill got first pause " + this); |
| 2233 | mAutoFillIgnoreFirstResumePause = false; |
| 2234 | } |
| 2235 | } |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 2236 | |
| 2237 | notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_PAUSE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2238 | mCalled = true; |
| 2239 | } |
| 2240 | |
| 2241 | /** |
| 2242 | * Called as part of the activity lifecycle when an activity is about to go |
| 2243 | * into the background as the result of user choice. For example, when the |
| 2244 | * user presses the Home key, {@link #onUserLeaveHint} will be called, but |
| 2245 | * when an incoming phone call causes the in-call Activity to be automatically |
| 2246 | * brought to the foreground, {@link #onUserLeaveHint} will not be called on |
| 2247 | * the activity being interrupted. In cases when it is invoked, this method |
| 2248 | * is called right before the activity's {@link #onPause} callback. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2249 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2250 | * <p>This callback and {@link #onUserInteraction} are intended to help |
| 2251 | * activities manage status bar notifications intelligently; specifically, |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 2252 | * for helping activities determine the proper time to cancel a notification. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2253 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2254 | * @see #onUserInteraction() |
Louis Chang | c2e193a | 2019-01-09 15:33:57 +0800 | [diff] [blame] | 2255 | * @see android.content.Intent#FLAG_ACTIVITY_NO_USER_ACTION |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2256 | */ |
| 2257 | protected void onUserLeaveHint() { |
| 2258 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2260 | /** |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 2261 | * @deprecated Method doesn't do anything and will be removed in the future. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2262 | */ |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 2263 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2264 | public boolean onCreateThumbnail(Bitmap outBitmap, Canvas canvas) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 2265 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | /** |
| 2269 | * Generate a new description for this activity. This method is called |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 2270 | * before stopping the activity and can, if desired, return some textual |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2271 | * description of its current state to be displayed to the user. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2272 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2273 | * <p>The default implementation returns null, which will cause you to |
| 2274 | * inherit the description from the previous activity. If all activities |
| 2275 | * return null, generally the label of the top activity will be used as the |
| 2276 | * description. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2277 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2278 | * @return A description of what the user is doing. It should be short and |
| 2279 | * sweet (only a few words). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2280 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2281 | * @see #onSaveInstanceState |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 2282 | * @see #onStop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2283 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2284 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2285 | public CharSequence onCreateDescription() { |
| 2286 | return null; |
| 2287 | } |
| 2288 | |
| 2289 | /** |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2290 | * This is called when the user is requesting an assist, to build a full |
| 2291 | * {@link Intent#ACTION_ASSIST} Intent with all of the context of the current |
| 2292 | * application. You can override this method to place into the bundle anything |
| 2293 | * you would like to appear in the {@link Intent#EXTRA_ASSIST_CONTEXT} part |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2294 | * of the assist Intent. |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2295 | * |
| 2296 | * <p>This function will be called after any global assist callbacks that had |
Ying Wang | 4e0eb22 | 2013-04-18 20:39:48 -0700 | [diff] [blame] | 2297 | * been registered with {@link Application#registerOnProvideAssistDataListener |
| 2298 | * Application.registerOnProvideAssistDataListener}. |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2299 | */ |
| 2300 | public void onProvideAssistData(Bundle data) { |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | /** |
| 2304 | * This is called when the user is requesting an assist, to provide references |
| 2305 | * to content related to the current activity. Before being called, the |
| 2306 | * {@code outContent} Intent is filled with the base Intent of the activity (the Intent |
| 2307 | * returned by {@link #getIntent()}). The Intent's extras are stripped of any types |
| 2308 | * that are not valid for {@link PersistableBundle} or non-framework Parcelables, and |
| 2309 | * the flags {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION} and |
| 2310 | * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION} are cleared from the Intent. |
| 2311 | * |
| 2312 | * <p>Custom implementation may adjust the content intent to better reflect the top-level |
| 2313 | * context of the activity, and fill in its ClipData with additional content of |
| 2314 | * interest that the user is currently viewing. For example, an image gallery application |
| 2315 | * that has launched in to an activity allowing the user to swipe through pictures should |
| 2316 | * modify the intent to reference the current image they are looking it; such an |
| 2317 | * application when showing a list of pictures should add a ClipData that has |
| 2318 | * references to all of the pictures currently visible on screen.</p> |
| 2319 | * |
| 2320 | * @param outContent The assist content to return. |
| 2321 | */ |
| 2322 | public void onProvideAssistContent(AssistContent outContent) { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2323 | } |
| 2324 | |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 2325 | /** |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 2326 | * Returns the list of direct actions supported by the app. |
| 2327 | * |
| 2328 | * <p>You should return the list of actions that could be executed in the |
| 2329 | * current context, which is in the current state of the app. If the actions |
| 2330 | * that could be executed by the app changes you should report that via |
| 2331 | * calling {@link VoiceInteractor#notifyDirectActionsChanged()}. |
| 2332 | * |
| 2333 | * <p>To get the voice interactor you need to call {@link #getVoiceInteractor()} |
Andrew Solovay | 7ad2170 | 2019-06-06 15:10:43 -0700 | [diff] [blame] | 2334 | * which would return non <code>null</code> only if there is an ongoing voice |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 2335 | * interaction session. You an also detect when the voice interactor is no |
| 2336 | * longer valid because the voice interaction session that is backing is finished |
| 2337 | * by calling {@link VoiceInteractor#registerOnDestroyedCallback(Executor, Runnable)}. |
| 2338 | * |
| 2339 | * <p>This method will be called only after {@link #onStart()} is being called and |
| 2340 | * before {@link #onStop()} is being called. |
| 2341 | * |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 2342 | * <p>You should pass to the callback the currently supported direct actions which |
Andrew Solovay | 7ad2170 | 2019-06-06 15:10:43 -0700 | [diff] [blame] | 2343 | * cannot be <code>null</code> or contain <code>null</code> elements. |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 2344 | * |
| 2345 | * <p>You should return the action list as soon as possible to ensure the consumer, |
| 2346 | * for example the assistant, is as responsive as possible which would improve user |
| 2347 | * experience of your app. |
| 2348 | * |
| 2349 | * @param cancellationSignal A signal to cancel the operation in progress. |
| 2350 | * @param callback The callback to send the action list. The actions list cannot |
Svet Ganov | 07e5fb2 | 2019-04-30 11:07:09 -0700 | [diff] [blame] | 2351 | * contain <code>null</code> elements. You can call this on any thread. |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 2352 | */ |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 2353 | public void onGetDirectActions(@NonNull CancellationSignal cancellationSignal, |
| 2354 | @NonNull Consumer<List<DirectAction>> callback) { |
| 2355 | callback.accept(Collections.emptyList()); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | /** |
| 2359 | * This is called to perform an action previously defined by the app. |
| 2360 | * Apps also have access to {@link #getVoiceInteractor()} to follow up on the action. |
| 2361 | * |
Svet Ganov | 07e5fb2 | 2019-04-30 11:07:09 -0700 | [diff] [blame] | 2362 | * @param actionId The ID for the action you previously reported via |
| 2363 | * {@link #onGetDirectActions(CancellationSignal, Consumer)}. |
| 2364 | * @param arguments Any additional arguments provided by the caller that are |
| 2365 | * specific to the given action. |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 2366 | * @param cancellationSignal A signal to cancel the operation in progress. |
Svet Ganov | 07e5fb2 | 2019-04-30 11:07:09 -0700 | [diff] [blame] | 2367 | * @param resultListener The callback to provide the result back to the caller. |
| 2368 | * You can call this on any thread. The result bundle is action specific. |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 2369 | * |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 2370 | * @see #onGetDirectActions(CancellationSignal, Consumer) |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 2371 | */ |
| 2372 | public void onPerformDirectAction(@NonNull String actionId, |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 2373 | @NonNull Bundle arguments, @NonNull CancellationSignal cancellationSignal, |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 2374 | @NonNull Consumer<Bundle> resultListener) { } |
| 2375 | |
| 2376 | /** |
Clara Bayarri | ab591ba | 2016-05-16 17:48:16 +0100 | [diff] [blame] | 2377 | * Request the Keyboard Shortcuts screen to show up. This will trigger |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 2378 | * {@link #onProvideKeyboardShortcuts} to retrieve the shortcuts for the foreground activity. |
| 2379 | */ |
Clara Bayarri | ac6f034 | 2016-05-16 14:15:14 +0100 | [diff] [blame] | 2380 | public final void requestShowKeyboardShortcuts() { |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 2381 | Intent intent = new Intent(Intent.ACTION_SHOW_KEYBOARD_SHORTCUTS); |
Andrei Stingaceanu | a3d2693 | 2016-07-15 11:12:20 +0100 | [diff] [blame] | 2382 | intent.setPackage(KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME); |
Nicholas Sauer | 28348ed74 | 2019-02-15 11:58:32 -0800 | [diff] [blame] | 2383 | sendBroadcastAsUser(intent, Process.myUserHandle()); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | /** |
| 2387 | * Dismiss the Keyboard Shortcuts screen. |
| 2388 | */ |
| 2389 | public final void dismissKeyboardShortcutsHelper() { |
| 2390 | Intent intent = new Intent(Intent.ACTION_DISMISS_KEYBOARD_SHORTCUTS); |
Andrei Stingaceanu | a3d2693 | 2016-07-15 11:12:20 +0100 | [diff] [blame] | 2391 | intent.setPackage(KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME); |
Nicholas Sauer | 28348ed74 | 2019-02-15 11:58:32 -0800 | [diff] [blame] | 2392 | sendBroadcastAsUser(intent, Process.myUserHandle()); |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 2393 | } |
| 2394 | |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 2395 | @Override |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 2396 | public void onProvideKeyboardShortcuts( |
| 2397 | List<KeyboardShortcutGroup> data, Menu menu, int deviceId) { |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 2398 | if (menu == null) { |
| 2399 | return; |
| 2400 | } |
| 2401 | KeyboardShortcutGroup group = null; |
| 2402 | int menuSize = menu.size(); |
| 2403 | for (int i = 0; i < menuSize; ++i) { |
| 2404 | final MenuItem item = menu.getItem(i); |
| 2405 | final CharSequence title = item.getTitle(); |
| 2406 | final char alphaShortcut = item.getAlphabeticShortcut(); |
Peeyush Agarwal | e631e32 | 2016-10-19 11:41:42 +0100 | [diff] [blame] | 2407 | final int alphaModifiers = item.getAlphabeticModifiers(); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 2408 | if (title != null && alphaShortcut != MIN_VALUE) { |
| 2409 | if (group == null) { |
Clara Bayarri | ada88b3 | 2016-02-02 18:08:01 +0000 | [diff] [blame] | 2410 | final int resource = mApplication.getApplicationInfo().labelRes; |
| 2411 | group = new KeyboardShortcutGroup(resource != 0 ? getString(resource) : null); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 2412 | } |
| 2413 | group.addItem(new KeyboardShortcutInfo( |
Peeyush Agarwal | e631e32 | 2016-10-19 11:41:42 +0100 | [diff] [blame] | 2414 | title, alphaShortcut, alphaModifiers)); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 2415 | } |
| 2416 | } |
| 2417 | if (group != null) { |
| 2418 | data.add(group); |
| 2419 | } |
| 2420 | } |
| 2421 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2422 | /** |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 2423 | * Ask to have the current assistant shown to the user. This only works if the calling |
| 2424 | * activity is the current foreground activity. It is the same as calling |
| 2425 | * {@link android.service.voice.VoiceInteractionService#showSession |
| 2426 | * VoiceInteractionService.showSession} and requesting all of the possible context. |
| 2427 | * The receiver will always see |
| 2428 | * {@link android.service.voice.VoiceInteractionSession#SHOW_SOURCE_APPLICATION} set. |
| 2429 | * @return Returns true if the assistant was successfully invoked, else false. For example |
| 2430 | * false will be returned if the caller is not the current top activity. |
| 2431 | */ |
| 2432 | public boolean showAssist(Bundle args) { |
| 2433 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2434 | return ActivityTaskManager.getService().showAssistFromActivity(mToken, args); |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 2435 | } catch (RemoteException e) { |
| 2436 | } |
| 2437 | return false; |
| 2438 | } |
| 2439 | |
| 2440 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2441 | * Called when you are no longer visible to the user. You will next |
| 2442 | * receive either {@link #onRestart}, {@link #onDestroy}, or nothing, |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 2443 | * depending on later user activity. This is a good place to stop |
| 2444 | * refreshing UI, running animations and other visual things. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2445 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2446 | * <p><em>Derived classes must call through to the super class's |
| 2447 | * implementation of this method. If they do not, an exception will be |
| 2448 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2449 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | * @see #onRestart |
| 2451 | * @see #onResume |
| 2452 | * @see #onSaveInstanceState |
| 2453 | * @see #onDestroy |
| 2454 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 2455 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2456 | protected void onStop() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2457 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onStop " + this); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 2458 | if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(false); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 2459 | mActivityTransitionState.onStop(); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2460 | dispatchActivityStopped(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2461 | mTranslucentCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2462 | mCalled = true; |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 2463 | |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 2464 | if (mAutoFillResetNeeded) { |
| 2465 | getAutofillManager().onInvisibleForAutofill(); |
| 2466 | } |
| 2467 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 2468 | if (isFinishing()) { |
| 2469 | if (mAutoFillResetNeeded) { |
Felipe Leme | 5b32ebe | 2018-02-15 12:52:19 -0800 | [diff] [blame] | 2470 | getAutofillManager().onActivityFinishing(); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 2471 | } else if (mIntent != null |
| 2472 | && mIntent.hasExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN)) { |
| 2473 | // Activity was launched when user tapped a link in the Autofill Save UI - since |
| 2474 | // user launched another activity, the Save UI should not be restored when this |
| 2475 | // activity is finished. |
| 2476 | getAutofillManager().onPendingSaveUi(AutofillManager.PENDING_UI_OPERATION_CANCEL, |
| 2477 | mIntent.getIBinderExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN)); |
| 2478 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 2479 | } |
chaviw | feb2e1e | 2018-12-19 17:24:11 -0800 | [diff] [blame] | 2480 | mEnterAnimationComplete = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | /** |
| 2484 | * Perform any final cleanup before an activity is destroyed. This can |
| 2485 | * happen either because the activity is finishing (someone called |
kopriva | fdb0bff | 2018-09-29 15:22:41 -0700 | [diff] [blame] | 2486 | * {@link #finish} on it), or because the system is temporarily destroying |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2487 | * this instance of the activity to save space. You can distinguish |
| 2488 | * between these two scenarios with the {@link #isFinishing} method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2489 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | * <p><em>Note: do not count on this method being called as a place for |
| 2491 | * saving data! For example, if an activity is editing data in a content |
| 2492 | * provider, those edits should be committed in either {@link #onPause} or |
| 2493 | * {@link #onSaveInstanceState}, not here.</em> This method is usually implemented to |
| 2494 | * free resources like threads that are associated with an activity, so |
| 2495 | * that a destroyed activity does not leave such things around while the |
| 2496 | * rest of its application is still running. There are situations where |
| 2497 | * the system will simply kill the activity's hosting process without |
| 2498 | * calling this method (or any others) in it, so it should not be used to |
| 2499 | * do things that are intended to remain around after the process goes |
| 2500 | * away. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2501 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | * <p><em>Derived classes must call through to the super class's |
| 2503 | * implementation of this method. If they do not, an exception will be |
| 2504 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2505 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2506 | * @see #onPause |
| 2507 | * @see #onStop |
| 2508 | * @see #finish |
| 2509 | * @see #isFinishing |
| 2510 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 2511 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2512 | protected void onDestroy() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2513 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onDestroy " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2514 | mCalled = true; |
| 2515 | |
| 2516 | // dismiss any dialogs we are managing. |
| 2517 | if (mManagedDialogs != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2518 | final int numDialogs = mManagedDialogs.size(); |
| 2519 | for (int i = 0; i < numDialogs; i++) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2520 | final ManagedDialog md = mManagedDialogs.valueAt(i); |
| 2521 | if (md.mDialog.isShowing()) { |
| 2522 | md.mDialog.dismiss(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2523 | } |
| 2524 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2525 | mManagedDialogs = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2526 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2527 | |
| 2528 | // close any cursors we are managing. |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 2529 | synchronized (mManagedCursors) { |
| 2530 | int numCursors = mManagedCursors.size(); |
| 2531 | for (int i = 0; i < numCursors; i++) { |
| 2532 | ManagedCursor c = mManagedCursors.get(i); |
| 2533 | if (c != null) { |
| 2534 | c.mCursor.close(); |
| 2535 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2536 | } |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 2537 | mManagedCursors.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2538 | } |
Amith Yamasani | 4986044 | 2010-03-17 20:54:10 -0700 | [diff] [blame] | 2539 | |
| 2540 | // Close any open search dialog |
| 2541 | if (mSearchManager != null) { |
| 2542 | mSearchManager.stopSearch(); |
| 2543 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 2544 | |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 2545 | if (mActionBar != null) { |
| 2546 | mActionBar.onDestroy(); |
| 2547 | } |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 2548 | |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2549 | dispatchActivityDestroyed(); |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 2550 | |
| 2551 | notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_STOP); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | /** |
Dianne Hackborn | ebc15ef | 2013-10-09 17:36:57 -0700 | [diff] [blame] | 2555 | * Report to the system that your app is now fully drawn, purely for diagnostic |
| 2556 | * purposes (calling it does not impact the visible behavior of the activity). |
| 2557 | * This is only used to help instrument application launch times, so that the |
| 2558 | * app can report when it is fully in a usable state; without this, the only thing |
| 2559 | * the system itself can determine is the point at which the activity's window |
| 2560 | * is <em>first</em> drawn and displayed. To participate in app launch time |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 2561 | * measurement, you should always call this method after first launch (when |
Dianne Hackborn | ebc15ef | 2013-10-09 17:36:57 -0700 | [diff] [blame] | 2562 | * {@link #onCreate(android.os.Bundle)} is called), at the point where you have |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 2563 | * entirely drawn your UI and populated with all of the significant data. You |
| 2564 | * can safely call this method any time after first launch as well, in which case |
| 2565 | * it will simply be ignored. |
| 2566 | */ |
| 2567 | public void reportFullyDrawn() { |
| 2568 | if (mDoReportFullyDrawn) { |
| 2569 | mDoReportFullyDrawn = false; |
| 2570 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2571 | ActivityTaskManager.getService().reportActivityFullyDrawn( |
| 2572 | mToken, mRestoredFromBundle); |
Mathieu Chartier | 63e14c1 | 2019-03-07 09:05:44 -0800 | [diff] [blame] | 2573 | VMRuntime.getRuntime().notifyStartupCompleted(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 2574 | } catch (RemoteException e) { |
| 2575 | } |
| 2576 | } |
| 2577 | } |
| 2578 | |
| 2579 | /** |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2580 | * Called by the system when the activity changes from fullscreen mode to multi-window mode and |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2581 | * visa-versa. This method provides the same configuration that will be sent in the following |
| 2582 | * {@link #onConfigurationChanged(Configuration)} call after the activity enters this mode. |
| 2583 | * |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2584 | * @see android.R.attr#resizeableActivity |
| 2585 | * |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2586 | * @param isInMultiWindowMode True if the activity is in multi-window mode. |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2587 | * @param newConfig The new configuration of the activity with the state |
| 2588 | * {@param isInMultiWindowMode}. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2589 | */ |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2590 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) { |
| 2591 | // Left deliberately empty. There should be no side effects if a direct |
| 2592 | // subclass of Activity does not call super. |
| 2593 | onMultiWindowModeChanged(isInMultiWindowMode); |
| 2594 | } |
| 2595 | |
| 2596 | /** |
| 2597 | * Called by the system when the activity changes from fullscreen mode to multi-window mode and |
| 2598 | * visa-versa. |
| 2599 | * |
| 2600 | * @see android.R.attr#resizeableActivity |
| 2601 | * |
| 2602 | * @param isInMultiWindowMode True if the activity is in multi-window mode. |
| 2603 | * |
| 2604 | * @deprecated Use {@link #onMultiWindowModeChanged(boolean, Configuration)} instead. |
| 2605 | */ |
| 2606 | @Deprecated |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2607 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 2608 | // Left deliberately empty. There should be no side effects if a direct |
| 2609 | // subclass of Activity does not call super. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | /** |
| 2613 | * Returns true if the activity is currently in multi-window mode. |
| 2614 | * @see android.R.attr#resizeableActivity |
| 2615 | * |
| 2616 | * @return True if the activity is in multi-window mode. |
| 2617 | */ |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2618 | public boolean isInMultiWindowMode() { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2619 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2620 | return ActivityTaskManager.getService().isInMultiWindowMode(mToken); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2621 | } catch (RemoteException e) { |
| 2622 | } |
| 2623 | return false; |
| 2624 | } |
| 2625 | |
| 2626 | /** |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2627 | * Called by the system when the activity changes to and from picture-in-picture mode. This |
| 2628 | * method provides the same configuration that will be sent in the following |
| 2629 | * {@link #onConfigurationChanged(Configuration)} call after the activity enters this mode. |
| 2630 | * |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2631 | * @see android.R.attr#supportsPictureInPicture |
| 2632 | * |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2633 | * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode. |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2634 | * @param newConfig The new configuration of the activity with the state |
| 2635 | * {@param isInPictureInPictureMode}. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2636 | */ |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2637 | public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, |
| 2638 | Configuration newConfig) { |
| 2639 | // Left deliberately empty. There should be no side effects if a direct |
| 2640 | // subclass of Activity does not call super. |
| 2641 | onPictureInPictureModeChanged(isInPictureInPictureMode); |
| 2642 | } |
| 2643 | |
| 2644 | /** |
| 2645 | * Called by the system when the activity changes to and from picture-in-picture mode. |
| 2646 | * |
| 2647 | * @see android.R.attr#supportsPictureInPicture |
| 2648 | * |
| 2649 | * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode. |
| 2650 | * |
| 2651 | * @deprecated Use {@link #onPictureInPictureModeChanged(boolean, Configuration)} instead. |
| 2652 | */ |
| 2653 | @Deprecated |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2654 | public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 2655 | // Left deliberately empty. There should be no side effects if a direct |
| 2656 | // subclass of Activity does not call super. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | /** |
| 2660 | * Returns true if the activity is currently in picture-in-picture mode. |
| 2661 | * @see android.R.attr#supportsPictureInPicture |
| 2662 | * |
| 2663 | * @return True if the activity is in picture-in-picture mode. |
| 2664 | */ |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2665 | public boolean isInPictureInPictureMode() { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2666 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2667 | return ActivityTaskManager.getService().isInPictureInPictureMode(mToken); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2668 | } catch (RemoteException e) { |
| 2669 | } |
| 2670 | return false; |
| 2671 | } |
| 2672 | |
| 2673 | /** |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2674 | * Puts the activity in picture-in-picture mode if possible in the current system state. Any |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2675 | * prior calls to {@link #setPictureInPictureParams(PictureInPictureParams)} will still apply |
| 2676 | * when entering picture-in-picture through this call. |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2677 | * |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2678 | * @see #enterPictureInPictureMode(PictureInPictureParams) |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 2679 | * @see android.R.attr#supportsPictureInPicture |
| 2680 | */ |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2681 | @Deprecated |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2682 | public void enterPictureInPictureMode() { |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2683 | enterPictureInPictureMode(new PictureInPictureParams.Builder().build()); |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 2684 | } |
| 2685 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2686 | /** @removed */ |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2687 | @Deprecated |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2688 | public boolean enterPictureInPictureMode(@NonNull PictureInPictureArgs args) { |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2689 | return enterPictureInPictureMode(PictureInPictureArgs.convert(args)); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | /** |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2693 | * Puts the activity in picture-in-picture mode if possible in the current system state. The |
| 2694 | * set parameters in {@param params} will be combined with the parameters from prior calls to |
| 2695 | * {@link #setPictureInPictureParams(PictureInPictureParams)}. |
| 2696 | * |
| 2697 | * The system may disallow entering picture-in-picture in various cases, including when the |
| 2698 | * activity is not visible, if the screen is locked or if the user has an activity pinned. |
| 2699 | * |
| 2700 | * @see android.R.attr#supportsPictureInPicture |
| 2701 | * @see PictureInPictureParams |
| 2702 | * |
| 2703 | * @param params non-null parameters to be combined with previously set parameters when entering |
| 2704 | * picture-in-picture. |
| 2705 | * |
Winson Chung | 80fa2d8 | 2018-01-25 13:58:20 -0800 | [diff] [blame] | 2706 | * @return true if the system successfully put this activity into picture-in-picture mode or was |
Andrew Solovay | 8a788f4 | 2018-12-12 14:25:47 -0800 | [diff] [blame] | 2707 | * already in picture-in-picture mode (see {@link #isInPictureInPictureMode()}). If the device |
Winson Chung | 80fa2d8 | 2018-01-25 13:58:20 -0800 | [diff] [blame] | 2708 | * does not support picture-in-picture, return false. |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2709 | */ |
| 2710 | public boolean enterPictureInPictureMode(@NonNull PictureInPictureParams params) { |
| 2711 | try { |
Winson Chung | 80fa2d8 | 2018-01-25 13:58:20 -0800 | [diff] [blame] | 2712 | if (!deviceSupportsPictureInPictureMode()) { |
| 2713 | return false; |
| 2714 | } |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2715 | if (params == null) { |
| 2716 | throw new IllegalArgumentException("Expected non-null picture-in-picture params"); |
| 2717 | } |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 2718 | if (!mCanEnterPictureInPicture) { |
| 2719 | throw new IllegalStateException("Activity must be resumed to enter" |
| 2720 | + " picture-in-picture"); |
| 2721 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2722 | return ActivityTaskManager.getService().enterPictureInPictureMode(mToken, params); |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2723 | } catch (RemoteException e) { |
| 2724 | return false; |
| 2725 | } |
| 2726 | } |
| 2727 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2728 | /** @removed */ |
| 2729 | @Deprecated |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2730 | public void setPictureInPictureArgs(@NonNull PictureInPictureArgs args) { |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2731 | setPictureInPictureParams(PictureInPictureArgs.convert(args)); |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | /** |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2735 | * Updates the properties of the picture-in-picture activity, or sets it to be used later when |
| 2736 | * {@link #enterPictureInPictureMode()} is called. |
| 2737 | * |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2738 | * @param params the new parameters for the picture-in-picture. |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2739 | */ |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2740 | public void setPictureInPictureParams(@NonNull PictureInPictureParams params) { |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2741 | try { |
Winson Chung | 80fa2d8 | 2018-01-25 13:58:20 -0800 | [diff] [blame] | 2742 | if (!deviceSupportsPictureInPictureMode()) { |
| 2743 | return; |
| 2744 | } |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2745 | if (params == null) { |
| 2746 | throw new IllegalArgumentException("Expected non-null picture-in-picture params"); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2747 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2748 | ActivityTaskManager.getService().setPictureInPictureParams(mToken, params); |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2749 | } catch (RemoteException e) { |
| 2750 | } |
| 2751 | } |
| 2752 | |
Winson Chung | 8802eac | 2017-04-17 14:21:44 -0700 | [diff] [blame] | 2753 | /** |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2754 | * Return the number of actions that will be displayed in the picture-in-picture UI when the |
| 2755 | * user interacts with the activity currently in picture-in-picture mode. This number may change |
| 2756 | * if the global configuration changes (ie. if the device is plugged into an external display), |
| 2757 | * but will always be larger than three. |
| 2758 | */ |
| 2759 | public int getMaxNumPictureInPictureActions() { |
| 2760 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2761 | return ActivityTaskManager.getService().getMaxNumPictureInPictureActions(mToken); |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2762 | } catch (RemoteException e) { |
| 2763 | return 0; |
| 2764 | } |
| 2765 | } |
| 2766 | |
Winson Chung | 80fa2d8 | 2018-01-25 13:58:20 -0800 | [diff] [blame] | 2767 | /** |
| 2768 | * @return Whether this device supports picture-in-picture. |
| 2769 | */ |
| 2770 | private boolean deviceSupportsPictureInPictureMode() { |
| 2771 | return getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE); |
| 2772 | } |
| 2773 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2774 | void dispatchMovedToDisplay(int displayId, Configuration config) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2775 | updateDisplay(displayId); |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2776 | onMovedToDisplay(displayId, config); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | /** |
| 2780 | * Called by the system when the activity is moved from one display to another without |
| 2781 | * recreation. This means that this activity is declared to handle all changes to configuration |
| 2782 | * that happened when it was switched to another display, so it wasn't destroyed and created |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2783 | * again. |
| 2784 | * |
| 2785 | * <p>This call will be followed by {@link #onConfigurationChanged(Configuration)} if the |
| 2786 | * applied configuration actually changed. It is up to app developer to choose whether to handle |
| 2787 | * the change in this method or in the following {@link #onConfigurationChanged(Configuration)} |
| 2788 | * call. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2789 | * |
| 2790 | * <p>Use this callback to track changes to the displays if some activity functionality relies |
| 2791 | * on an association with some display properties. |
| 2792 | * |
| 2793 | * @param displayId The id of the display to which activity was moved. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2794 | * @param config Configuration of the activity resources on new display after move. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2795 | * |
| 2796 | * @see #onConfigurationChanged(Configuration) |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2797 | * @see View#onMovedToDisplay(int, Configuration) |
Andrii Kulian | cadacce | 2017-04-26 18:09:54 -0700 | [diff] [blame] | 2798 | * @hide |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2799 | */ |
Artur Satayev | 5a52585 | 2019-10-31 15:15:50 +0000 | [diff] [blame] | 2800 | @UnsupportedAppUsage |
Tiger Huang | fc21845 | 2018-09-27 00:38:50 +0800 | [diff] [blame] | 2801 | @TestApi |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2802 | public void onMovedToDisplay(int displayId, Configuration config) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2803 | } |
| 2804 | |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2805 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2806 | * Called by the system when the device configuration changes while your |
| 2807 | * activity is running. Note that this will <em>only</em> be called if |
| 2808 | * you have selected configurations you would like to handle with the |
| 2809 | * {@link android.R.attr#configChanges} attribute in your manifest. If |
| 2810 | * any configuration change occurs that is not selected to be reported |
| 2811 | * by that attribute, then instead of reporting it the system will stop |
| 2812 | * and restart the activity (to have it launched with the new |
| 2813 | * configuration). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2814 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2815 | * <p>At the time that this function has been called, your Resources |
| 2816 | * object will have been updated to return resource values matching the |
| 2817 | * new configuration. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2818 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2819 | * @param newConfig The new device configuration. |
| 2820 | */ |
Ian Lake | 666a965 | 2018-09-12 15:13:19 -0700 | [diff] [blame] | 2821 | public void onConfigurationChanged(@NonNull Configuration newConfig) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2822 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onConfigurationChanged " + this + ": " + newConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2823 | mCalled = true; |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 2824 | |
Dianne Hackborn | 9d07180 | 2010-12-08 14:49:15 -0800 | [diff] [blame] | 2825 | mFragments.dispatchConfigurationChanged(newConfig); |
| 2826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2827 | if (mWindow != null) { |
| 2828 | // Pass the configuration changed event to the window |
| 2829 | mWindow.onConfigurationChanged(newConfig); |
| 2830 | } |
Adam Powell | 45c0b19 | 2011-07-28 15:11:57 -0700 | [diff] [blame] | 2831 | |
| 2832 | if (mActionBar != null) { |
| 2833 | // Do this last; the action bar will need to access |
| 2834 | // view changes from above. |
| 2835 | mActionBar.onConfigurationChanged(newConfig); |
| 2836 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2837 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2839 | /** |
| 2840 | * If this activity is being destroyed because it can not handle a |
| 2841 | * configuration parameter being changed (and thus its |
| 2842 | * {@link #onConfigurationChanged(Configuration)} method is |
| 2843 | * <em>not</em> being called), then you can use this method to discover |
| 2844 | * the set of changes that have occurred while in the process of being |
| 2845 | * destroyed. Note that there is no guarantee that these will be |
| 2846 | * accurate (other changes could have happened at any time), so you should |
| 2847 | * only use this as an optimization hint. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2848 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2849 | * @return Returns a bit field of the configuration parameters that are |
| 2850 | * changing, as defined by the {@link android.content.res.Configuration} |
| 2851 | * class. |
| 2852 | */ |
| 2853 | public int getChangingConfigurations() { |
| 2854 | return mConfigChangeFlags; |
| 2855 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2856 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2857 | /** |
| 2858 | * Retrieve the non-configuration instance data that was previously |
| 2859 | * returned by {@link #onRetainNonConfigurationInstance()}. This will |
| 2860 | * be available from the initial {@link #onCreate} and |
| 2861 | * {@link #onStart} calls to the new instance, allowing you to extract |
| 2862 | * any useful dynamic state from the previous instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2863 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2864 | * <p>Note that the data you retrieve here should <em>only</em> be used |
| 2865 | * as an optimization for handling configuration changes. You should always |
| 2866 | * be able to handle getting a null pointer back, and an activity must |
| 2867 | * still be able to restore itself to its previous state (through the |
| 2868 | * normal {@link #onSaveInstanceState(Bundle)} mechanism) even if this |
| 2869 | * function returns null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2870 | * |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2871 | * <p><strong>Note:</strong> For most cases you should use the {@link Fragment} API |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 2872 | * {@link Fragment#setRetainInstance(boolean)} instead; this is also |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2873 | * available on older platforms through the Android support libraries. |
| 2874 | * |
| 2875 | * @return the object previously returned by {@link #onRetainNonConfigurationInstance()} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2876 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2877 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2878 | public Object getLastNonConfigurationInstance() { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2879 | return mLastNonConfigurationInstances != null |
| 2880 | ? mLastNonConfigurationInstances.activity : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2881 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2882 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2883 | /** |
| 2884 | * Called by the system, as part of destroying an |
| 2885 | * activity due to a configuration change, when it is known that a new |
| 2886 | * instance will immediately be created for the new configuration. You |
| 2887 | * can return any object you like here, including the activity instance |
| 2888 | * itself, which can later be retrieved by calling |
| 2889 | * {@link #getLastNonConfigurationInstance()} in the new activity |
| 2890 | * instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2891 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2892 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 2893 | * or later, consider instead using a {@link Fragment} with |
| 2894 | * {@link Fragment#setRetainInstance(boolean) |
| 2895 | * Fragment.setRetainInstance(boolean}.</em> |
| 2896 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2897 | * <p>This function is called purely as an optimization, and you must |
| 2898 | * not rely on it being called. When it is called, a number of guarantees |
| 2899 | * will be made to help optimize configuration switching: |
| 2900 | * <ul> |
| 2901 | * <li> The function will be called between {@link #onStop} and |
| 2902 | * {@link #onDestroy}. |
| 2903 | * <li> A new instance of the activity will <em>always</em> be immediately |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 2904 | * created after this one's {@link #onDestroy()} is called. In particular, |
| 2905 | * <em>no</em> messages will be dispatched during this time (when the returned |
| 2906 | * object does not have an activity to be associated with). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2907 | * <li> The object you return here will <em>always</em> be available from |
| 2908 | * the {@link #getLastNonConfigurationInstance()} method of the following |
| 2909 | * activity instance as described there. |
| 2910 | * </ul> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2911 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | * <p>These guarantees are designed so that an activity can use this API |
| 2913 | * to propagate extensive state from the old to new activity instance, from |
| 2914 | * loaded bitmaps, to network connections, to evenly actively running |
| 2915 | * threads. Note that you should <em>not</em> propagate any data that |
| 2916 | * may change based on the configuration, including any data loaded from |
| 2917 | * resources such as strings, layouts, or drawables. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2918 | * |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 2919 | * <p>The guarantee of no message handling during the switch to the next |
| 2920 | * activity simplifies use with active objects. For example if your retained |
| 2921 | * state is an {@link android.os.AsyncTask} you are guaranteed that its |
| 2922 | * call back functions (like {@link android.os.AsyncTask#onPostExecute}) will |
| 2923 | * not be called from the call here until you execute the next instance's |
| 2924 | * {@link #onCreate(Bundle)}. (Note however that there is of course no such |
| 2925 | * guarantee for {@link android.os.AsyncTask#doInBackground} since that is |
| 2926 | * running in a separate thread.) |
| 2927 | * |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2928 | * <p><strong>Note:</strong> For most cases you should use the {@link Fragment} API |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 2929 | * {@link Fragment#setRetainInstance(boolean)} instead; this is also |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2930 | * available on older platforms through the Android support libraries. |
| 2931 | * |
| 2932 | * @return any Object holding the desired state to propagate to the |
| 2933 | * next activity instance |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2934 | */ |
| 2935 | public Object onRetainNonConfigurationInstance() { |
| 2936 | return null; |
| 2937 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2939 | /** |
| 2940 | * Retrieve the non-configuration instance data that was previously |
| 2941 | * returned by {@link #onRetainNonConfigurationChildInstances()}. This will |
| 2942 | * be available from the initial {@link #onCreate} and |
| 2943 | * {@link #onStart} calls to the new instance, allowing you to extract |
| 2944 | * any useful dynamic state from the previous instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2945 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2946 | * <p>Note that the data you retrieve here should <em>only</em> be used |
| 2947 | * as an optimization for handling configuration changes. You should always |
| 2948 | * be able to handle getting a null pointer back, and an activity must |
| 2949 | * still be able to restore itself to its previous state (through the |
| 2950 | * normal {@link #onSaveInstanceState(Bundle)} mechanism) even if this |
| 2951 | * function returns null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2952 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2953 | * @return Returns the object previously returned by |
| 2954 | * {@link #onRetainNonConfigurationChildInstances()} |
| 2955 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2956 | @Nullable |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2957 | HashMap<String, Object> getLastNonConfigurationChildInstances() { |
| 2958 | return mLastNonConfigurationInstances != null |
| 2959 | ? mLastNonConfigurationInstances.children : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2960 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2962 | /** |
| 2963 | * This method is similar to {@link #onRetainNonConfigurationInstance()} except that |
| 2964 | * it should return either a mapping from child activity id strings to arbitrary objects, |
| 2965 | * or null. This method is intended to be used by Activity framework subclasses that control a |
| 2966 | * set of child activities, such as ActivityGroup. The same guarantees and restrictions apply |
| 2967 | * as for {@link #onRetainNonConfigurationInstance()}. The default implementation returns null. |
| 2968 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2969 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2970 | HashMap<String,Object> onRetainNonConfigurationChildInstances() { |
| 2971 | return null; |
| 2972 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2973 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2974 | NonConfigurationInstances retainNonConfigurationInstances() { |
| 2975 | Object activity = onRetainNonConfigurationInstance(); |
| 2976 | HashMap<String, Object> children = onRetainNonConfigurationChildInstances(); |
Adam Powell | 44ba79e | 2016-02-04 16:20:37 -0800 | [diff] [blame] | 2977 | FragmentManagerNonConfig fragments = mFragments.retainNestedNonConfig(); |
Adam Powell | cbade7f | 2016-04-15 11:14:37 -0700 | [diff] [blame] | 2978 | |
| 2979 | // We're already stopped but we've been asked to retain. |
| 2980 | // Our fragments are taken care of but we need to mark the loaders for retention. |
| 2981 | // In order to do this correctly we need to restart the loaders first before |
| 2982 | // handing them off to the next activity. |
| 2983 | mFragments.doLoaderStart(); |
| 2984 | mFragments.doLoaderStop(true); |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2985 | ArrayMap<String, LoaderManager> loaders = mFragments.retainLoaderNonConfig(); |
Adam Powell | cbade7f | 2016-04-15 11:14:37 -0700 | [diff] [blame] | 2986 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2987 | if (activity == null && children == null && fragments == null && loaders == null |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 2988 | && mVoiceInteractor == null) { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2989 | return null; |
| 2990 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2991 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2992 | NonConfigurationInstances nci = new NonConfigurationInstances(); |
| 2993 | nci.activity = activity; |
| 2994 | nci.children = children; |
| 2995 | nci.fragments = fragments; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2996 | nci.loaders = loaders; |
Dianne Hackborn | 57dd737 | 2015-07-27 18:11:14 -0700 | [diff] [blame] | 2997 | if (mVoiceInteractor != null) { |
| 2998 | mVoiceInteractor.retainInstance(); |
| 2999 | nci.voiceInteractor = mVoiceInteractor; |
| 3000 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 3001 | return nci; |
| 3002 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 3003 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3004 | public void onLowMemory() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3005 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onLowMemory " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3006 | mCalled = true; |
Dianne Hackborn | 9d07180 | 2010-12-08 14:49:15 -0800 | [diff] [blame] | 3007 | mFragments.dispatchLowMemory(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3008 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 3009 | |
| 3010 | public void onTrimMemory(int level) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3011 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onTrimMemory " + this + ": " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 3012 | mCalled = true; |
| 3013 | mFragments.dispatchTrimMemory(level); |
| 3014 | } |
| 3015 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3016 | /** |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 3017 | * Return the FragmentManager for interacting with fragments associated |
| 3018 | * with this activity. |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 3019 | * |
| 3020 | * @deprecated Use {@link android.support.v4.app.FragmentActivity#getSupportFragmentManager()} |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 3021 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 3022 | @Deprecated |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 3023 | public FragmentManager getFragmentManager() { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 3024 | return mFragments.getFragmentManager(); |
Dianne Hackborn | 9e14e9f3 | 2010-07-14 11:07:38 -0700 | [diff] [blame] | 3025 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3026 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 3027 | /** |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 3028 | * Called when a Fragment is being attached to this activity, immediately |
| 3029 | * after the call to its {@link Fragment#onAttach Fragment.onAttach()} |
| 3030 | * method and before {@link Fragment#onCreate Fragment.onCreate()}. |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 3031 | * |
| 3032 | * @deprecated Use {@link |
| 3033 | * android.support.v4.app.FragmentActivity#onAttachFragment(android.support.v4.app.Fragment)} |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 3034 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 3035 | @Deprecated |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 3036 | public void onAttachFragment(Fragment fragment) { |
| 3037 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3038 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 3039 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3040 | * Wrapper around |
| 3041 | * {@link ContentResolver#query(android.net.Uri , String[], String, String[], String)} |
| 3042 | * that gives the resulting {@link Cursor} to call |
| 3043 | * {@link #startManagingCursor} so that the activity will manage its |
| 3044 | * lifecycle for you. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3045 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 3046 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 3047 | * or later, consider instead using {@link LoaderManager} instead, available |
| 3048 | * via {@link #getLoaderManager()}.</em> |
| 3049 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 3050 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on a cursor obtained using |
| 3051 | * this method, because the activity will do that for you at the appropriate time. However, if |
| 3052 | * you call {@link #stopManagingCursor} on a cursor from a managed query, the system <em>will |
| 3053 | * not</em> automatically close the cursor and, in that case, you must call |
| 3054 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3055 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3056 | * @param uri The URI of the content provider to query. |
| 3057 | * @param projection List of columns to return. |
| 3058 | * @param selection SQL WHERE clause. |
| 3059 | * @param sortOrder SQL ORDER BY clause. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3060 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3061 | * @return The Cursor that was returned by query(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3062 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3063 | * @see ContentResolver#query(android.net.Uri , String[], String, String[], String) |
| 3064 | * @see #startManagingCursor |
| 3065 | * @hide |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 3066 | * |
| 3067 | * @deprecated Use {@link CursorLoader} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3068 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 3069 | @Deprecated |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3070 | @UnsupportedAppUsage |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 3071 | public final Cursor managedQuery(Uri uri, String[] projection, String selection, |
| 3072 | String sortOrder) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3073 | Cursor c = getContentResolver().query(uri, projection, selection, null, sortOrder); |
| 3074 | if (c != null) { |
| 3075 | startManagingCursor(c); |
| 3076 | } |
| 3077 | return c; |
| 3078 | } |
| 3079 | |
| 3080 | /** |
| 3081 | * Wrapper around |
| 3082 | * {@link ContentResolver#query(android.net.Uri , String[], String, String[], String)} |
| 3083 | * that gives the resulting {@link Cursor} to call |
| 3084 | * {@link #startManagingCursor} so that the activity will manage its |
| 3085 | * lifecycle for you. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3086 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 3087 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 3088 | * or later, consider instead using {@link LoaderManager} instead, available |
| 3089 | * via {@link #getLoaderManager()}.</em> |
| 3090 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 3091 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on a cursor obtained using |
| 3092 | * this method, because the activity will do that for you at the appropriate time. However, if |
| 3093 | * you call {@link #stopManagingCursor} on a cursor from a managed query, the system <em>will |
| 3094 | * not</em> automatically close the cursor and, in that case, you must call |
| 3095 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3096 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3097 | * @param uri The URI of the content provider to query. |
| 3098 | * @param projection List of columns to return. |
| 3099 | * @param selection SQL WHERE clause. |
| 3100 | * @param selectionArgs The arguments to selection, if any ?s are pesent |
| 3101 | * @param sortOrder SQL ORDER BY clause. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3102 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3103 | * @return The Cursor that was returned by query(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3104 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3105 | * @see ContentResolver#query(android.net.Uri , String[], String, String[], String) |
| 3106 | * @see #startManagingCursor |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 3107 | * |
| 3108 | * @deprecated Use {@link CursorLoader} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3109 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 3110 | @Deprecated |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 3111 | public final Cursor managedQuery(Uri uri, String[] projection, String selection, |
| 3112 | String[] selectionArgs, String sortOrder) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3113 | Cursor c = getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder); |
| 3114 | if (c != null) { |
| 3115 | startManagingCursor(c); |
| 3116 | } |
| 3117 | return c; |
| 3118 | } |
| 3119 | |
| 3120 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3121 | * This method allows the activity to take care of managing the given |
| 3122 | * {@link Cursor}'s lifecycle for you based on the activity's lifecycle. |
| 3123 | * That is, when the activity is stopped it will automatically call |
| 3124 | * {@link Cursor#deactivate} on the given Cursor, and when it is later restarted |
| 3125 | * it will call {@link Cursor#requery} for you. When the activity is |
| 3126 | * destroyed, all managed Cursors will be closed automatically. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3127 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 3128 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 3129 | * or later, consider instead using {@link LoaderManager} instead, available |
| 3130 | * via {@link #getLoaderManager()}.</em> |
| 3131 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 3132 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on cursor obtained from |
| 3133 | * {@link #managedQuery}, because the activity will do that for you at the appropriate time. |
| 3134 | * However, if you call {@link #stopManagingCursor} on a cursor from a managed query, the system |
| 3135 | * <em>will not</em> automatically close the cursor and, in that case, you must call |
| 3136 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3137 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3138 | * @param c The Cursor to be managed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3139 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3140 | * @see #managedQuery(android.net.Uri , String[], String, String[], String) |
| 3141 | * @see #stopManagingCursor |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3142 | * |
| 3143 | * @deprecated Use the new {@link android.content.CursorLoader} class with |
| 3144 | * {@link LoaderManager} instead; this is also |
| 3145 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3146 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 3147 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3148 | public void startManagingCursor(Cursor c) { |
| 3149 | synchronized (mManagedCursors) { |
| 3150 | mManagedCursors.add(new ManagedCursor(c)); |
| 3151 | } |
| 3152 | } |
| 3153 | |
| 3154 | /** |
| 3155 | * Given a Cursor that was previously given to |
| 3156 | * {@link #startManagingCursor}, stop the activity's management of that |
| 3157 | * cursor. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3158 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 3159 | * <p><strong>Warning:</strong> After calling this method on a cursor from a managed query, |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3160 | * the system <em>will not</em> automatically close the cursor and you must call |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 3161 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3162 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3163 | * @param c The Cursor that was being managed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3164 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3165 | * @see #startManagingCursor |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3166 | * |
| 3167 | * @deprecated Use the new {@link android.content.CursorLoader} class with |
| 3168 | * {@link LoaderManager} instead; this is also |
| 3169 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3170 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 3171 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3172 | public void stopManagingCursor(Cursor c) { |
| 3173 | synchronized (mManagedCursors) { |
| 3174 | final int N = mManagedCursors.size(); |
| 3175 | for (int i=0; i<N; i++) { |
| 3176 | ManagedCursor mc = mManagedCursors.get(i); |
| 3177 | if (mc.mCursor == c) { |
| 3178 | mManagedCursors.remove(i); |
| 3179 | break; |
| 3180 | } |
| 3181 | } |
| 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | /** |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3186 | * @deprecated As of {@link android.os.Build.VERSION_CODES#GINGERBREAD} |
| 3187 | * this is a no-op. |
Dianne Hackborn | 4f3867e | 2010-12-14 22:09:51 -0800 | [diff] [blame] | 3188 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3189 | */ |
Dianne Hackborn | d3efa39 | 2010-09-01 17:34:12 -0700 | [diff] [blame] | 3190 | @Deprecated |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3191 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3192 | public void setPersistent(boolean isPersistent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | /** |
Alan Viverette | db7423c | 2017-03-31 13:13:58 -0400 | [diff] [blame] | 3196 | * Finds a view that was identified by the {@code android:id} XML attribute |
| 3197 | * that was processed in {@link #onCreate}. |
| 3198 | * <p> |
| 3199 | * <strong>Note:</strong> In most cases -- depending on compiler support -- |
| 3200 | * the resulting view is automatically cast to the target class type. If |
| 3201 | * the target class type is unconstrained, an explicit cast may be |
| 3202 | * necessary. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3203 | * |
Alan Viverette | db7423c | 2017-03-31 13:13:58 -0400 | [diff] [blame] | 3204 | * @param id the ID to search for |
| 3205 | * @return a view with given ID if found, or {@code null} otherwise |
| 3206 | * @see View#findViewById(int) |
Chris Craik | 6faa9e5 | 2018-01-11 10:46:10 -0800 | [diff] [blame] | 3207 | * @see Activity#requireViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3208 | */ |
Scott Kennedy | c051955 | 2015-02-11 15:33:10 -0800 | [diff] [blame] | 3209 | @Nullable |
Alan Viverette | db7423c | 2017-03-31 13:13:58 -0400 | [diff] [blame] | 3210 | public <T extends View> T findViewById(@IdRes int id) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3211 | return getWindow().findViewById(id); |
| 3212 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3213 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3214 | /** |
Chris Craik | 6faa9e5 | 2018-01-11 10:46:10 -0800 | [diff] [blame] | 3215 | * Finds a view that was identified by the {@code android:id} XML attribute that was processed |
| 3216 | * in {@link #onCreate}, or throws an IllegalArgumentException if the ID is invalid, or there is |
| 3217 | * no matching view in the hierarchy. |
| 3218 | * <p> |
| 3219 | * <strong>Note:</strong> In most cases -- depending on compiler support -- |
| 3220 | * the resulting view is automatically cast to the target class type. If |
| 3221 | * the target class type is unconstrained, an explicit cast may be |
| 3222 | * necessary. |
| 3223 | * |
| 3224 | * @param id the ID to search for |
| 3225 | * @return a view with given ID |
| 3226 | * @see View#requireViewById(int) |
| 3227 | * @see Activity#findViewById(int) |
| 3228 | */ |
| 3229 | @NonNull |
| 3230 | public final <T extends View> T requireViewById(@IdRes int id) { |
| 3231 | T view = findViewById(id); |
| 3232 | if (view == null) { |
| 3233 | throw new IllegalArgumentException("ID does not reference a View inside this Activity"); |
| 3234 | } |
| 3235 | return view; |
| 3236 | } |
| 3237 | |
| 3238 | /** |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3239 | * Retrieve a reference to this activity's ActionBar. |
Adam Powell | 42c0fe8 | 2010-08-10 16:36:56 -0700 | [diff] [blame] | 3240 | * |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3241 | * @return The Activity's ActionBar, or null if it does not have one. |
| 3242 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3243 | @Nullable |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3244 | public ActionBar getActionBar() { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3245 | initWindowDecorActionBar(); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3246 | return mActionBar; |
| 3247 | } |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3248 | |
| 3249 | /** |
| 3250 | * Set a {@link android.widget.Toolbar Toolbar} to act as the {@link ActionBar} for this |
| 3251 | * Activity window. |
| 3252 | * |
| 3253 | * <p>When set to a non-null value the {@link #getActionBar()} method will return |
| 3254 | * an {@link ActionBar} object that can be used to control the given toolbar as if it were |
| 3255 | * a traditional window decor action bar. The toolbar's menu will be populated with the |
| 3256 | * Activity's options menu and the navigation button will be wired through the standard |
| 3257 | * {@link android.R.id#home home} menu select action.</p> |
| 3258 | * |
| 3259 | * <p>In order to use a Toolbar within the Activity's window content the application |
| 3260 | * must not request the window feature {@link Window#FEATURE_ACTION_BAR FEATURE_ACTION_BAR}.</p> |
| 3261 | * |
Chris Banes | c7d6c32 | 2016-01-27 14:09:16 +0000 | [diff] [blame] | 3262 | * @param toolbar Toolbar to set as the Activity's action bar, or {@code null} to clear it |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3263 | */ |
Adam Powell | 3778014 | 2014-06-01 13:31:00 -0700 | [diff] [blame] | 3264 | public void setActionBar(@Nullable Toolbar toolbar) { |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 3265 | final ActionBar ab = getActionBar(); |
| 3266 | if (ab instanceof WindowDecorActionBar) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3267 | throw new IllegalStateException("This Activity already has an action bar supplied " + |
| 3268 | "by the window decor. Do not request Window.FEATURE_ACTION_BAR and set " + |
| 3269 | "android:windowActionBar to false in your theme to use a Toolbar instead."); |
| 3270 | } |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 3271 | |
| 3272 | // If we reach here then we're setting a new action bar |
| 3273 | // First clear out the MenuInflater to make sure that it is valid for the new Action Bar |
Chris Banes | 601bb99 | 2015-06-22 10:05:38 +0100 | [diff] [blame] | 3274 | mMenuInflater = null; |
| 3275 | |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 3276 | // If we have an action bar currently, destroy it |
| 3277 | if (ab != null) { |
| 3278 | ab.onDestroy(); |
| 3279 | } |
| 3280 | |
Chris Banes | c7d6c32 | 2016-01-27 14:09:16 +0000 | [diff] [blame] | 3281 | if (toolbar != null) { |
| 3282 | final ToolbarActionBar tbab = new ToolbarActionBar(toolbar, getTitle(), this); |
| 3283 | mActionBar = tbab; |
| 3284 | mWindow.setCallback(tbab.getWrappedWindowCallback()); |
| 3285 | } else { |
| 3286 | mActionBar = null; |
| 3287 | // Re-set the original window callback since we may have already set a Toolbar wrapper |
| 3288 | mWindow.setCallback(this); |
| 3289 | } |
| 3290 | |
| 3291 | invalidateOptionsMenu(); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3292 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3294 | /** |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3295 | * Creates a new ActionBar, locates the inflated ActionBarView, |
| 3296 | * initializes the ActionBar with the view, and sets mActionBar. |
| 3297 | */ |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3298 | private void initWindowDecorActionBar() { |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 3299 | Window window = getWindow(); |
Adam Powell | a593d98 | 2011-05-13 14:09:54 -0700 | [diff] [blame] | 3300 | |
| 3301 | // Initializing the window decor can change window feature flags. |
| 3302 | // Make sure that we have the correct set before performing the test below. |
| 3303 | window.getDecorView(); |
| 3304 | |
Adam Powell | 9b4c804 | 2010-08-10 15:36:44 -0700 | [diff] [blame] | 3305 | if (isChild() || !window.hasFeature(Window.FEATURE_ACTION_BAR) || mActionBar != null) { |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3306 | return; |
| 3307 | } |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 3308 | |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3309 | mActionBar = new WindowDecorActionBar(this); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3310 | mActionBar.setDefaultDisplayHomeAsUpEnabled(mEnableDefaultActionBarUp); |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 3311 | |
| 3312 | mWindow.setDefaultIcon(mActivityInfo.getIconResource()); |
| 3313 | mWindow.setDefaultLogo(mActivityInfo.getLogoResource()); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3314 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3315 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3316 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3317 | * Set the activity content from a layout resource. The resource will be |
| 3318 | * inflated, adding all top-level views to the activity. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 3319 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | * @param layoutResID Resource ID to be inflated. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3321 | * |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 3322 | * @see #setContentView(android.view.View) |
| 3323 | * @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3324 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3325 | public void setContentView(@LayoutRes int layoutResID) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3326 | getWindow().setContentView(layoutResID); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3327 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | /** |
| 3331 | * Set the activity content to an explicit view. This view is placed |
| 3332 | * directly into the activity's view hierarchy. It can itself be a complex |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 3333 | * view hierarchy. When calling this method, the layout parameters of the |
| 3334 | * specified view are ignored. Both the width and the height of the view are |
| 3335 | * set by default to {@link ViewGroup.LayoutParams#MATCH_PARENT}. To use |
| 3336 | * your own layout parameters, invoke |
| 3337 | * {@link #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)} |
| 3338 | * instead. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3339 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | * @param view The desired content to display. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 3341 | * |
| 3342 | * @see #setContentView(int) |
| 3343 | * @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3344 | */ |
| 3345 | public void setContentView(View view) { |
| 3346 | getWindow().setContentView(view); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3347 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3348 | } |
| 3349 | |
| 3350 | /** |
| 3351 | * Set the activity content to an explicit view. This view is placed |
| 3352 | * directly into the activity's view hierarchy. It can itself be a complex |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 3353 | * view hierarchy. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3354 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3355 | * @param view The desired content to display. |
| 3356 | * @param params Layout parameters for the view. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 3357 | * |
| 3358 | * @see #setContentView(android.view.View) |
| 3359 | * @see #setContentView(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | */ |
| 3361 | public void setContentView(View view, ViewGroup.LayoutParams params) { |
| 3362 | getWindow().setContentView(view, params); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3363 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | /** |
| 3367 | * Add an additional content view to the activity. Added after any existing |
| 3368 | * ones in the activity -- existing views are NOT removed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3369 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3370 | * @param view The desired content to display. |
| 3371 | * @param params Layout parameters for the view. |
| 3372 | */ |
| 3373 | public void addContentView(View view, ViewGroup.LayoutParams params) { |
| 3374 | getWindow().addContentView(view, params); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3375 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | /** |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3379 | * Retrieve the {@link TransitionManager} responsible for default transitions in this window. |
| 3380 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 3381 | * |
| 3382 | * <p>This method will return non-null after content has been initialized (e.g. by using |
| 3383 | * {@link #setContentView}) if {@link Window#FEATURE_CONTENT_TRANSITIONS} has been granted.</p> |
| 3384 | * |
| 3385 | * @return This window's content TransitionManager or null if none is set. |
| 3386 | */ |
| 3387 | public TransitionManager getContentTransitionManager() { |
| 3388 | return getWindow().getTransitionManager(); |
| 3389 | } |
| 3390 | |
| 3391 | /** |
| 3392 | * Set the {@link TransitionManager} to use for default transitions in this window. |
| 3393 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 3394 | * |
| 3395 | * @param tm The TransitionManager to use for scene changes. |
| 3396 | */ |
| 3397 | public void setContentTransitionManager(TransitionManager tm) { |
| 3398 | getWindow().setTransitionManager(tm); |
| 3399 | } |
| 3400 | |
| 3401 | /** |
| 3402 | * Retrieve the {@link Scene} representing this window's current content. |
| 3403 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 3404 | * |
| 3405 | * <p>This method will return null if the current content is not represented by a Scene.</p> |
| 3406 | * |
| 3407 | * @return Current Scene being shown or null |
| 3408 | */ |
| 3409 | public Scene getContentScene() { |
| 3410 | return getWindow().getContentScene(); |
| 3411 | } |
| 3412 | |
| 3413 | /** |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 3414 | * Sets whether this activity is finished when touched outside its window's |
| 3415 | * bounds. |
| 3416 | */ |
| 3417 | public void setFinishOnTouchOutside(boolean finish) { |
| 3418 | mWindow.setCloseOnTouchOutside(finish); |
| 3419 | } |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3420 | |
| 3421 | /** @hide */ |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 3422 | @IntDef(prefix = { "DEFAULT_KEYS_" }, value = { |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3423 | DEFAULT_KEYS_DISABLE, |
| 3424 | DEFAULT_KEYS_DIALER, |
| 3425 | DEFAULT_KEYS_SHORTCUT, |
| 3426 | DEFAULT_KEYS_SEARCH_LOCAL, |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 3427 | DEFAULT_KEYS_SEARCH_GLOBAL |
| 3428 | }) |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3429 | @Retention(RetentionPolicy.SOURCE) |
| 3430 | @interface DefaultKeyMode {} |
| 3431 | |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 3432 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3433 | * Use with {@link #setDefaultKeyMode} to turn off default handling of |
| 3434 | * keys. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3435 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3436 | * @see #setDefaultKeyMode |
| 3437 | */ |
| 3438 | static public final int DEFAULT_KEYS_DISABLE = 0; |
| 3439 | /** |
| 3440 | * Use with {@link #setDefaultKeyMode} to launch the dialer during default |
| 3441 | * key handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3442 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3443 | * @see #setDefaultKeyMode |
| 3444 | */ |
| 3445 | static public final int DEFAULT_KEYS_DIALER = 1; |
| 3446 | /** |
| 3447 | * Use with {@link #setDefaultKeyMode} to execute a menu shortcut in |
| 3448 | * default key handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3449 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3450 | * <p>That is, the user does not need to hold down the menu key to execute menu shortcuts. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3451 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3452 | * @see #setDefaultKeyMode |
| 3453 | */ |
| 3454 | static public final int DEFAULT_KEYS_SHORTCUT = 2; |
| 3455 | /** |
| 3456 | * Use with {@link #setDefaultKeyMode} to specify that unhandled keystrokes |
| 3457 | * will start an application-defined search. (If the application or activity does not |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 3458 | * actually define a search, the keys will be ignored.) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3459 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | * <p>See {@link android.app.SearchManager android.app.SearchManager} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3461 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3462 | * @see #setDefaultKeyMode |
| 3463 | */ |
| 3464 | static public final int DEFAULT_KEYS_SEARCH_LOCAL = 3; |
| 3465 | |
| 3466 | /** |
| 3467 | * Use with {@link #setDefaultKeyMode} to specify that unhandled keystrokes |
| 3468 | * will start a global search (typically web search, but some platforms may define alternate |
| 3469 | * methods for global search) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3470 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3471 | * <p>See {@link android.app.SearchManager android.app.SearchManager} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3472 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3473 | * @see #setDefaultKeyMode |
| 3474 | */ |
| 3475 | static public final int DEFAULT_KEYS_SEARCH_GLOBAL = 4; |
| 3476 | |
| 3477 | /** |
| 3478 | * Select the default key handling for this activity. This controls what |
| 3479 | * will happen to key events that are not otherwise handled. The default |
| 3480 | * mode ({@link #DEFAULT_KEYS_DISABLE}) will simply drop them on the |
| 3481 | * floor. Other modes allow you to launch the dialer |
| 3482 | * ({@link #DEFAULT_KEYS_DIALER}), execute a shortcut in your options |
| 3483 | * menu without requiring the menu key be held down |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3484 | * ({@link #DEFAULT_KEYS_SHORTCUT}), or launch a search ({@link #DEFAULT_KEYS_SEARCH_LOCAL} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3485 | * and {@link #DEFAULT_KEYS_SEARCH_GLOBAL}). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3486 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | * <p>Note that the mode selected here does not impact the default |
| 3488 | * handling of system keys, such as the "back" and "menu" keys, and your |
| 3489 | * activity and its views always get a first chance to receive and handle |
| 3490 | * all application keys. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3491 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3492 | * @param mode The desired default key mode constant. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3493 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3494 | * @see #onKeyDown |
| 3495 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3496 | public final void setDefaultKeyMode(@DefaultKeyMode int mode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3497 | mDefaultKeyMode = mode; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3499 | // Some modes use a SpannableStringBuilder to track & dispatch input events |
| 3500 | // This list must remain in sync with the switch in onKeyDown() |
| 3501 | switch (mode) { |
| 3502 | case DEFAULT_KEYS_DISABLE: |
| 3503 | case DEFAULT_KEYS_SHORTCUT: |
| 3504 | mDefaultKeySsb = null; // not used in these modes |
| 3505 | break; |
| 3506 | case DEFAULT_KEYS_DIALER: |
| 3507 | case DEFAULT_KEYS_SEARCH_LOCAL: |
| 3508 | case DEFAULT_KEYS_SEARCH_GLOBAL: |
| 3509 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 3510 | Selection.setSelection(mDefaultKeySsb,0); |
| 3511 | break; |
| 3512 | default: |
| 3513 | throw new IllegalArgumentException(); |
| 3514 | } |
| 3515 | } |
| 3516 | |
| 3517 | /** |
| 3518 | * Called when a key was pressed down and not handled by any of the views |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3519 | * inside of the activity. So, for example, key presses while the cursor |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3520 | * is inside a TextView will not trigger the event (unless it is a navigation |
| 3521 | * to another object) because TextView handles its own key presses. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3522 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3523 | * <p>If the focused view didn't want this event, this method is called. |
| 3524 | * |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3525 | * <p>The default implementation takes care of {@link KeyEvent#KEYCODE_BACK} |
| 3526 | * by calling {@link #onBackPressed()}, though the behavior varies based |
| 3527 | * on the application compatibility mode: for |
| 3528 | * {@link android.os.Build.VERSION_CODES#ECLAIR} or later applications, |
| 3529 | * it will set up the dispatch to call {@link #onKeyUp} where the action |
| 3530 | * will be performed; for earlier applications, it will perform the |
| 3531 | * action immediately in on-down, as those versions of the platform |
| 3532 | * behaved. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3533 | * |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3534 | * <p>Other additional default key handling may be performed |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3535 | * if configured with {@link #setDefaultKeyMode}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3536 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3537 | * @return Return <code>true</code> to prevent this event from being propagated |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3538 | * further, or <code>false</code> to indicate that you have not handled |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3539 | * this event and it should continue to be propagated. |
| 3540 | * @see #onKeyUp |
| 3541 | * @see android.view.KeyEvent |
| 3542 | */ |
| 3543 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3544 | if (keyCode == KeyEvent.KEYCODE_BACK) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3545 | if (getApplicationInfo().targetSdkVersion |
| 3546 | >= Build.VERSION_CODES.ECLAIR) { |
| 3547 | event.startTracking(); |
| 3548 | } else { |
| 3549 | onBackPressed(); |
| 3550 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3551 | return true; |
| 3552 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3553 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3554 | if (mDefaultKeyMode == DEFAULT_KEYS_DISABLE) { |
| 3555 | return false; |
| 3556 | } else if (mDefaultKeyMode == DEFAULT_KEYS_SHORTCUT) { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 3557 | Window w = getWindow(); |
| 3558 | if (w.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 3559 | w.performPanelShortcut(Window.FEATURE_OPTIONS_PANEL, keyCode, event, |
| 3560 | Menu.FLAG_ALWAYS_PERFORM_CLOSE)) { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3561 | return true; |
| 3562 | } |
| 3563 | return false; |
Evan Rosky | c4620378 | 2017-02-17 13:11:53 -0800 | [diff] [blame] | 3564 | } else if (keyCode == KeyEvent.KEYCODE_TAB) { |
| 3565 | // Don't consume TAB here since it's used for navigation. Arrow keys |
| 3566 | // aren't considered "typing keys" so they already won't get consumed. |
| 3567 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | } else { |
| 3569 | // Common code for DEFAULT_KEYS_DIALER & DEFAULT_KEYS_SEARCH_* |
| 3570 | boolean clearSpannable = false; |
| 3571 | boolean handled; |
| 3572 | if ((event.getRepeatCount() != 0) || event.isSystem()) { |
| 3573 | clearSpannable = true; |
| 3574 | handled = false; |
| 3575 | } else { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3576 | handled = TextKeyListener.getInstance().onKeyDown( |
| 3577 | null, mDefaultKeySsb, keyCode, event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3578 | if (handled && mDefaultKeySsb.length() > 0) { |
| 3579 | // something useable has been typed - dispatch it now. |
| 3580 | |
| 3581 | final String str = mDefaultKeySsb.toString(); |
| 3582 | clearSpannable = true; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3583 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3584 | switch (mDefaultKeyMode) { |
| 3585 | case DEFAULT_KEYS_DIALER: |
| 3586 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + str)); |
| 3587 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3588 | startActivity(intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3589 | break; |
| 3590 | case DEFAULT_KEYS_SEARCH_LOCAL: |
| 3591 | startSearch(str, false, null, false); |
| 3592 | break; |
| 3593 | case DEFAULT_KEYS_SEARCH_GLOBAL: |
| 3594 | startSearch(str, false, null, true); |
| 3595 | break; |
| 3596 | } |
| 3597 | } |
| 3598 | } |
| 3599 | if (clearSpannable) { |
| 3600 | mDefaultKeySsb.clear(); |
| 3601 | mDefaultKeySsb.clearSpans(); |
| 3602 | Selection.setSelection(mDefaultKeySsb,0); |
| 3603 | } |
| 3604 | return handled; |
| 3605 | } |
| 3606 | } |
| 3607 | |
| 3608 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3609 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 3610 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 3611 | * the event). |
Siarhei Vishniakou | ccf973f | 2018-10-30 14:04:57 -0700 | [diff] [blame] | 3612 | * |
| 3613 | * To receive this callback, you must return true from onKeyDown for the current |
| 3614 | * event stream. |
| 3615 | * |
| 3616 | * @see KeyEvent.Callback#onKeyLongPress() |
| 3617 | * @see KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3618 | */ |
| 3619 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 3620 | return false; |
| 3621 | } |
| 3622 | |
| 3623 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3624 | * Called when a key was released and not handled by any of the views |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3625 | * inside of the activity. So, for example, key presses while the cursor |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3626 | * is inside a TextView will not trigger the event (unless it is a navigation |
| 3627 | * to another object) because TextView handles its own key presses. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3628 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3629 | * <p>The default implementation handles KEYCODE_BACK to stop the activity |
| 3630 | * and go back. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3631 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3632 | * @return Return <code>true</code> to prevent this event from being propagated |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3633 | * further, or <code>false</code> to indicate that you have not handled |
| 3634 | * this event and it should continue to be propagated. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3635 | * @see #onKeyDown |
| 3636 | * @see KeyEvent |
| 3637 | */ |
| 3638 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3639 | if (getApplicationInfo().targetSdkVersion |
| 3640 | >= Build.VERSION_CODES.ECLAIR) { |
| 3641 | if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() |
| 3642 | && !event.isCanceled()) { |
| 3643 | onBackPressed(); |
| 3644 | return true; |
| 3645 | } |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3646 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3647 | return false; |
| 3648 | } |
| 3649 | |
| 3650 | /** |
| 3651 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 3652 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 3653 | * the event). |
| 3654 | */ |
| 3655 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 3656 | return false; |
| 3657 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3658 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3659 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3660 | * Called when the activity has detected the user's press of the back |
| 3661 | * key. The default implementation simply finishes the current activity, |
| 3662 | * but you can override this to do whatever you want. |
| 3663 | */ |
| 3664 | public void onBackPressed() { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3665 | if (mActionBar != null && mActionBar.collapseActionView()) { |
| 3666 | return; |
| 3667 | } |
| 3668 | |
George Mount | 27b0dc0 | 2017-02-21 10:24:09 -0800 | [diff] [blame] | 3669 | FragmentManager fragmentManager = mFragments.getFragmentManager(); |
| 3670 | |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 3671 | if (!fragmentManager.isStateSaved() && fragmentManager.popBackStackImmediate()) { |
| 3672 | return; |
| 3673 | } |
| 3674 | if (!isTaskRoot()) { |
| 3675 | // If the activity is not the root of the task, allow finish to proceed normally. |
| 3676 | finishAfterTransition(); |
| 3677 | return; |
| 3678 | } |
| 3679 | try { |
| 3680 | // Inform activity task manager that the activity received a back press |
| 3681 | // while at the root of the task. This call allows ActivityTaskManager |
| 3682 | // to intercept or defer finishing. |
| 3683 | ActivityTaskManager.getService().onBackPressedOnTaskRoot(mToken, |
| 3684 | new IRequestFinishCallback.Stub() { |
| 3685 | public void requestFinish() { |
Mady Mellor | 9d662c0 | 2019-05-23 07:09:18 -0700 | [diff] [blame] | 3686 | mHandler.post(() -> finishAfterTransition()); |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 3687 | } |
| 3688 | }); |
| 3689 | } catch (RemoteException e) { |
Craig Mautner | 73f843d | 2014-05-19 09:42:28 -0700 | [diff] [blame] | 3690 | finishAfterTransition(); |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 3691 | } |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3692 | } |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 3693 | |
| 3694 | /** |
| 3695 | * Called when a key shortcut event is not handled by any of the views in the Activity. |
| 3696 | * Override this method to implement global key shortcuts for the Activity. |
| 3697 | * Key shortcuts can also be implemented by setting the |
| 3698 | * {@link MenuItem#setShortcut(char, char) shortcut} property of menu items. |
| 3699 | * |
| 3700 | * @param keyCode The value in event.getKeyCode(). |
| 3701 | * @param event Description of the key event. |
| 3702 | * @return True if the key shortcut was handled. |
| 3703 | */ |
| 3704 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
Abodunrinwa Toki | a04b7ad | 2015-06-30 17:44:04 -0700 | [diff] [blame] | 3705 | // Let the Action Bar have a chance at handling the shortcut. |
| 3706 | ActionBar actionBar = getActionBar(); |
| 3707 | return (actionBar != null && actionBar.onKeyShortcut(keyCode, event)); |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 3708 | } |
| 3709 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3710 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3711 | * Called when a touch screen event was not handled by any of the views |
| 3712 | * under it. This is most useful to process touch events that happen |
| 3713 | * outside of your window bounds, where there is no view to receive it. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3714 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3715 | * @param event The touch screen event being processed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3716 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3717 | * @return Return true if you have consumed the event, false if you haven't. |
| 3718 | * The default implementation always returns false. |
| 3719 | */ |
| 3720 | public boolean onTouchEvent(MotionEvent event) { |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 3721 | if (mWindow.shouldCloseOnTouch(this, event)) { |
| 3722 | finish(); |
| 3723 | return true; |
| 3724 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3726 | return false; |
| 3727 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3728 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3729 | /** |
| 3730 | * Called when the trackball was moved and not handled by any of the |
| 3731 | * views inside of the activity. So, for example, if the trackball moves |
| 3732 | * while focus is on a button, you will receive a call here because |
| 3733 | * buttons do not normally do anything with trackball events. The call |
| 3734 | * here happens <em>before</em> trackball movements are converted to |
| 3735 | * DPAD key events, which then get sent back to the view hierarchy, and |
| 3736 | * will be processed at the point for things like focus navigation. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3737 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3738 | * @param event The trackball event being processed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3739 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3740 | * @return Return true if you have consumed the event, false if you haven't. |
| 3741 | * The default implementation always returns false. |
| 3742 | */ |
| 3743 | public boolean onTrackballEvent(MotionEvent event) { |
| 3744 | return false; |
| 3745 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3746 | |
| 3747 | /** |
| 3748 | * Called when a generic motion event was not handled by any of the |
| 3749 | * views inside of the activity. |
| 3750 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3751 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 3752 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3753 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 3754 | * the class of input that was received. Implementations of this method |
| 3755 | * must examine the bits in the source before processing the event. |
| 3756 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3757 | * </p><p> |
| 3758 | * Generic motion events with source class |
| 3759 | * {@link android.view.InputDevice#SOURCE_CLASS_POINTER} |
| 3760 | * are delivered to the view under the pointer. All other generic motion events are |
| 3761 | * delivered to the focused view. |
| 3762 | * </p><p> |
| 3763 | * See {@link View#onGenericMotionEvent(MotionEvent)} for an example of how to |
| 3764 | * handle this event. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3765 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3766 | * |
| 3767 | * @param event The generic motion event being processed. |
| 3768 | * |
| 3769 | * @return Return true if you have consumed the event, false if you haven't. |
| 3770 | * The default implementation always returns false. |
| 3771 | */ |
| 3772 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 3773 | return false; |
| 3774 | } |
| 3775 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3776 | /** |
| 3777 | * Called whenever a key, touch, or trackball event is dispatched to the |
| 3778 | * activity. Implement this method if you wish to know that the user has |
| 3779 | * interacted with the device in some way while your activity is running. |
| 3780 | * This callback and {@link #onUserLeaveHint} are intended to help |
| 3781 | * activities manage status bar notifications intelligently; specifically, |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 3782 | * for helping activities determine the proper time to cancel a notification. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3783 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3784 | * <p>All calls to your activity's {@link #onUserLeaveHint} callback will |
| 3785 | * be accompanied by calls to {@link #onUserInteraction}. This |
| 3786 | * ensures that your activity will be told of relevant user activity such |
| 3787 | * as pulling down the notification pane and touching an item there. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3788 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3789 | * <p>Note that this callback will be invoked for the touch down action |
| 3790 | * that begins a touch gesture, but may not be invoked for the touch-moved |
| 3791 | * and touch-up actions that follow. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3792 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3793 | * @see #onUserLeaveHint() |
| 3794 | */ |
| 3795 | public void onUserInteraction() { |
| 3796 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3798 | public void onWindowAttributesChanged(WindowManager.LayoutParams params) { |
| 3799 | // Update window manager if: we have a view, that view is |
| 3800 | // attached to its parent (which will be a RootView), and |
| 3801 | // this activity is not embedded. |
| 3802 | if (mParent == null) { |
| 3803 | View decor = mDecor; |
| 3804 | if (decor != null && decor.getParent() != null) { |
| 3805 | getWindowManager().updateViewLayout(decor, params); |
Adam He | 43c0699 | 2019-04-15 15:41:49 -0700 | [diff] [blame] | 3806 | if (mContentCaptureManager != null) { |
| 3807 | mContentCaptureManager.updateWindowAttributes(params); |
| 3808 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3809 | } |
| 3810 | } |
| 3811 | } |
| 3812 | |
| 3813 | public void onContentChanged() { |
| 3814 | } |
| 3815 | |
| 3816 | /** |
| 3817 | * Called when the current {@link Window} of the activity gains or loses |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 3818 | * focus. This is the best indicator of whether this activity is the entity |
| 3819 | * with which the user actively interacts. The default implementation |
| 3820 | * clears the key tracking state, so should always be called. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3821 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3822 | * <p>Note that this provides information about global focus state, which |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 3823 | * is managed independently of activity lifecycle. As such, while focus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3824 | * changes will generally have some relation to lifecycle changes (an |
| 3825 | * activity that is stopped will not generally get window focus), you |
| 3826 | * should not rely on any particular order between the callbacks here and |
| 3827 | * those in the other lifecycle methods such as {@link #onResume}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3828 | * |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 3829 | * <p>As a general rule, however, a foreground activity will have window |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3830 | * focus... unless it has displayed other dialogs or popups that take |
| 3831 | * input focus, in which case the activity itself will not have focus |
| 3832 | * when the other windows have it. Likewise, the system may display |
| 3833 | * system-level windows (such as the status bar notification panel or |
| 3834 | * a system alert) which will temporarily take window input focus without |
| 3835 | * pausing the foreground activity. |
| 3836 | * |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 3837 | * <p>Starting with {@link android.os.Build.VERSION_CODES#Q} there can be |
| 3838 | * multiple resumed activities at the same time in multi-window mode, so |
| 3839 | * resumed state does not guarantee window focus even if there are no |
| 3840 | * overlays above. |
| 3841 | * |
| 3842 | * <p>If the intent is to know when an activity is the topmost active, the |
| 3843 | * one the user interacted with last among all activities but not including |
| 3844 | * non-activity windows like dialogs and popups, then |
| 3845 | * {@link #onTopResumedActivityChanged(boolean)} should be used. On platform |
| 3846 | * versions prior to {@link android.os.Build.VERSION_CODES#Q}, |
| 3847 | * {@link #onResume} is the best indicator. |
| 3848 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3849 | * @param hasFocus Whether the window of this activity has focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3850 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3851 | * @see #hasWindowFocus() |
| 3852 | * @see #onResume |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3853 | * @see View#onWindowFocusChanged(boolean) |
Andrii Kulian | 8e4df1e | 2019-03-19 15:17:56 -0700 | [diff] [blame] | 3854 | * @see #onTopResumedActivityChanged(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3855 | */ |
| 3856 | public void onWindowFocusChanged(boolean hasFocus) { |
| 3857 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3858 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3859 | /** |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3860 | * Called when the main window associated with the activity has been |
| 3861 | * attached to the window manager. |
| 3862 | * See {@link View#onAttachedToWindow() View.onAttachedToWindow()} |
| 3863 | * for more information. |
| 3864 | * @see View#onAttachedToWindow |
| 3865 | */ |
| 3866 | public void onAttachedToWindow() { |
| 3867 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3868 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3869 | /** |
| 3870 | * Called when the main window associated with the activity has been |
| 3871 | * detached from the window manager. |
| 3872 | * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()} |
| 3873 | * for more information. |
| 3874 | * @see View#onDetachedFromWindow |
| 3875 | */ |
| 3876 | public void onDetachedFromWindow() { |
| 3877 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3878 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3879 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3880 | * Returns true if this activity's <em>main</em> window currently has window focus. |
| 3881 | * Note that this is not the same as the view itself having focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3882 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3883 | * @return True if this activity's main window currently has window focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3884 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3885 | * @see #onWindowAttributesChanged(android.view.WindowManager.LayoutParams) |
| 3886 | */ |
| 3887 | public boolean hasWindowFocus() { |
| 3888 | Window w = getWindow(); |
| 3889 | if (w != null) { |
| 3890 | View d = w.getDecorView(); |
| 3891 | if (d != null) { |
| 3892 | return d.hasWindowFocus(); |
| 3893 | } |
| 3894 | } |
| 3895 | return false; |
| 3896 | } |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3897 | |
| 3898 | /** |
| 3899 | * Called when the main window associated with the activity has been dismissed. |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 3900 | * @hide |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3901 | */ |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 3902 | @Override |
Ned Burns | 7d6cb91 | 2016-12-02 17:25:33 -0500 | [diff] [blame] | 3903 | public void onWindowDismissed(boolean finishTask, boolean suppressWindowTransition) { |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 3904 | finish(finishTask ? FINISH_TASK_WITH_ACTIVITY : DONT_FINISH_TASK_WITH_ACTIVITY); |
Ned Burns | 7d6cb91 | 2016-12-02 17:25:33 -0500 | [diff] [blame] | 3905 | if (suppressWindowTransition) { |
| 3906 | overridePendingTransition(0, 0); |
| 3907 | } |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3908 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3909 | |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3910 | |
Skuhne | ce2faa5 | 2015-08-11 10:36:38 -0700 | [diff] [blame] | 3911 | /** |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3912 | * Moves the activity between {@link WindowConfiguration#WINDOWING_MODE_FREEFORM} windowing mode |
| 3913 | * and {@link WindowConfiguration#WINDOWING_MODE_FULLSCREEN}. |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3914 | * |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3915 | * @hide |
| 3916 | */ |
| 3917 | @Override |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3918 | public void toggleFreeformWindowingMode() throws RemoteException { |
| 3919 | ActivityTaskManager.getService().toggleFreeformWindowingMode(mToken); |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3920 | } |
| 3921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3922 | /** |
Jaewan Kim | d98dcab | 2016-05-03 02:52:18 +0900 | [diff] [blame] | 3923 | * Puts the activity in picture-in-picture mode if the activity supports. |
| 3924 | * @see android.R.attr#supportsPictureInPicture |
| 3925 | * @hide |
| 3926 | */ |
| 3927 | @Override |
| 3928 | public void enterPictureInPictureModeIfPossible() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 3929 | if (mActivityInfo.supportsPictureInPicture()) { |
Jaewan Kim | d98dcab | 2016-05-03 02:52:18 +0900 | [diff] [blame] | 3930 | enterPictureInPictureMode(); |
| 3931 | } |
| 3932 | } |
| 3933 | |
| 3934 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3935 | * Called to process key events. You can override this to intercept all |
| 3936 | * key events before they are dispatched to the window. Be sure to call |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3937 | * this implementation for key events that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3938 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3939 | * @param event The key event. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3940 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3941 | * @return boolean Return true if this event was consumed. |
| 3942 | */ |
| 3943 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 3944 | onUserInteraction(); |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3945 | |
| 3946 | // Let action bars open menus in response to the menu key prioritized over |
| 3947 | // the window handling it |
George Mount | 5beb2617 | 2015-12-15 13:36:01 -0800 | [diff] [blame] | 3948 | final int keyCode = event.getKeyCode(); |
| 3949 | if (keyCode == KeyEvent.KEYCODE_MENU && |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3950 | mActionBar != null && mActionBar.onMenuKeyEvent(event)) { |
| 3951 | return true; |
| 3952 | } |
| 3953 | |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3954 | Window win = getWindow(); |
| 3955 | if (win.superDispatchKeyEvent(event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3956 | return true; |
| 3957 | } |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3958 | View decor = mDecor; |
| 3959 | if (decor == null) decor = win.getDecorView(); |
| 3960 | return event.dispatch(this, decor != null |
| 3961 | ? decor.getKeyDispatcherState() : null, this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3962 | } |
| 3963 | |
| 3964 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 3965 | * Called to process a key shortcut event. |
| 3966 | * You can override this to intercept all key shortcut events before they are |
| 3967 | * dispatched to the window. Be sure to call this implementation for key shortcut |
| 3968 | * events that should be handled normally. |
| 3969 | * |
| 3970 | * @param event The key shortcut event. |
| 3971 | * @return True if this event was consumed. |
| 3972 | */ |
| 3973 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 3974 | onUserInteraction(); |
| 3975 | if (getWindow().superDispatchKeyShortcutEvent(event)) { |
| 3976 | return true; |
| 3977 | } |
| 3978 | return onKeyShortcut(event.getKeyCode(), event); |
| 3979 | } |
| 3980 | |
| 3981 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3982 | * Called to process touch screen events. You can override this to |
| 3983 | * intercept all touch screen events before they are dispatched to the |
| 3984 | * window. Be sure to call this implementation for touch screen events |
| 3985 | * that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3986 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3987 | * @param ev The touch screen event. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3988 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3989 | * @return boolean Return true if this event was consumed. |
| 3990 | */ |
| 3991 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 3992 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 3993 | onUserInteraction(); |
| 3994 | } |
| 3995 | if (getWindow().superDispatchTouchEvent(ev)) { |
| 3996 | return true; |
| 3997 | } |
| 3998 | return onTouchEvent(ev); |
| 3999 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4001 | /** |
| 4002 | * Called to process trackball events. You can override this to |
| 4003 | * intercept all trackball events before they are dispatched to the |
| 4004 | * window. Be sure to call this implementation for trackball events |
| 4005 | * that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4006 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4007 | * @param ev The trackball event. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4008 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4009 | * @return boolean Return true if this event was consumed. |
| 4010 | */ |
| 4011 | public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 4012 | onUserInteraction(); |
| 4013 | if (getWindow().superDispatchTrackballEvent(ev)) { |
| 4014 | return true; |
| 4015 | } |
| 4016 | return onTrackballEvent(ev); |
| 4017 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4018 | |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4019 | /** |
| 4020 | * Called to process generic motion events. You can override this to |
| 4021 | * intercept all generic motion events before they are dispatched to the |
| 4022 | * window. Be sure to call this implementation for generic motion events |
| 4023 | * that should be handled normally. |
| 4024 | * |
| 4025 | * @param ev The generic motion event. |
| 4026 | * |
| 4027 | * @return boolean Return true if this event was consumed. |
| 4028 | */ |
| 4029 | public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 4030 | onUserInteraction(); |
| 4031 | if (getWindow().superDispatchGenericMotionEvent(ev)) { |
| 4032 | return true; |
| 4033 | } |
| 4034 | return onGenericMotionEvent(ev); |
| 4035 | } |
| 4036 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4037 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 4038 | event.setClassName(getClass().getName()); |
| 4039 | event.setPackageName(getPackageName()); |
| 4040 | |
| 4041 | LayoutParams params = getWindow().getAttributes(); |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 4042 | boolean isFullScreen = (params.width == LayoutParams.MATCH_PARENT) && |
| 4043 | (params.height == LayoutParams.MATCH_PARENT); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4044 | event.setFullScreen(isFullScreen); |
| 4045 | |
| 4046 | CharSequence title = getTitle(); |
| 4047 | if (!TextUtils.isEmpty(title)) { |
| 4048 | event.getText().add(title); |
| 4049 | } |
| 4050 | |
| 4051 | return true; |
| 4052 | } |
| 4053 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4054 | /** |
| 4055 | * Default implementation of |
| 4056 | * {@link android.view.Window.Callback#onCreatePanelView} |
| 4057 | * for activities. This |
| 4058 | * simply returns null so that all panel sub-windows will have the default |
| 4059 | * menu behavior. |
| 4060 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4061 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4062 | public View onCreatePanelView(int featureId) { |
| 4063 | return null; |
| 4064 | } |
| 4065 | |
| 4066 | /** |
| 4067 | * Default implementation of |
| 4068 | * {@link android.view.Window.Callback#onCreatePanelMenu} |
| 4069 | * for activities. This calls through to the new |
| 4070 | * {@link #onCreateOptionsMenu} method for the |
| 4071 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} panel, |
| 4072 | * so that subclasses of Activity don't need to deal with feature codes. |
| 4073 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 4074 | public boolean onCreatePanelMenu(int featureId, @NonNull Menu menu) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4075 | if (featureId == Window.FEATURE_OPTIONS_PANEL) { |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 4076 | boolean show = onCreateOptionsMenu(menu); |
| 4077 | show |= mFragments.dispatchCreateOptionsMenu(menu, getMenuInflater()); |
| 4078 | return show; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4079 | } |
| 4080 | return false; |
| 4081 | } |
| 4082 | |
| 4083 | /** |
| 4084 | * Default implementation of |
| 4085 | * {@link android.view.Window.Callback#onPreparePanel} |
| 4086 | * for activities. This |
| 4087 | * calls through to the new {@link #onPrepareOptionsMenu} method for the |
| 4088 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} |
| 4089 | * panel, so that subclasses of |
| 4090 | * Activity don't need to deal with feature codes. |
| 4091 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 4092 | public boolean onPreparePanel(int featureId, @Nullable View view, @NonNull Menu menu) { |
| 4093 | if (featureId == Window.FEATURE_OPTIONS_PANEL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4094 | boolean goforit = onPrepareOptionsMenu(menu); |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 4095 | goforit |= mFragments.dispatchPrepareOptionsMenu(menu); |
Adam Powell | ef31e7c | 2012-05-08 09:59:40 -0700 | [diff] [blame] | 4096 | return goforit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | } |
| 4098 | return true; |
| 4099 | } |
| 4100 | |
| 4101 | /** |
| 4102 | * {@inheritDoc} |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4103 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4104 | * @return The default implementation returns true. |
| 4105 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 4106 | @Override |
| 4107 | public boolean onMenuOpened(int featureId, @NonNull Menu menu) { |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 4108 | if (featureId == Window.FEATURE_ACTION_BAR) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 4109 | initWindowDecorActionBar(); |
Adam Powell | 049dd3d | 2010-12-02 13:43:59 -0800 | [diff] [blame] | 4110 | if (mActionBar != null) { |
| 4111 | mActionBar.dispatchMenuVisibilityChanged(true); |
| 4112 | } else { |
| 4113 | Log.e(TAG, "Tried to open action bar menu with no action bar"); |
| 4114 | } |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 4115 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4116 | return true; |
| 4117 | } |
| 4118 | |
| 4119 | /** |
| 4120 | * Default implementation of |
| 4121 | * {@link android.view.Window.Callback#onMenuItemSelected} |
| 4122 | * for activities. This calls through to the new |
| 4123 | * {@link #onOptionsItemSelected} method for the |
| 4124 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} |
| 4125 | * panel, so that subclasses of |
| 4126 | * Activity don't need to deal with feature codes. |
| 4127 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 4128 | public boolean onMenuItemSelected(int featureId, @NonNull MenuItem item) { |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 4129 | CharSequence titleCondensed = item.getTitleCondensed(); |
| 4130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4131 | switch (featureId) { |
| 4132 | case Window.FEATURE_OPTIONS_PANEL: |
| 4133 | // Put event logging here so it gets called even if subclass |
| 4134 | // doesn't call through to superclass's implmeentation of each |
| 4135 | // of these methods below |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 4136 | if(titleCondensed != null) { |
| 4137 | EventLog.writeEvent(50000, 0, titleCondensed.toString()); |
| 4138 | } |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 4139 | if (onOptionsItemSelected(item)) { |
| 4140 | return true; |
| 4141 | } |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 4142 | if (mFragments.dispatchOptionsItemSelected(item)) { |
| 4143 | return true; |
| 4144 | } |
| 4145 | if (item.getItemId() == android.R.id.home && mActionBar != null && |
| 4146 | (mActionBar.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) != 0) { |
| 4147 | if (mParent == null) { |
Adam Powell | 07304f529 | 2012-05-07 17:32:44 -0700 | [diff] [blame] | 4148 | return onNavigateUp(); |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 4149 | } else { |
Adam Powell | 07304f529 | 2012-05-07 17:32:44 -0700 | [diff] [blame] | 4150 | return mParent.onNavigateUpFromChild(this); |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 4151 | } |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 4152 | } |
| 4153 | return false; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4155 | case Window.FEATURE_CONTEXT_MENU: |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 4156 | if(titleCondensed != null) { |
| 4157 | EventLog.writeEvent(50000, 1, titleCondensed.toString()); |
| 4158 | } |
Dianne Hackborn | 5ddd127 | 2010-06-12 10:15:28 -0700 | [diff] [blame] | 4159 | if (onContextItemSelected(item)) { |
| 4160 | return true; |
| 4161 | } |
| 4162 | return mFragments.dispatchContextItemSelected(item); |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 4163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4164 | default: |
| 4165 | return false; |
| 4166 | } |
| 4167 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4169 | /** |
| 4170 | * Default implementation of |
| 4171 | * {@link android.view.Window.Callback#onPanelClosed(int, Menu)} for |
| 4172 | * activities. This calls through to {@link #onOptionsMenuClosed(Menu)} |
| 4173 | * method for the {@link android.view.Window#FEATURE_OPTIONS_PANEL} panel, |
| 4174 | * so that subclasses of Activity don't need to deal with feature codes. |
| 4175 | * For context menus ({@link Window#FEATURE_CONTEXT_MENU}), the |
| 4176 | * {@link #onContextMenuClosed(Menu)} will be called. |
| 4177 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 4178 | public void onPanelClosed(int featureId, @NonNull Menu menu) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4179 | switch (featureId) { |
| 4180 | case Window.FEATURE_OPTIONS_PANEL: |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 4181 | mFragments.dispatchOptionsMenuClosed(menu); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4182 | onOptionsMenuClosed(menu); |
| 4183 | break; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | case Window.FEATURE_CONTEXT_MENU: |
| 4186 | onContextMenuClosed(menu); |
| 4187 | break; |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 4188 | |
| 4189 | case Window.FEATURE_ACTION_BAR: |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 4190 | initWindowDecorActionBar(); |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 4191 | mActionBar.dispatchMenuVisibilityChanged(false); |
| 4192 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4193 | } |
| 4194 | } |
| 4195 | |
| 4196 | /** |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 4197 | * Declare that the options menu has changed, so should be recreated. |
| 4198 | * The {@link #onCreateOptionsMenu(Menu)} method will be called the next |
| 4199 | * time it needs to be displayed. |
| 4200 | */ |
| 4201 | public void invalidateOptionsMenu() { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 4202 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 4203 | (mActionBar == null || !mActionBar.invalidateOptionsMenu())) { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 4204 | mWindow.invalidatePanelMenu(Window.FEATURE_OPTIONS_PANEL); |
| 4205 | } |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 4206 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4207 | |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 4208 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4209 | * Initialize the contents of the Activity's standard options menu. You |
| 4210 | * should place your menu items in to <var>menu</var>. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4211 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4212 | * <p>This is only called once, the first time the options menu is |
| 4213 | * displayed. To update the menu every time it is displayed, see |
| 4214 | * {@link #onPrepareOptionsMenu}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4215 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4216 | * <p>The default implementation populates the menu with standard system |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4217 | * menu items. These are placed in the {@link Menu#CATEGORY_SYSTEM} group so that |
| 4218 | * they will be correctly ordered with application-defined menu items. |
| 4219 | * Deriving classes should always call through to the base implementation. |
| 4220 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4221 | * <p>You can safely hold on to <var>menu</var> (and any items created |
| 4222 | * from it), making modifications to it as desired, until the next |
| 4223 | * time onCreateOptionsMenu() is called. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4224 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4225 | * <p>When you add items to the menu, you can implement the Activity's |
| 4226 | * {@link #onOptionsItemSelected} method to handle them there. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4227 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4228 | * @param menu The options menu in which you place your items. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4229 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4230 | * @return You must return true for the menu to be displayed; |
| 4231 | * if you return false it will not be shown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4232 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4233 | * @see #onPrepareOptionsMenu |
| 4234 | * @see #onOptionsItemSelected |
| 4235 | */ |
| 4236 | public boolean onCreateOptionsMenu(Menu menu) { |
| 4237 | if (mParent != null) { |
| 4238 | return mParent.onCreateOptionsMenu(menu); |
| 4239 | } |
| 4240 | return true; |
| 4241 | } |
| 4242 | |
| 4243 | /** |
| 4244 | * Prepare the Screen's standard options menu to be displayed. This is |
| 4245 | * called right before the menu is shown, every time it is shown. You can |
| 4246 | * use this method to efficiently enable/disable items or otherwise |
| 4247 | * dynamically modify the contents. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4248 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4249 | * <p>The default implementation updates the system menu items based on the |
| 4250 | * activity's state. Deriving classes should always call through to the |
| 4251 | * base class implementation. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4252 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4253 | * @param menu The options menu as last shown or first initialized by |
| 4254 | * onCreateOptionsMenu(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4255 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4256 | * @return You must return true for the menu to be displayed; |
| 4257 | * if you return false it will not be shown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4258 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4259 | * @see #onCreateOptionsMenu |
| 4260 | */ |
| 4261 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 4262 | if (mParent != null) { |
| 4263 | return mParent.onPrepareOptionsMenu(menu); |
| 4264 | } |
| 4265 | return true; |
| 4266 | } |
| 4267 | |
| 4268 | /** |
| 4269 | * This hook is called whenever an item in your options menu is selected. |
| 4270 | * The default implementation simply returns false to have the normal |
| 4271 | * processing happen (calling the item's Runnable or sending a message to |
| 4272 | * its Handler as appropriate). You can use this method for any items |
| 4273 | * for which you would like to do processing without those other |
| 4274 | * facilities. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4275 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4276 | * <p>Derived classes should call through to the base class for it to |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4277 | * perform the default menu handling.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4278 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4279 | * @param item The menu item that was selected. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4280 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4281 | * @return boolean Return false to allow normal menu processing to |
| 4282 | * proceed, true to consume it here. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4283 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4284 | * @see #onCreateOptionsMenu |
| 4285 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 4286 | public boolean onOptionsItemSelected(@NonNull MenuItem item) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4287 | if (mParent != null) { |
| 4288 | return mParent.onOptionsItemSelected(item); |
| 4289 | } |
| 4290 | return false; |
| 4291 | } |
| 4292 | |
| 4293 | /** |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4294 | * This method is called whenever the user chooses to navigate Up within your application's |
| 4295 | * activity hierarchy from the action bar. |
| 4296 | * |
| 4297 | * <p>If the attribute {@link android.R.attr#parentActivityName parentActivityName} |
| 4298 | * was specified in the manifest for this activity or an activity-alias to it, |
| 4299 | * default Up navigation will be handled automatically. If any activity |
| 4300 | * along the parent chain requires extra Intent arguments, the Activity subclass |
| 4301 | * should override the method {@link #onPrepareNavigateUpTaskStack(TaskStackBuilder)} |
| 4302 | * to supply those arguments.</p> |
| 4303 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 4304 | * <p>See <a href="{@docRoot}guide/components/tasks-and-back-stack.html">Tasks and Back Stack</a> |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4305 | * from the developer guide and <a href="{@docRoot}design/patterns/navigation.html">Navigation</a> |
| 4306 | * from the design guide for more information about navigating within your app.</p> |
| 4307 | * |
| 4308 | * <p>See the {@link TaskStackBuilder} class and the Activity methods |
| 4309 | * {@link #getParentActivityIntent()}, {@link #shouldUpRecreateTask(Intent)}, and |
| 4310 | * {@link #navigateUpTo(Intent)} for help implementing custom Up navigation. |
| 4311 | * The AppNavigation sample application in the Android SDK is also available for reference.</p> |
| 4312 | * |
| 4313 | * @return true if Up navigation completed successfully and this Activity was finished, |
| 4314 | * false otherwise. |
| 4315 | */ |
| 4316 | public boolean onNavigateUp() { |
| 4317 | // Automatically handle hierarchical Up navigation if the proper |
| 4318 | // metadata is available. |
| 4319 | Intent upIntent = getParentActivityIntent(); |
| 4320 | if (upIntent != null) { |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 4321 | if (mActivityInfo.taskAffinity == null) { |
| 4322 | // Activities with a null affinity are special; they really shouldn't |
| 4323 | // specify a parent activity intent in the first place. Just finish |
| 4324 | // the current activity and call it a day. |
| 4325 | finish(); |
| 4326 | } else if (shouldUpRecreateTask(upIntent)) { |
Adam Powell | f78a844 | 2012-05-01 18:09:32 -0700 | [diff] [blame] | 4327 | TaskStackBuilder b = TaskStackBuilder.create(this); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4328 | onCreateNavigateUpTaskStack(b); |
| 4329 | onPrepareNavigateUpTaskStack(b); |
| 4330 | b.startActivities(); |
Adam Powell | 3d193d9 | 2012-05-15 16:51:55 -0700 | [diff] [blame] | 4331 | |
| 4332 | // We can't finishAffinity if we have a result. |
| 4333 | // Fall back and simply finish the current activity instead. |
| 4334 | if (mResultCode != RESULT_CANCELED || mResultData != null) { |
| 4335 | // Tell the developer what's going on to avoid hair-pulling. |
| 4336 | Log.i(TAG, "onNavigateUp only finishing topmost activity to return a result"); |
| 4337 | finish(); |
| 4338 | } else { |
| 4339 | finishAffinity(); |
| 4340 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4341 | } else { |
| 4342 | navigateUpTo(upIntent); |
| 4343 | } |
| 4344 | return true; |
| 4345 | } |
| 4346 | return false; |
| 4347 | } |
| 4348 | |
| 4349 | /** |
| 4350 | * This is called when a child activity of this one attempts to navigate up. |
| 4351 | * The default implementation simply calls onNavigateUp() on this activity (the parent). |
| 4352 | * |
| 4353 | * @param child The activity making the call. |
| 4354 | */ |
| 4355 | public boolean onNavigateUpFromChild(Activity child) { |
| 4356 | return onNavigateUp(); |
| 4357 | } |
| 4358 | |
| 4359 | /** |
| 4360 | * Define the synthetic task stack that will be generated during Up navigation from |
| 4361 | * a different task. |
| 4362 | * |
| 4363 | * <p>The default implementation of this method adds the parent chain of this activity |
| 4364 | * as specified in the manifest to the supplied {@link TaskStackBuilder}. Applications |
| 4365 | * may choose to override this method to construct the desired task stack in a different |
| 4366 | * way.</p> |
| 4367 | * |
Adam Powell | f019595 | 2012-05-02 21:38:54 -0700 | [diff] [blame] | 4368 | * <p>This method will be invoked by the default implementation of {@link #onNavigateUp()} |
| 4369 | * if {@link #shouldUpRecreateTask(Intent)} returns true when supplied with the intent |
| 4370 | * returned by {@link #getParentActivityIntent()}.</p> |
| 4371 | * |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4372 | * <p>Applications that wish to supply extra Intent parameters to the parent stack defined |
| 4373 | * by the manifest should override {@link #onPrepareNavigateUpTaskStack(TaskStackBuilder)}.</p> |
| 4374 | * |
| 4375 | * @param builder An empty TaskStackBuilder - the application should add intents representing |
| 4376 | * the desired task stack |
| 4377 | */ |
| 4378 | public void onCreateNavigateUpTaskStack(TaskStackBuilder builder) { |
| 4379 | builder.addParentStack(this); |
| 4380 | } |
| 4381 | |
| 4382 | /** |
| 4383 | * Prepare the synthetic task stack that will be generated during Up navigation |
| 4384 | * from a different task. |
| 4385 | * |
| 4386 | * <p>This method receives the {@link TaskStackBuilder} with the constructed series of |
| 4387 | * Intents as generated by {@link #onCreateNavigateUpTaskStack(TaskStackBuilder)}. |
| 4388 | * If any extra data should be added to these intents before launching the new task, |
| 4389 | * the application should override this method and add that data here.</p> |
| 4390 | * |
| 4391 | * @param builder A TaskStackBuilder that has been populated with Intents by |
| 4392 | * onCreateNavigateUpTaskStack. |
| 4393 | */ |
| 4394 | public void onPrepareNavigateUpTaskStack(TaskStackBuilder builder) { |
| 4395 | } |
| 4396 | |
| 4397 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4398 | * This hook is called whenever the options menu is being closed (either by the user canceling |
| 4399 | * the menu with the back/menu button, or when an item is selected). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4400 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4401 | * @param menu The options menu as last shown or first initialized by |
| 4402 | * onCreateOptionsMenu(). |
| 4403 | */ |
| 4404 | public void onOptionsMenuClosed(Menu menu) { |
| 4405 | if (mParent != null) { |
| 4406 | mParent.onOptionsMenuClosed(menu); |
| 4407 | } |
| 4408 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4410 | /** |
| 4411 | * Programmatically opens the options menu. If the options menu is already |
| 4412 | * open, this method does nothing. |
| 4413 | */ |
| 4414 | public void openOptionsMenu() { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 4415 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 4416 | (mActionBar == null || !mActionBar.openOptionsMenu())) { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 4417 | mWindow.openPanel(Window.FEATURE_OPTIONS_PANEL, null); |
| 4418 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4419 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4420 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4421 | /** |
| 4422 | * Progammatically closes the options menu. If the options menu is already |
| 4423 | * closed, this method does nothing. |
| 4424 | */ |
| 4425 | public void closeOptionsMenu() { |
Evan Rosky | 41823d1 | 2017-03-21 14:42:35 -0700 | [diff] [blame] | 4426 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 4427 | (mActionBar == null || !mActionBar.closeOptionsMenu())) { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 4428 | mWindow.closePanel(Window.FEATURE_OPTIONS_PANEL); |
| 4429 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4430 | } |
| 4431 | |
| 4432 | /** |
| 4433 | * Called when a context menu for the {@code view} is about to be shown. |
| 4434 | * Unlike {@link #onCreateOptionsMenu(Menu)}, this will be called every |
| 4435 | * time the context menu is about to be shown and should be populated for |
| 4436 | * the view (or item inside the view for {@link AdapterView} subclasses, |
| 4437 | * this can be found in the {@code menuInfo})). |
| 4438 | * <p> |
| 4439 | * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an |
| 4440 | * item has been selected. |
| 4441 | * <p> |
| 4442 | * It is not safe to hold onto the context menu after this method returns. |
Scott Main | cdf5106 | 2013-01-08 20:03:05 -0800 | [diff] [blame] | 4443 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4444 | */ |
| 4445 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { |
| 4446 | } |
| 4447 | |
| 4448 | /** |
| 4449 | * Registers a context menu to be shown for the given view (multiple views |
| 4450 | * can show the context menu). This method will set the |
| 4451 | * {@link OnCreateContextMenuListener} on the view to this activity, so |
| 4452 | * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be |
| 4453 | * called when it is time to show the context menu. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4454 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4455 | * @see #unregisterForContextMenu(View) |
| 4456 | * @param view The view that should show a context menu. |
| 4457 | */ |
| 4458 | public void registerForContextMenu(View view) { |
| 4459 | view.setOnCreateContextMenuListener(this); |
| 4460 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4461 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4462 | /** |
| 4463 | * Prevents a context menu to be shown for the given view. This method will remove the |
| 4464 | * {@link OnCreateContextMenuListener} on the view. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4465 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4466 | * @see #registerForContextMenu(View) |
| 4467 | * @param view The view that should stop showing a context menu. |
| 4468 | */ |
| 4469 | public void unregisterForContextMenu(View view) { |
| 4470 | view.setOnCreateContextMenuListener(null); |
| 4471 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4472 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4473 | /** |
| 4474 | * Programmatically opens the context menu for a particular {@code view}. |
| 4475 | * The {@code view} should have been added via |
| 4476 | * {@link #registerForContextMenu(View)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4477 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4478 | * @param view The view to show the context menu for. |
| 4479 | */ |
| 4480 | public void openContextMenu(View view) { |
| 4481 | view.showContextMenu(); |
| 4482 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4484 | /** |
| 4485 | * Programmatically closes the most recently opened context menu, if showing. |
| 4486 | */ |
| 4487 | public void closeContextMenu() { |
Jose Lima | bd769a1 | 2015-01-28 10:43:15 -0800 | [diff] [blame] | 4488 | if (mWindow.hasFeature(Window.FEATURE_CONTEXT_MENU)) { |
| 4489 | mWindow.closePanel(Window.FEATURE_CONTEXT_MENU); |
| 4490 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4491 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4493 | /** |
| 4494 | * This hook is called whenever an item in a context menu is selected. The |
| 4495 | * default implementation simply returns false to have the normal processing |
| 4496 | * happen (calling the item's Runnable or sending a message to its Handler |
| 4497 | * as appropriate). You can use this method for any items for which you |
| 4498 | * would like to do processing without those other facilities. |
| 4499 | * <p> |
| 4500 | * Use {@link MenuItem#getMenuInfo()} to get extra information set by the |
| 4501 | * View that added this menu item. |
| 4502 | * <p> |
| 4503 | * Derived classes should call through to the base class for it to perform |
| 4504 | * the default menu handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4505 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4506 | * @param item The context menu item that was selected. |
| 4507 | * @return boolean Return false to allow normal context menu processing to |
| 4508 | * proceed, true to consume it here. |
| 4509 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 4510 | public boolean onContextItemSelected(@NonNull MenuItem item) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4511 | if (mParent != null) { |
| 4512 | return mParent.onContextItemSelected(item); |
| 4513 | } |
| 4514 | return false; |
| 4515 | } |
| 4516 | |
| 4517 | /** |
| 4518 | * This hook is called whenever the context menu is being closed (either by |
| 4519 | * the user canceling the menu with the back/menu button, or when an item is |
| 4520 | * selected). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4521 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4522 | * @param menu The context menu that is being closed. |
| 4523 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 4524 | public void onContextMenuClosed(@NonNull Menu menu) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4525 | if (mParent != null) { |
| 4526 | mParent.onContextMenuClosed(menu); |
| 4527 | } |
| 4528 | } |
| 4529 | |
| 4530 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4531 | * @deprecated Old no-arguments version of {@link #onCreateDialog(int, Bundle)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4532 | */ |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4533 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4534 | protected Dialog onCreateDialog(int id) { |
| 4535 | return null; |
| 4536 | } |
| 4537 | |
| 4538 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4539 | * Callback for creating dialogs that are managed (saved and restored) for you |
| 4540 | * by the activity. The default implementation calls through to |
| 4541 | * {@link #onCreateDialog(int)} for compatibility. |
| 4542 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 4543 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 4544 | * or later, consider instead using a {@link DialogFragment} instead.</em> |
| 4545 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4546 | * <p>If you use {@link #showDialog(int)}, the activity will call through to |
| 4547 | * this method the first time, and hang onto it thereafter. Any dialog |
| 4548 | * that is created by this method will automatically be saved and restored |
| 4549 | * for you, including whether it is showing. |
| 4550 | * |
| 4551 | * <p>If you would like the activity to manage saving and restoring dialogs |
| 4552 | * for you, you should override this method and handle any ids that are |
| 4553 | * passed to {@link #showDialog}. |
| 4554 | * |
| 4555 | * <p>If you would like an opportunity to prepare your dialog before it is shown, |
| 4556 | * override {@link #onPrepareDialog(int, Dialog, Bundle)}. |
| 4557 | * |
| 4558 | * @param id The id of the dialog. |
| 4559 | * @param args The dialog arguments provided to {@link #showDialog(int, Bundle)}. |
| 4560 | * @return The dialog. If you return null, the dialog will not be created. |
| 4561 | * |
| 4562 | * @see #onPrepareDialog(int, Dialog, Bundle) |
| 4563 | * @see #showDialog(int, Bundle) |
| 4564 | * @see #dismissDialog(int) |
| 4565 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4566 | * |
| 4567 | * @deprecated Use the new {@link DialogFragment} class with |
| 4568 | * {@link FragmentManager} instead; this is also |
| 4569 | * available on older platforms through the Android compatibility package. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4570 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4571 | @Nullable |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4572 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4573 | protected Dialog onCreateDialog(int id, Bundle args) { |
| 4574 | return onCreateDialog(id); |
| 4575 | } |
| 4576 | |
| 4577 | /** |
| 4578 | * @deprecated Old no-arguments version of |
| 4579 | * {@link #onPrepareDialog(int, Dialog, Bundle)}. |
| 4580 | */ |
| 4581 | @Deprecated |
| 4582 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 4583 | dialog.setOwnerActivity(this); |
| 4584 | } |
| 4585 | |
| 4586 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4587 | * Provides an opportunity to prepare a managed dialog before it is being |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4588 | * shown. The default implementation calls through to |
| 4589 | * {@link #onPrepareDialog(int, Dialog)} for compatibility. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4590 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4591 | * <p> |
| 4592 | * Override this if you need to update a managed dialog based on the state |
| 4593 | * of the application each time it is shown. For example, a time picker |
| 4594 | * dialog might want to be updated with the current time. You should call |
| 4595 | * through to the superclass's implementation. The default implementation |
| 4596 | * will set this Activity as the owner activity on the Dialog. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4597 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4598 | * @param id The id of the managed dialog. |
| 4599 | * @param dialog The dialog. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4600 | * @param args The dialog arguments provided to {@link #showDialog(int, Bundle)}. |
| 4601 | * @see #onCreateDialog(int, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4602 | * @see #showDialog(int) |
| 4603 | * @see #dismissDialog(int) |
| 4604 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4605 | * |
| 4606 | * @deprecated Use the new {@link DialogFragment} class with |
| 4607 | * {@link FragmentManager} instead; this is also |
| 4608 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4609 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4610 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4611 | protected void onPrepareDialog(int id, Dialog dialog, Bundle args) { |
| 4612 | onPrepareDialog(id, dialog); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4613 | } |
| 4614 | |
| 4615 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4616 | * Simple version of {@link #showDialog(int, Bundle)} that does not |
| 4617 | * take any arguments. Simply calls {@link #showDialog(int, Bundle)} |
| 4618 | * with null arguments. |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4619 | * |
| 4620 | * @deprecated Use the new {@link DialogFragment} class with |
| 4621 | * {@link FragmentManager} instead; this is also |
| 4622 | * available on older platforms through the Android compatibility package. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4623 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4624 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4625 | public final void showDialog(int id) { |
| 4626 | showDialog(id, null); |
| 4627 | } |
| 4628 | |
| 4629 | /** |
| 4630 | * Show a dialog managed by this activity. A call to {@link #onCreateDialog(int, Bundle)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4631 | * will be made with the same id the first time this is called for a given |
| 4632 | * id. From thereafter, the dialog will be automatically saved and restored. |
| 4633 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 4634 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 4635 | * or later, consider instead using a {@link DialogFragment} instead.</em> |
| 4636 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4637 | * <p>Each time a dialog is shown, {@link #onPrepareDialog(int, Dialog, Bundle)} will |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4638 | * be made to provide an opportunity to do any timely preparation. |
| 4639 | * |
| 4640 | * @param id The id of the managed dialog. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4641 | * @param args Arguments to pass through to the dialog. These will be saved |
| 4642 | * and restored for you. Note that if the dialog is already created, |
| 4643 | * {@link #onCreateDialog(int, Bundle)} will not be called with the new |
| 4644 | * arguments but {@link #onPrepareDialog(int, Dialog, Bundle)} will be. |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 4645 | * If you need to rebuild the dialog, call {@link #removeDialog(int)} first. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4646 | * @return Returns true if the Dialog was created; false is returned if |
| 4647 | * it is not created because {@link #onCreateDialog(int, Bundle)} returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4648 | * |
Joe Onorato | 37296dc | 2009-07-31 17:58:55 -0700 | [diff] [blame] | 4649 | * @see Dialog |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4650 | * @see #onCreateDialog(int, Bundle) |
| 4651 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4652 | * @see #dismissDialog(int) |
| 4653 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4654 | * |
| 4655 | * @deprecated Use the new {@link DialogFragment} class with |
| 4656 | * {@link FragmentManager} instead; this is also |
| 4657 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4658 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4659 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4660 | public final boolean showDialog(int id, Bundle args) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4661 | if (mManagedDialogs == null) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4662 | mManagedDialogs = new SparseArray<ManagedDialog>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4663 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4664 | ManagedDialog md = mManagedDialogs.get(id); |
| 4665 | if (md == null) { |
| 4666 | md = new ManagedDialog(); |
| 4667 | md.mDialog = createDialog(id, null, args); |
| 4668 | if (md.mDialog == null) { |
| 4669 | return false; |
| 4670 | } |
| 4671 | mManagedDialogs.put(id, md); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4672 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4673 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4674 | md.mArgs = args; |
| 4675 | onPrepareDialog(id, md.mDialog, args); |
| 4676 | md.mDialog.show(); |
| 4677 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4678 | } |
| 4679 | |
| 4680 | /** |
| 4681 | * Dismiss a dialog that was previously shown via {@link #showDialog(int)}. |
| 4682 | * |
| 4683 | * @param id The id of the managed dialog. |
| 4684 | * |
| 4685 | * @throws IllegalArgumentException if the id was not previously shown via |
| 4686 | * {@link #showDialog(int)}. |
| 4687 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4688 | * @see #onCreateDialog(int, Bundle) |
| 4689 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4690 | * @see #showDialog(int) |
| 4691 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4692 | * |
| 4693 | * @deprecated Use the new {@link DialogFragment} class with |
| 4694 | * {@link FragmentManager} instead; this is also |
| 4695 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4696 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4697 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4698 | public final void dismissDialog(int id) { |
| 4699 | if (mManagedDialogs == null) { |
| 4700 | throw missingDialog(id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4701 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4702 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4703 | final ManagedDialog md = mManagedDialogs.get(id); |
| 4704 | if (md == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4705 | throw missingDialog(id); |
| 4706 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4707 | md.mDialog.dismiss(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4708 | } |
| 4709 | |
| 4710 | /** |
| 4711 | * Creates an exception to throw if a user passed in a dialog id that is |
| 4712 | * unexpected. |
| 4713 | */ |
| 4714 | private IllegalArgumentException missingDialog(int id) { |
| 4715 | return new IllegalArgumentException("no dialog with id " + id + " was ever " |
| 4716 | + "shown via Activity#showDialog"); |
| 4717 | } |
| 4718 | |
| 4719 | /** |
| 4720 | * Removes any internal references to a dialog managed by this Activity. |
| 4721 | * If the dialog is showing, it will dismiss it as part of the clean up. |
| 4722 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4723 | * <p>This can be useful if you know that you will never show a dialog again and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4724 | * want to avoid the overhead of saving and restoring it in the future. |
| 4725 | * |
Dianne Hackborn | d2ce8bbb | 2010-10-06 16:46:05 -0700 | [diff] [blame] | 4726 | * <p>As of {@link android.os.Build.VERSION_CODES#GINGERBREAD}, this function |
| 4727 | * will not throw an exception if you try to remove an ID that does not |
| 4728 | * currently have an associated dialog.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4729 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4730 | * @param id The id of the managed dialog. |
| 4731 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4732 | * @see #onCreateDialog(int, Bundle) |
| 4733 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4734 | * @see #showDialog(int) |
| 4735 | * @see #dismissDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4736 | * |
| 4737 | * @deprecated Use the new {@link DialogFragment} class with |
| 4738 | * {@link FragmentManager} instead; this is also |
| 4739 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4740 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4741 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4742 | public final void removeDialog(int id) { |
Dianne Hackborn | d2ce8bbb | 2010-10-06 16:46:05 -0700 | [diff] [blame] | 4743 | if (mManagedDialogs != null) { |
| 4744 | final ManagedDialog md = mManagedDialogs.get(id); |
| 4745 | if (md != null) { |
| 4746 | md.mDialog.dismiss(); |
| 4747 | mManagedDialogs.remove(id); |
| 4748 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4749 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | /** |
| 4753 | * This hook is called when the user signals the desire to start a search. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4754 | * |
Bjorn Bringert | 6266e40 | 2009-09-25 14:25:41 +0100 | [diff] [blame] | 4755 | * <p>You can use this function as a simple way to launch the search UI, in response to a |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4756 | * menu item, search button, or other widgets within your activity. Unless overidden, |
Bjorn Bringert | 6266e40 | 2009-09-25 14:25:41 +0100 | [diff] [blame] | 4757 | * calling this function is the same as calling |
| 4758 | * {@link #startSearch startSearch(null, false, null, false)}, which launches |
| 4759 | * search for the current activity as specified in its manifest, see {@link SearchManager}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4760 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4761 | * <p>You can override this function to force global search, e.g. in response to a dedicated |
| 4762 | * search key, or to block search entirely (by simply returning false). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4763 | * |
Erik Wolsheimer | ac5cecd | 2017-12-05 13:11:50 -0800 | [diff] [blame] | 4764 | * <p>Note: when running in a {@link Configuration#UI_MODE_TYPE_TELEVISION} or |
| 4765 | * {@link Configuration#UI_MODE_TYPE_WATCH}, the default implementation changes to simply |
| 4766 | * return false and you must supply your own custom implementation if you want to support |
| 4767 | * search. |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 4768 | * |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 4769 | * @param searchEvent The {@link SearchEvent} that signaled this search. |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 4770 | * @return Returns {@code true} if search launched, and {@code false} if the activity does |
| 4771 | * not respond to search. The default implementation always returns {@code true}, except |
| 4772 | * when in {@link Configuration#UI_MODE_TYPE_TELEVISION} mode where it returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4773 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4774 | * @see android.app.SearchManager |
| 4775 | */ |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 4776 | public boolean onSearchRequested(@Nullable SearchEvent searchEvent) { |
| 4777 | mSearchEvent = searchEvent; |
| 4778 | boolean result = onSearchRequested(); |
| 4779 | mSearchEvent = null; |
| 4780 | return result; |
| 4781 | } |
| 4782 | |
| 4783 | /** |
| 4784 | * @see #onSearchRequested(SearchEvent) |
| 4785 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4786 | public boolean onSearchRequested() { |
Erik Wolsheimer | ac5cecd | 2017-12-05 13:11:50 -0800 | [diff] [blame] | 4787 | final int uiMode = getResources().getConfiguration().uiMode |
| 4788 | & Configuration.UI_MODE_TYPE_MASK; |
| 4789 | if (uiMode != Configuration.UI_MODE_TYPE_TELEVISION |
| 4790 | && uiMode != Configuration.UI_MODE_TYPE_WATCH) { |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 4791 | startSearch(null, false, null, false); |
| 4792 | return true; |
| 4793 | } else { |
| 4794 | return false; |
| 4795 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4796 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4798 | /** |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 4799 | * During the onSearchRequested() callbacks, this function will return the |
| 4800 | * {@link SearchEvent} that triggered the callback, if it exists. |
| 4801 | * |
| 4802 | * @return SearchEvent The SearchEvent that triggered the {@link |
| 4803 | * #onSearchRequested} callback. |
| 4804 | */ |
| 4805 | public final SearchEvent getSearchEvent() { |
| 4806 | return mSearchEvent; |
| 4807 | } |
| 4808 | |
| 4809 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4810 | * This hook is called to launch the search UI. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4811 | * |
| 4812 | * <p>It is typically called from onSearchRequested(), either directly from |
| 4813 | * Activity.onSearchRequested() or from an overridden version in any given |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4814 | * Activity. If your goal is simply to activate search, it is preferred to call |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4815 | * onSearchRequested(), which may have been overridden elsewhere in your Activity. If your goal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4816 | * is to inject specific data such as context data, it is preferred to <i>override</i> |
| 4817 | * onSearchRequested(), so that any callers to it will benefit from the override. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4818 | * |
Erik Wolsheimer | ac5cecd | 2017-12-05 13:11:50 -0800 | [diff] [blame] | 4819 | * <p>Note: when running in a {@link Configuration#UI_MODE_TYPE_WATCH}, use of this API is |
| 4820 | * not supported. |
| 4821 | * |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4822 | * @param initialQuery Any non-null non-empty string will be inserted as |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4823 | * pre-entered text in the search query box. |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4824 | * @param selectInitialQuery If true, the initial query will be preselected, which means that |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4825 | * any further typing will replace it. This is useful for cases where an entire pre-formed |
| 4826 | * query is being inserted. If false, the selection point will be placed at the end of the |
| 4827 | * inserted query. This is useful when the inserted query is text that the user entered, |
| 4828 | * and the user would expect to be able to keep typing. <i>This parameter is only meaningful |
| 4829 | * if initialQuery is a non-empty string.</i> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4830 | * @param appSearchData An application can insert application-specific |
| 4831 | * context here, in order to improve quality or specificity of its own |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4832 | * searches. This data will be returned with SEARCH intent(s). Null if |
| 4833 | * no extra data is required. |
| 4834 | * @param globalSearch If false, this will only launch the search that has been specifically |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4835 | * defined by the application (which is usually defined as a local search). If no default |
Mike LeBeau | cfa419b | 2009-08-17 10:56:02 -0700 | [diff] [blame] | 4836 | * search is defined in the current application or activity, global search will be launched. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4837 | * If true, this will always launch a platform-global (e.g. web-based) search instead. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4838 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4839 | * @see android.app.SearchManager |
| 4840 | * @see #onSearchRequested |
| 4841 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4842 | public void startSearch(@Nullable String initialQuery, boolean selectInitialQuery, |
| 4843 | @Nullable Bundle appSearchData, boolean globalSearch) { |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 4844 | ensureSearchManager(); |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 4845 | mSearchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4846 | appSearchData, globalSearch); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | /** |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4850 | * Similar to {@link #startSearch}, but actually fires off the search query after invoking |
| 4851 | * the search dialog. Made available for testing purposes. |
| 4852 | * |
| 4853 | * @param query The query to trigger. If empty, the request will be ignored. |
| 4854 | * @param appSearchData An application can insert application-specific |
| 4855 | * context here, in order to improve quality or specificity of its own |
| 4856 | * searches. This data will be returned with SEARCH intent(s). Null if |
| 4857 | * no extra data is required. |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4858 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4859 | public void triggerSearch(String query, @Nullable Bundle appSearchData) { |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4860 | ensureSearchManager(); |
Bjorn Bringert | b782a2f | 2009-10-01 09:57:33 +0100 | [diff] [blame] | 4861 | mSearchManager.triggerSearch(query, getComponentName(), appSearchData); |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4862 | } |
| 4863 | |
| 4864 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4865 | * Request that key events come to this activity. Use this if your |
| 4866 | * activity has no views with focus, but the activity still wants |
| 4867 | * a chance to process key events. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4868 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4869 | * @see android.view.Window#takeKeyEvents |
| 4870 | */ |
| 4871 | public void takeKeyEvents(boolean get) { |
| 4872 | getWindow().takeKeyEvents(get); |
| 4873 | } |
| 4874 | |
| 4875 | /** |
| 4876 | * Enable extended window features. This is a convenience for calling |
| 4877 | * {@link android.view.Window#requestFeature getWindow().requestFeature()}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4878 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4879 | * @param featureId The desired feature as defined in |
| 4880 | * {@link android.view.Window}. |
| 4881 | * @return Returns true if the requested feature is supported and now |
| 4882 | * enabled. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4883 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4884 | * @see android.view.Window#requestFeature |
| 4885 | */ |
| 4886 | public final boolean requestWindowFeature(int featureId) { |
| 4887 | return getWindow().requestFeature(featureId); |
| 4888 | } |
| 4889 | |
| 4890 | /** |
| 4891 | * Convenience for calling |
| 4892 | * {@link android.view.Window#setFeatureDrawableResource}. |
| 4893 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 4894 | public final void setFeatureDrawableResource(int featureId, @DrawableRes int resId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4895 | getWindow().setFeatureDrawableResource(featureId, resId); |
| 4896 | } |
| 4897 | |
| 4898 | /** |
| 4899 | * Convenience for calling |
| 4900 | * {@link android.view.Window#setFeatureDrawableUri}. |
| 4901 | */ |
| 4902 | public final void setFeatureDrawableUri(int featureId, Uri uri) { |
| 4903 | getWindow().setFeatureDrawableUri(featureId, uri); |
| 4904 | } |
| 4905 | |
| 4906 | /** |
| 4907 | * Convenience for calling |
| 4908 | * {@link android.view.Window#setFeatureDrawable(int, Drawable)}. |
| 4909 | */ |
| 4910 | public final void setFeatureDrawable(int featureId, Drawable drawable) { |
| 4911 | getWindow().setFeatureDrawable(featureId, drawable); |
| 4912 | } |
| 4913 | |
| 4914 | /** |
| 4915 | * Convenience for calling |
| 4916 | * {@link android.view.Window#setFeatureDrawableAlpha}. |
| 4917 | */ |
| 4918 | public final void setFeatureDrawableAlpha(int featureId, int alpha) { |
| 4919 | getWindow().setFeatureDrawableAlpha(featureId, alpha); |
| 4920 | } |
| 4921 | |
| 4922 | /** |
| 4923 | * Convenience for calling |
| 4924 | * {@link android.view.Window#getLayoutInflater}. |
| 4925 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4926 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4927 | public LayoutInflater getLayoutInflater() { |
| 4928 | return getWindow().getLayoutInflater(); |
| 4929 | } |
| 4930 | |
| 4931 | /** |
| 4932 | * Returns a {@link MenuInflater} with this context. |
| 4933 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4934 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4935 | public MenuInflater getMenuInflater() { |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 4936 | // Make sure that action views can get an appropriate theme. |
| 4937 | if (mMenuInflater == null) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 4938 | initWindowDecorActionBar(); |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 4939 | if (mActionBar != null) { |
Dianne Hackborn | 9275197 | 2012-05-18 19:22:14 -0700 | [diff] [blame] | 4940 | mMenuInflater = new MenuInflater(mActionBar.getThemedContext(), this); |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 4941 | } else { |
| 4942 | mMenuInflater = new MenuInflater(this); |
| 4943 | } |
| 4944 | } |
| 4945 | return mMenuInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4946 | } |
| 4947 | |
| 4948 | @Override |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 4949 | public void setTheme(int resid) { |
| 4950 | super.setTheme(resid); |
| 4951 | mWindow.setTheme(resid); |
| 4952 | } |
| 4953 | |
| 4954 | @Override |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 4955 | protected void onApplyThemeResource(Resources.Theme theme, @StyleRes int resid, |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4956 | boolean first) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4957 | if (mParent == null) { |
| 4958 | super.onApplyThemeResource(theme, resid, first); |
| 4959 | } else { |
| 4960 | try { |
| 4961 | theme.setTo(mParent.getTheme()); |
| 4962 | } catch (Exception e) { |
| 4963 | // Empty |
| 4964 | } |
| 4965 | theme.applyStyle(resid, false); |
| 4966 | } |
Winson | 073a526 | 2016-02-29 16:04:40 -0800 | [diff] [blame] | 4967 | |
| 4968 | // Get the primary color and update the TaskDescription for this activity |
| 4969 | TypedArray a = theme.obtainStyledAttributes( |
| 4970 | com.android.internal.R.styleable.ActivityTaskDescription); |
| 4971 | if (mTaskDescription.getPrimaryColor() == 0) { |
| 4972 | int colorPrimary = a.getColor( |
| 4973 | com.android.internal.R.styleable.ActivityTaskDescription_colorPrimary, 0); |
| 4974 | if (colorPrimary != 0 && Color.alpha(colorPrimary) == 0xFF) { |
| 4975 | mTaskDescription.setPrimaryColor(colorPrimary); |
| 4976 | } |
| 4977 | } |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 4978 | |
| 4979 | int colorBackground = a.getColor( |
| 4980 | com.android.internal.R.styleable.ActivityTaskDescription_colorBackground, 0); |
| 4981 | if (colorBackground != 0 && Color.alpha(colorBackground) == 0xFF) { |
| 4982 | mTaskDescription.setBackgroundColor(colorBackground); |
Winson | 073a526 | 2016-02-29 16:04:40 -0800 | [diff] [blame] | 4983 | } |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 4984 | |
| 4985 | final int statusBarColor = a.getColor( |
| 4986 | com.android.internal.R.styleable.ActivityTaskDescription_statusBarColor, 0); |
| 4987 | if (statusBarColor != 0) { |
| 4988 | mTaskDescription.setStatusBarColor(statusBarColor); |
| 4989 | } |
| 4990 | |
| 4991 | final int navigationBarColor = a.getColor( |
| 4992 | com.android.internal.R.styleable.ActivityTaskDescription_navigationBarColor, 0); |
| 4993 | if (navigationBarColor != 0) { |
| 4994 | mTaskDescription.setNavigationBarColor(navigationBarColor); |
| 4995 | } |
| 4996 | |
Adrian Roos | 4c86459 | 2019-04-10 14:47:57 +0200 | [diff] [blame] | 4997 | final int targetSdk = getApplicationInfo().targetSdkVersion; |
| 4998 | final boolean targetPreQ = targetSdk < Build.VERSION_CODES.Q; |
| 4999 | if (!targetPreQ) { |
| 5000 | mTaskDescription.setEnsureStatusBarContrastWhenTransparent(a.getBoolean( |
Adrian Roos | 8c7ca4f | 2019-04-17 11:35:22 +0200 | [diff] [blame] | 5001 | R.styleable.ActivityTaskDescription_enforceStatusBarContrast, |
Adrian Roos | 4c86459 | 2019-04-10 14:47:57 +0200 | [diff] [blame] | 5002 | false)); |
| 5003 | mTaskDescription.setEnsureNavigationBarContrastWhenTransparent(a.getBoolean( |
Adrian Roos | 6eb1ed3 | 2019-04-08 16:23:43 +0200 | [diff] [blame] | 5004 | R.styleable |
Adrian Roos | 8c7ca4f | 2019-04-17 11:35:22 +0200 | [diff] [blame] | 5005 | .ActivityTaskDescription_enforceNavigationBarContrast, |
Adrian Roos | 4c86459 | 2019-04-10 14:47:57 +0200 | [diff] [blame] | 5006 | true)); |
| 5007 | } |
| 5008 | |
Winson | 073a526 | 2016-02-29 16:04:40 -0800 | [diff] [blame] | 5009 | a.recycle(); |
| 5010 | setTaskDescription(mTaskDescription); |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 5011 | } |
| 5012 | |
| 5013 | /** |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5014 | * Requests permissions to be granted to this application. These permissions |
| 5015 | * must be requested in your manifest, they should not be granted to your app, |
Peter Visontay | 2c6b6c4 | 2018-06-14 14:47:12 +0100 | [diff] [blame] | 5016 | * and they should have protection level {@link |
| 5017 | * android.content.pm.PermissionInfo#PROTECTION_DANGEROUS dangerous}, regardless |
| 5018 | * whether they are declared by the platform or a third-party app. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5019 | * <p> |
| 5020 | * Normal permissions {@link android.content.pm.PermissionInfo#PROTECTION_NORMAL} |
| 5021 | * are granted at install time if requested in the manifest. Signature permissions |
| 5022 | * {@link android.content.pm.PermissionInfo#PROTECTION_SIGNATURE} are granted at |
| 5023 | * install time if requested in the manifest and the signature of your app matches |
| 5024 | * the signature of the app declaring the permissions. |
| 5025 | * </p> |
| 5026 | * <p> |
| 5027 | * If your app does not have the requested permissions the user will be presented |
| 5028 | * with UI for accepting them. After the user has accepted or rejected the |
| 5029 | * requested permissions you will receive a callback on {@link |
| 5030 | * #onRequestPermissionsResult(int, String[], int[])} reporting whether the |
| 5031 | * permissions were granted or not. |
| 5032 | * </p> |
| 5033 | * <p> |
| 5034 | * Note that requesting a permission does not guarantee it will be granted and |
| 5035 | * your app should be able to run without having this permission. |
| 5036 | * </p> |
| 5037 | * <p> |
| 5038 | * This method may start an activity allowing the user to choose which permissions |
| 5039 | * to grant and which to reject. Hence, you should be prepared that your activity |
| 5040 | * may be paused and resumed. Further, granting some permissions may require |
| 5041 | * a restart of you application. In such a case, the system will recreate the |
| 5042 | * activity stack before delivering the result to {@link |
| 5043 | * #onRequestPermissionsResult(int, String[], int[])}. |
| 5044 | * </p> |
| 5045 | * <p> |
| 5046 | * When checking whether you have a permission you should use {@link |
| 5047 | * #checkSelfPermission(String)}. |
| 5048 | * </p> |
| 5049 | * <p> |
Svet Ganov | d7ad54e | 2015-08-21 06:18:09 -0700 | [diff] [blame] | 5050 | * Calling this API for permissions already granted to your app would show UI |
| 5051 | * to the user to decide whether the app can still hold these permissions. This |
| 5052 | * can be useful if the way your app uses data guarded by the permissions |
| 5053 | * changes significantly. |
| 5054 | * </p> |
| 5055 | * <p> |
Svet Ganov | 255aece | 2015-07-03 16:03:53 -0700 | [diff] [blame] | 5056 | * You cannot request a permission if your activity sets {@link |
| 5057 | * android.R.styleable#AndroidManifestActivity_noHistory noHistory} to |
| 5058 | * <code>true</code> because in this case the activity would not receive |
| 5059 | * result callbacks including {@link #onRequestPermissionsResult(int, String[], int[])}. |
| 5060 | * </p> |
| 5061 | * <p> |
Peter Visontay | 2c6b6c4 | 2018-06-14 14:47:12 +0100 | [diff] [blame] | 5062 | * The <a href="https://github.com/googlesamples/android-RuntimePermissions"> |
Trevor Johns | 682c24e | 2016-04-12 10:13:47 -0700 | [diff] [blame] | 5063 | * RuntimePermissions</a> sample app demonstrates how to use this method to |
| 5064 | * request permissions at run time. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5065 | * </p> |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5066 | * |
Svet Ganov | f66381c | 2016-02-18 20:02:36 -0800 | [diff] [blame] | 5067 | * @param permissions The requested permissions. Must me non-null and not empty. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5068 | * @param requestCode Application specific request code to match with a result |
| 5069 | * reported to {@link #onRequestPermissionsResult(int, String[], int[])}. |
Svet Ganov | 255aece | 2015-07-03 16:03:53 -0700 | [diff] [blame] | 5070 | * Should be >= 0. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5071 | * |
Paul Miller | 77a0e13 | 2016-02-11 13:46:49 -0800 | [diff] [blame] | 5072 | * @throws IllegalArgumentException if requestCode is negative. |
| 5073 | * |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5074 | * @see #onRequestPermissionsResult(int, String[], int[]) |
| 5075 | * @see #checkSelfPermission(String) |
Svetoslav | aa048b6 | 2015-06-02 15:08:48 -0700 | [diff] [blame] | 5076 | * @see #shouldShowRequestPermissionRationale(String) |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5077 | */ |
| 5078 | public final void requestPermissions(@NonNull String[] permissions, int requestCode) { |
Paul Miller | 77a0e13 | 2016-02-11 13:46:49 -0800 | [diff] [blame] | 5079 | if (requestCode < 0) { |
| 5080 | throw new IllegalArgumentException("requestCode should be >= 0"); |
| 5081 | } |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 5082 | if (mHasCurrentPermissionsRequest) { |
Ahmad Melegy | e2bfbf1 | 2017-11-14 21:27:28 +0000 | [diff] [blame] | 5083 | Log.w(TAG, "Can request only one set of permissions at a time"); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 5084 | // Dispatch the callback with empty arrays which means a cancellation. |
| 5085 | onRequestPermissionsResult(requestCode, new String[0], new int[0]); |
| 5086 | return; |
| 5087 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5088 | Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions); |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 5089 | startActivityForResult(REQUEST_PERMISSIONS_WHO_PREFIX, intent, requestCode, null); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 5090 | mHasCurrentPermissionsRequest = true; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5091 | } |
| 5092 | |
| 5093 | /** |
| 5094 | * Callback for the result from requesting permissions. This method |
| 5095 | * is invoked for every call on {@link #requestPermissions(String[], int)}. |
Svet Ganov | 0f45c7c | 2015-07-16 16:28:51 -0700 | [diff] [blame] | 5096 | * <p> |
| 5097 | * <strong>Note:</strong> It is possible that the permissions request interaction |
| 5098 | * with the user is interrupted. In this case you will receive empty permissions |
| 5099 | * and results arrays which should be treated as a cancellation. |
| 5100 | * </p> |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5101 | * |
| 5102 | * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}. |
| 5103 | * @param permissions The requested permissions. Never null. |
| 5104 | * @param grantResults The grant results for the corresponding permissions |
| 5105 | * which is either {@link android.content.pm.PackageManager#PERMISSION_GRANTED} |
| 5106 | * or {@link android.content.pm.PackageManager#PERMISSION_DENIED}. Never null. |
| 5107 | * |
| 5108 | * @see #requestPermissions(String[], int) |
| 5109 | */ |
| 5110 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, |
| 5111 | @NonNull int[] grantResults) { |
| 5112 | /* callback - no nothing */ |
| 5113 | } |
| 5114 | |
| 5115 | /** |
Svetoslav | 20770dd | 2015-05-29 15:43:04 -0700 | [diff] [blame] | 5116 | * Gets whether you should show UI with rationale for requesting a permission. |
| 5117 | * You should do this only if you do not have the permission and the context in |
| 5118 | * which the permission is requested does not clearly communicate to the user |
| 5119 | * what would be the benefit from granting this permission. |
| 5120 | * <p> |
| 5121 | * For example, if you write a camera app, requesting the camera permission |
| 5122 | * would be expected by the user and no rationale for why it is requested is |
| 5123 | * needed. If however, the app needs location for tagging photos then a non-tech |
| 5124 | * savvy user may wonder how location is related to taking photos. In this case |
| 5125 | * you may choose to show UI with rationale of requesting this permission. |
| 5126 | * </p> |
| 5127 | * |
| 5128 | * @param permission A permission your app wants to request. |
| 5129 | * @return Whether you can show permission rationale UI. |
| 5130 | * |
| 5131 | * @see #checkSelfPermission(String) |
| 5132 | * @see #requestPermissions(String[], int) |
| 5133 | * @see #onRequestPermissionsResult(int, String[], int[]) |
| 5134 | */ |
Svetoslav | 9ce9a15 | 2015-06-02 17:59:31 -0700 | [diff] [blame] | 5135 | public boolean shouldShowRequestPermissionRationale(@NonNull String permission) { |
Svetoslav | 20770dd | 2015-05-29 15:43:04 -0700 | [diff] [blame] | 5136 | return getPackageManager().shouldShowRequestPermissionRationale(permission); |
| 5137 | } |
| 5138 | |
| 5139 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5140 | * Same as calling {@link #startActivityForResult(Intent, int, Bundle)} |
| 5141 | * with no options. |
| 5142 | * |
| 5143 | * @param intent The intent to start. |
| 5144 | * @param requestCode If >= 0, this code will be returned in |
| 5145 | * onActivityResult() when the activity exits. |
| 5146 | * |
| 5147 | * @throws android.content.ActivityNotFoundException |
| 5148 | * |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 5149 | * @see #startActivity |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5150 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5151 | public void startActivityForResult(@RequiresPermission Intent intent, int requestCode) { |
George Mount | abb63cb | 2014-06-23 11:17:58 -0700 | [diff] [blame] | 5152 | startActivityForResult(intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5153 | } |
| 5154 | |
| 5155 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5156 | * Launch an activity for which you would like a result when it finished. |
| 5157 | * When this activity exits, your |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 5158 | * onActivityResult() method will be called with the given requestCode. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5159 | * Using a negative requestCode is the same as calling |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5160 | * {@link #startActivity} (the activity is not launched as a sub-activity). |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5161 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5162 | * <p>Note that this method should only be used with Intent protocols |
| 5163 | * that are defined to return a result. In other protocols (such as |
| 5164 | * {@link Intent#ACTION_MAIN} or {@link Intent#ACTION_VIEW}), you may |
| 5165 | * not get the result when you expect. For example, if the activity you |
Mark Renouf | cca6d05 | 2016-12-02 14:11:18 -0500 | [diff] [blame] | 5166 | * are launching uses {@link Intent#FLAG_ACTIVITY_NEW_TASK}, it will not |
| 5167 | * run in your task and thus you will immediately receive a cancel result. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5168 | * |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5169 | * <p>As a special case, if you call startActivityForResult() with a requestCode |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5170 | * >= 0 during the initial onCreate(Bundle savedInstanceState)/onResume() of your |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 5171 | * activity, then your window will not be displayed until a result is |
| 5172 | * returned back from the started activity. This is to avoid visible |
| 5173 | * flickering when redirecting to another activity. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5174 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5175 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 5176 | * if there was no Activity found to run the given Intent. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5177 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5178 | * @param intent The intent to start. |
| 5179 | * @param requestCode If >= 0, this code will be returned in |
| 5180 | * onActivityResult() when the activity exits. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5181 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5182 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5183 | * Context.startActivity(Intent, Bundle)} for more details. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5184 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5185 | * @throws android.content.ActivityNotFoundException |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5186 | * |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 5187 | * @see #startActivity |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5188 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5189 | public void startActivityForResult(@RequiresPermission Intent intent, int requestCode, |
| 5190 | @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5191 | if (mParent == null) { |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5192 | options = transferSpringboardActivityOptions(options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5193 | Instrumentation.ActivityResult ar = |
| 5194 | mInstrumentation.execStartActivity( |
| 5195 | this, mMainThread.getApplicationThread(), mToken, this, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5196 | intent, requestCode, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5197 | if (ar != null) { |
| 5198 | mMainThread.sendActivityResult( |
| 5199 | mToken, mEmbeddedID, requestCode, ar.getResultCode(), |
| 5200 | ar.getResultData()); |
| 5201 | } |
| 5202 | if (requestCode >= 0) { |
| 5203 | // If this start is requesting a result, we can avoid making |
| 5204 | // the activity visible until the result is received. Setting |
| 5205 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 5206 | // activity hidden during this time, to avoid flickering. |
| 5207 | // This can only be done when a result is requested because |
| 5208 | // that guarantees we will get information back when the |
| 5209 | // activity is finished, no matter what happens to it. |
| 5210 | mStartedActivity = true; |
| 5211 | } |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 5212 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5213 | cancelInputsAndStartExitTransition(options); |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 5214 | // TODO Consider clearing/flushing other event sources and events for child windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5215 | } else { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5216 | if (options != null) { |
| 5217 | mParent.startActivityFromChild(this, intent, requestCode, options); |
| 5218 | } else { |
| 5219 | // Note we want to go through this method for compatibility with |
| 5220 | // existing applications that may have overridden it. |
| 5221 | mParent.startActivityFromChild(this, intent, requestCode); |
| 5222 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5223 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5224 | } |
| 5225 | |
| 5226 | /** |
| 5227 | * Cancels pending inputs and if an Activity Transition is to be run, starts the transition. |
| 5228 | * |
| 5229 | * @param options The ActivityOptions bundle used to start an Activity. |
| 5230 | */ |
| 5231 | private void cancelInputsAndStartExitTransition(Bundle options) { |
| 5232 | final View decor = mWindow != null ? mWindow.peekDecorView() : null; |
| 5233 | if (decor != null) { |
| 5234 | decor.cancelPendingInputEvents(); |
| 5235 | } |
Sunny Goyal | d85bed5 | 2018-09-25 12:01:01 -0700 | [diff] [blame] | 5236 | if (options != null) { |
George Mount | ff24328 | 2014-07-07 16:12:07 -0700 | [diff] [blame] | 5237 | mActivityTransitionState.startExitOutTransition(this, options); |
| 5238 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5239 | } |
| 5240 | |
Chet Haase | b64e777f | 2016-12-09 07:17:10 -0800 | [diff] [blame] | 5241 | /** |
| 5242 | * Returns whether there are any activity transitions currently running on this |
| 5243 | * activity. A return value of {@code true} can mean that either an enter or |
| 5244 | * exit transition is running, including whether the background of the activity |
| 5245 | * is animating as a part of that transition. |
| 5246 | * |
| 5247 | * @return true if a transition is currently running on this activity, false otherwise. |
| 5248 | */ |
| 5249 | public boolean isActivityTransitionRunning() { |
| 5250 | return mActivityTransitionState.isTransitionRunning(); |
| 5251 | } |
| 5252 | |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5253 | private Bundle transferSpringboardActivityOptions(Bundle options) { |
| 5254 | if (options == null && (mWindow != null && !mWindow.isActive())) { |
| 5255 | final ActivityOptions activityOptions = getActivityOptions(); |
George Mount | 9638378 | 2016-06-08 15:13:52 -0700 | [diff] [blame] | 5256 | if (activityOptions != null && |
| 5257 | activityOptions.getAnimationType() == ActivityOptions.ANIM_SCENE_TRANSITION) { |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5258 | return activityOptions.toBundle(); |
| 5259 | } |
| 5260 | } |
| 5261 | return options; |
| 5262 | } |
| 5263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5264 | /** |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 5265 | * @hide Implement to provide correct calling token. |
| 5266 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5267 | @UnsupportedAppUsage |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 5268 | public void startActivityForResultAsUser(Intent intent, int requestCode, UserHandle user) { |
| 5269 | startActivityForResultAsUser(intent, requestCode, null, user); |
| 5270 | } |
| 5271 | |
| 5272 | /** |
| 5273 | * @hide Implement to provide correct calling token. |
| 5274 | */ |
| 5275 | public void startActivityForResultAsUser(Intent intent, int requestCode, |
| 5276 | @Nullable Bundle options, UserHandle user) { |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 5277 | startActivityForResultAsUser(intent, mEmbeddedID, requestCode, options, user); |
| 5278 | } |
| 5279 | |
| 5280 | /** |
| 5281 | * @hide Implement to provide correct calling token. |
| 5282 | */ |
| 5283 | public void startActivityForResultAsUser(Intent intent, String resultWho, int requestCode, |
| 5284 | @Nullable Bundle options, UserHandle user) { |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 5285 | if (mParent != null) { |
| 5286 | throw new RuntimeException("Can't be called from a child"); |
| 5287 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5288 | options = transferSpringboardActivityOptions(options); |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 5289 | Instrumentation.ActivityResult ar = mInstrumentation.execStartActivity( |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 5290 | this, mMainThread.getApplicationThread(), mToken, resultWho, intent, requestCode, |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 5291 | options, user); |
| 5292 | if (ar != null) { |
| 5293 | mMainThread.sendActivityResult( |
| 5294 | mToken, mEmbeddedID, requestCode, ar.getResultCode(), ar.getResultData()); |
| 5295 | } |
| 5296 | if (requestCode >= 0) { |
| 5297 | // If this start is requesting a result, we can avoid making |
| 5298 | // the activity visible until the result is received. Setting |
| 5299 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 5300 | // activity hidden during this time, to avoid flickering. |
| 5301 | // This can only be done when a result is requested because |
| 5302 | // that guarantees we will get information back when the |
| 5303 | // activity is finished, no matter what happens to it. |
| 5304 | mStartedActivity = true; |
| 5305 | } |
| 5306 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5307 | cancelInputsAndStartExitTransition(options); |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 5308 | } |
| 5309 | |
| 5310 | /** |
| 5311 | * @hide Implement to provide correct calling token. |
| 5312 | */ |
Philip P. Moltmann | 4e615e6 | 2018-08-28 14:57:49 -0700 | [diff] [blame] | 5313 | @Override |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 5314 | public void startActivityAsUser(Intent intent, UserHandle user) { |
| 5315 | startActivityAsUser(intent, null, user); |
| 5316 | } |
| 5317 | |
| 5318 | /** |
| 5319 | * @hide Implement to provide correct calling token. |
| 5320 | */ |
| 5321 | public void startActivityAsUser(Intent intent, Bundle options, UserHandle user) { |
| 5322 | if (mParent != null) { |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 5323 | throw new RuntimeException("Can't be called from a child"); |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 5324 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5325 | options = transferSpringboardActivityOptions(options); |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 5326 | Instrumentation.ActivityResult ar = |
| 5327 | mInstrumentation.execStartActivity( |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 5328 | this, mMainThread.getApplicationThread(), mToken, mEmbeddedID, |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 5329 | intent, -1, options, user); |
| 5330 | if (ar != null) { |
| 5331 | mMainThread.sendActivityResult( |
| 5332 | mToken, mEmbeddedID, -1, ar.getResultCode(), |
| 5333 | ar.getResultData()); |
| 5334 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5335 | cancelInputsAndStartExitTransition(options); |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | /** |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 5339 | * Start a new activity as if it was started by the activity that started our |
| 5340 | * current activity. This is for the resolver and chooser activities, which operate |
| 5341 | * as intermediaries that dispatch their intent to the target the user selects -- to |
| 5342 | * do this, they must perform all security checks including permission grants as if |
| 5343 | * their launch had come from the original activity. |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 5344 | * @param intent The Intent to start. |
| 5345 | * @param options ActivityOptions or null. |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5346 | * @param permissionToken Token received from the system that permits this call to be made. |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 5347 | * @param ignoreTargetSecurity If true, the activity manager will not check whether the |
| 5348 | * caller it is doing the start is, is actually allowed to start the target activity. |
| 5349 | * If you set this to true, you must set an explicit component in the Intent and do any |
| 5350 | * appropriate security checks yourself. |
| 5351 | * @param userId The user the new activity should run as. |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 5352 | * @hide |
| 5353 | */ |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 5354 | public void startActivityAsCaller(Intent intent, @Nullable Bundle options, |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5355 | IBinder permissionToken, boolean ignoreTargetSecurity, int userId) { |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 5356 | if (mParent != null) { |
| 5357 | throw new RuntimeException("Can't be called from a child"); |
| 5358 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5359 | options = transferSpringboardActivityOptions(options); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 5360 | Instrumentation.ActivityResult ar = |
| 5361 | mInstrumentation.execStartActivityAsCaller( |
| 5362 | this, mMainThread.getApplicationThread(), mToken, this, |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5363 | intent, -1, options, permissionToken, ignoreTargetSecurity, userId); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 5364 | if (ar != null) { |
| 5365 | mMainThread.sendActivityResult( |
| 5366 | mToken, mEmbeddedID, -1, ar.getResultCode(), |
| 5367 | ar.getResultData()); |
| 5368 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5369 | cancelInputsAndStartExitTransition(options); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 5370 | } |
| 5371 | |
| 5372 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5373 | * Same as calling {@link #startIntentSenderForResult(IntentSender, int, |
| 5374 | * Intent, int, int, int, Bundle)} with no options. |
| 5375 | * |
| 5376 | * @param intent The IntentSender to launch. |
| 5377 | * @param requestCode If >= 0, this code will be returned in |
| 5378 | * onActivityResult() when the activity exits. |
| 5379 | * @param fillInIntent If non-null, this will be provided as the |
| 5380 | * intent parameter to {@link IntentSender#sendIntent}. |
| 5381 | * @param flagsMask Intent flags in the original IntentSender that you |
| 5382 | * would like to change. |
| 5383 | * @param flagsValues Desired values for any bits set in |
| 5384 | * <var>flagsMask</var> |
| 5385 | * @param extraFlags Always set to 0. |
| 5386 | */ |
| 5387 | public void startIntentSenderForResult(IntentSender intent, int requestCode, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5388 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5389 | throws IntentSender.SendIntentException { |
| 5390 | startIntentSenderForResult(intent, requestCode, fillInIntent, flagsMask, |
| 5391 | flagsValues, extraFlags, null); |
| 5392 | } |
| 5393 | |
| 5394 | /** |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5395 | * Like {@link #startActivityForResult(Intent, int)}, but allowing you |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5396 | * to use a IntentSender to describe the activity to be started. If |
| 5397 | * the IntentSender is for an activity, that activity will be started |
| 5398 | * as if you had called the regular {@link #startActivityForResult(Intent, int)} |
| 5399 | * here; otherwise, its associated action will be executed (such as |
| 5400 | * sending a broadcast) as if you had called |
| 5401 | * {@link IntentSender#sendIntent IntentSender.sendIntent} on it. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5402 | * |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5403 | * @param intent The IntentSender to launch. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5404 | * @param requestCode If >= 0, this code will be returned in |
| 5405 | * onActivityResult() when the activity exits. |
| 5406 | * @param fillInIntent If non-null, this will be provided as the |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5407 | * intent parameter to {@link IntentSender#sendIntent}. |
| 5408 | * @param flagsMask Intent flags in the original IntentSender that you |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5409 | * would like to change. |
| 5410 | * @param flagsValues Desired values for any bits set in |
| 5411 | * <var>flagsMask</var> |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5412 | * @param extraFlags Always set to 0. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5413 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5414 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5415 | * Context.startActivity(Intent, Bundle)} for more details. If options |
| 5416 | * have also been supplied by the IntentSender, options given here will |
| 5417 | * override any that conflict with those given by the IntentSender. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5418 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5419 | public void startIntentSenderForResult(IntentSender intent, int requestCode, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5420 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5421 | Bundle options) throws IntentSender.SendIntentException { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5422 | if (mParent == null) { |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 5423 | startIntentSenderForResultInner(intent, mEmbeddedID, requestCode, fillInIntent, |
| 5424 | flagsMask, flagsValues, options); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5425 | } else if (options != null) { |
| 5426 | mParent.startIntentSenderFromChild(this, intent, requestCode, |
| 5427 | fillInIntent, flagsMask, flagsValues, extraFlags, options); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5428 | } else { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5429 | // Note we want to go through this call for compatibility with |
| 5430 | // existing applications that may have overridden the method. |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5431 | mParent.startIntentSenderFromChild(this, intent, requestCode, |
| 5432 | fillInIntent, flagsMask, flagsValues, extraFlags); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5433 | } |
| 5434 | } |
| 5435 | |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 5436 | private void startIntentSenderForResultInner(IntentSender intent, String who, int requestCode, |
| 5437 | Intent fillInIntent, int flagsMask, int flagsValues, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5438 | Bundle options) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5439 | throws IntentSender.SendIntentException { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5440 | try { |
Sunny Goyal | d85bed5 | 2018-09-25 12:01:01 -0700 | [diff] [blame] | 5441 | options = transferSpringboardActivityOptions(options); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5442 | String resolvedType = null; |
| 5443 | if (fillInIntent != null) { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 5444 | fillInIntent.migrateExtraStreamToClipData(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5445 | fillInIntent.prepareToLeaveProcess(this); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5446 | resolvedType = fillInIntent.resolveTypeIfNeeded(getContentResolver()); |
| 5447 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 5448 | int result = ActivityTaskManager.getService() |
Dianne Hackborn | 3e6e385 | 2017-05-19 16:12:08 -0700 | [diff] [blame] | 5449 | .startActivityIntentSender(mMainThread.getApplicationThread(), |
| 5450 | intent != null ? intent.getTarget() : null, |
| 5451 | intent != null ? intent.getWhitelistToken() : null, |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 5452 | fillInIntent, resolvedType, mToken, who, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5453 | requestCode, flagsMask, flagsValues, options); |
| 5454 | if (result == ActivityManager.START_CANCELED) { |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5455 | throw new IntentSender.SendIntentException(); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5456 | } |
| 5457 | Instrumentation.checkStartActivityResult(result, null); |
Sunny Goyal | d85bed5 | 2018-09-25 12:01:01 -0700 | [diff] [blame] | 5458 | |
| 5459 | if (options != null) { |
| 5460 | // Only when the options are not null, as the intent can point to something other |
| 5461 | // than an Activity. |
| 5462 | cancelInputsAndStartExitTransition(options); |
| 5463 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5464 | } catch (RemoteException e) { |
| 5465 | } |
| 5466 | if (requestCode >= 0) { |
| 5467 | // If this start is requesting a result, we can avoid making |
| 5468 | // the activity visible until the result is received. Setting |
| 5469 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 5470 | // activity hidden during this time, to avoid flickering. |
| 5471 | // This can only be done when a result is requested because |
| 5472 | // that guarantees we will get information back when the |
| 5473 | // activity is finished, no matter what happens to it. |
| 5474 | mStartedActivity = true; |
| 5475 | } |
| 5476 | } |
| 5477 | |
| 5478 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5479 | * Same as {@link #startActivity(Intent, Bundle)} with no options |
| 5480 | * specified. |
| 5481 | * |
| 5482 | * @param intent The intent to start. |
| 5483 | * |
| 5484 | * @throws android.content.ActivityNotFoundException |
| 5485 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 5486 | * @see #startActivity(Intent, Bundle) |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5487 | * @see #startActivityForResult |
| 5488 | */ |
| 5489 | @Override |
| 5490 | public void startActivity(Intent intent) { |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 5491 | this.startActivity(intent, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5492 | } |
| 5493 | |
| 5494 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5495 | * Launch a new activity. You will not receive any information about when |
| 5496 | * the activity exits. This implementation overrides the base version, |
| 5497 | * providing information about |
| 5498 | * the activity performing the launch. Because of this additional |
| 5499 | * information, the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag is not |
| 5500 | * required; if not specified, the new activity will be added to the |
| 5501 | * task of the caller. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5502 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5503 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 5504 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5505 | * |
| 5506 | * @param intent The intent to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5507 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5508 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5509 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5510 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5511 | * @throws android.content.ActivityNotFoundException |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5512 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 5513 | * @see #startActivity(Intent) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5514 | * @see #startActivityForResult |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5515 | */ |
| 5516 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5517 | public void startActivity(Intent intent, @Nullable Bundle options) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5518 | if (options != null) { |
| 5519 | startActivityForResult(intent, -1, options); |
| 5520 | } else { |
| 5521 | // Note we want to go through this call for compatibility with |
| 5522 | // applications that may have overridden the method. |
| 5523 | startActivityForResult(intent, -1); |
| 5524 | } |
| 5525 | } |
| 5526 | |
| 5527 | /** |
| 5528 | * Same as {@link #startActivities(Intent[], Bundle)} with no options |
| 5529 | * specified. |
| 5530 | * |
| 5531 | * @param intents The intents to start. |
| 5532 | * |
| 5533 | * @throws android.content.ActivityNotFoundException |
| 5534 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 5535 | * @see #startActivities(Intent[], Bundle) |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5536 | * @see #startActivityForResult |
| 5537 | */ |
| 5538 | @Override |
| 5539 | public void startActivities(Intent[] intents) { |
| 5540 | startActivities(intents, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5541 | } |
| 5542 | |
| 5543 | /** |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 5544 | * Launch a new activity. You will not receive any information about when |
| 5545 | * the activity exits. This implementation overrides the base version, |
| 5546 | * providing information about |
| 5547 | * the activity performing the launch. Because of this additional |
| 5548 | * information, the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag is not |
| 5549 | * required; if not specified, the new activity will be added to the |
| 5550 | * task of the caller. |
| 5551 | * |
| 5552 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 5553 | * if there was no Activity found to run the given Intent. |
| 5554 | * |
| 5555 | * @param intents The intents to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5556 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5557 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5558 | * Context.startActivity(Intent, Bundle)} for more details. |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 5559 | * |
| 5560 | * @throws android.content.ActivityNotFoundException |
| 5561 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 5562 | * @see #startActivities(Intent[]) |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 5563 | * @see #startActivityForResult |
| 5564 | */ |
| 5565 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5566 | public void startActivities(Intent[] intents, @Nullable Bundle options) { |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 5567 | mInstrumentation.execStartActivities(this, mMainThread.getApplicationThread(), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5568 | mToken, this, intents, options); |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5572 | * Same as calling {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)} |
| 5573 | * with no options. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5574 | * |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5575 | * @param intent The IntentSender to launch. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5576 | * @param fillInIntent If non-null, this will be provided as the |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5577 | * intent parameter to {@link IntentSender#sendIntent}. |
| 5578 | * @param flagsMask Intent flags in the original IntentSender that you |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5579 | * would like to change. |
| 5580 | * @param flagsValues Desired values for any bits set in |
| 5581 | * <var>flagsMask</var> |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5582 | * @param extraFlags Always set to 0. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5583 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5584 | public void startIntentSender(IntentSender intent, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5585 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5586 | throws IntentSender.SendIntentException { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5587 | startIntentSender(intent, fillInIntent, flagsMask, flagsValues, |
| 5588 | extraFlags, null); |
| 5589 | } |
| 5590 | |
| 5591 | /** |
| 5592 | * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender |
| 5593 | * to start; see |
| 5594 | * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int, Bundle)} |
| 5595 | * for more information. |
| 5596 | * |
| 5597 | * @param intent The IntentSender to launch. |
| 5598 | * @param fillInIntent If non-null, this will be provided as the |
| 5599 | * intent parameter to {@link IntentSender#sendIntent}. |
| 5600 | * @param flagsMask Intent flags in the original IntentSender that you |
| 5601 | * would like to change. |
| 5602 | * @param flagsValues Desired values for any bits set in |
| 5603 | * <var>flagsMask</var> |
| 5604 | * @param extraFlags Always set to 0. |
| 5605 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5606 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5607 | * Context.startActivity(Intent, Bundle)} for more details. If options |
| 5608 | * have also been supplied by the IntentSender, options given here will |
| 5609 | * override any that conflict with those given by the IntentSender. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5610 | */ |
| 5611 | public void startIntentSender(IntentSender intent, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5612 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5613 | Bundle options) throws IntentSender.SendIntentException { |
| 5614 | if (options != null) { |
| 5615 | startIntentSenderForResult(intent, -1, fillInIntent, flagsMask, |
| 5616 | flagsValues, extraFlags, options); |
| 5617 | } else { |
| 5618 | // Note we want to go through this call for compatibility with |
| 5619 | // applications that may have overridden the method. |
| 5620 | startIntentSenderForResult(intent, -1, fillInIntent, flagsMask, |
| 5621 | flagsValues, extraFlags); |
| 5622 | } |
| 5623 | } |
| 5624 | |
| 5625 | /** |
| 5626 | * Same as calling {@link #startActivityIfNeeded(Intent, int, Bundle)} |
| 5627 | * with no options. |
| 5628 | * |
| 5629 | * @param intent The intent to start. |
| 5630 | * @param requestCode If >= 0, this code will be returned in |
| 5631 | * onActivityResult() when the activity exits, as described in |
| 5632 | * {@link #startActivityForResult}. |
| 5633 | * |
| 5634 | * @return If a new activity was launched then true is returned; otherwise |
| 5635 | * false is returned and you must handle the Intent yourself. |
| 5636 | * |
| 5637 | * @see #startActivity |
| 5638 | * @see #startActivityForResult |
| 5639 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5640 | public boolean startActivityIfNeeded(@RequiresPermission @NonNull Intent intent, |
| 5641 | int requestCode) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5642 | return startActivityIfNeeded(intent, requestCode, null); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5643 | } |
| 5644 | |
| 5645 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5646 | * A special variation to launch an activity only if a new activity |
| 5647 | * instance is needed to handle the given Intent. In other words, this is |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5648 | * just like {@link #startActivityForResult(Intent, int)} except: if you are |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5649 | * using the {@link Intent#FLAG_ACTIVITY_SINGLE_TOP} flag, or |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5650 | * singleTask or singleTop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5651 | * {@link android.R.styleable#AndroidManifestActivity_launchMode launchMode}, |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5652 | * and the activity |
| 5653 | * that handles <var>intent</var> is the same as your currently running |
| 5654 | * activity, then a new instance is not needed. In this case, instead of |
| 5655 | * the normal behavior of calling {@link #onNewIntent} this function will |
| 5656 | * return and you can handle the Intent yourself. |
| 5657 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5658 | * <p>This function can only be called from a top-level activity; if it is |
| 5659 | * called from a child activity, a runtime exception will be thrown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5660 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5661 | * @param intent The intent to start. |
| 5662 | * @param requestCode If >= 0, this code will be returned in |
| 5663 | * onActivityResult() when the activity exits, as described in |
| 5664 | * {@link #startActivityForResult}. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5665 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5666 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5667 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5668 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5669 | * @return If a new activity was launched then true is returned; otherwise |
| 5670 | * false is returned and you must handle the Intent yourself. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5671 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5672 | * @see #startActivity |
| 5673 | * @see #startActivityForResult |
| 5674 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5675 | public boolean startActivityIfNeeded(@RequiresPermission @NonNull Intent intent, |
| 5676 | int requestCode, @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5677 | if (mParent == null) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5678 | int result = ActivityManager.START_RETURN_INTENT_TO_CALLER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5679 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 5680 | Uri referrer = onProvideReferrer(); |
| 5681 | if (referrer != null) { |
| 5682 | intent.putExtra(Intent.EXTRA_REFERRER, referrer); |
| 5683 | } |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 5684 | intent.migrateExtraStreamToClipData(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5685 | intent.prepareToLeaveProcess(this); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 5686 | result = ActivityTaskManager.getService() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5687 | .startActivity(mMainThread.getApplicationThread(), getBasePackageName(), |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5688 | intent, intent.resolveTypeIfNeeded(getContentResolver()), mToken, |
| 5689 | mEmbeddedID, requestCode, ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
| 5690 | null, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5691 | } catch (RemoteException e) { |
| 5692 | // Empty |
| 5693 | } |
Siva Velusamy | 92a8b22 | 2012-03-09 16:24:04 -0800 | [diff] [blame] | 5694 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5695 | Instrumentation.checkStartActivityResult(result, intent); |
Siva Velusamy | 92a8b22 | 2012-03-09 16:24:04 -0800 | [diff] [blame] | 5696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5697 | if (requestCode >= 0) { |
| 5698 | // If this start is requesting a result, we can avoid making |
| 5699 | // the activity visible until the result is received. Setting |
| 5700 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 5701 | // activity hidden during this time, to avoid flickering. |
| 5702 | // This can only be done when a result is requested because |
| 5703 | // that guarantees we will get information back when the |
| 5704 | // activity is finished, no matter what happens to it. |
| 5705 | mStartedActivity = true; |
| 5706 | } |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5707 | return result != ActivityManager.START_RETURN_INTENT_TO_CALLER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5708 | } |
| 5709 | |
| 5710 | throw new UnsupportedOperationException( |
| 5711 | "startActivityIfNeeded can only be called from a top-level activity"); |
| 5712 | } |
| 5713 | |
| 5714 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5715 | * Same as calling {@link #startNextMatchingActivity(Intent, Bundle)} with |
| 5716 | * no options. |
| 5717 | * |
| 5718 | * @param intent The intent to dispatch to the next activity. For |
| 5719 | * correct behavior, this must be the same as the Intent that started |
| 5720 | * your own activity; the only changes you can make are to the extras |
| 5721 | * inside of it. |
| 5722 | * |
| 5723 | * @return Returns a boolean indicating whether there was another Activity |
| 5724 | * to start: true if there was a next activity to start, false if there |
| 5725 | * wasn't. In general, if true is returned you will then want to call |
| 5726 | * finish() on yourself. |
| 5727 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5728 | public boolean startNextMatchingActivity(@RequiresPermission @NonNull Intent intent) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5729 | return startNextMatchingActivity(intent, null); |
| 5730 | } |
| 5731 | |
| 5732 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5733 | * Special version of starting an activity, for use when you are replacing |
| 5734 | * other activity components. You can use this to hand the Intent off |
| 5735 | * to the next Activity that can handle it. You typically call this in |
| 5736 | * {@link #onCreate} with the Intent returned by {@link #getIntent}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5737 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5738 | * @param intent The intent to dispatch to the next activity. For |
| 5739 | * correct behavior, this must be the same as the Intent that started |
| 5740 | * your own activity; the only changes you can make are to the extras |
| 5741 | * inside of it. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5742 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5743 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5744 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5745 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5746 | * @return Returns a boolean indicating whether there was another Activity |
| 5747 | * to start: true if there was a next activity to start, false if there |
| 5748 | * wasn't. In general, if true is returned you will then want to call |
| 5749 | * finish() on yourself. |
| 5750 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5751 | public boolean startNextMatchingActivity(@RequiresPermission @NonNull Intent intent, |
| 5752 | @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5753 | if (mParent == null) { |
| 5754 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 5755 | intent.migrateExtraStreamToClipData(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5756 | intent.prepareToLeaveProcess(this); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 5757 | return ActivityTaskManager.getService() |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5758 | .startNextMatchingActivity(mToken, intent, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5759 | } catch (RemoteException e) { |
| 5760 | // Empty |
| 5761 | } |
| 5762 | return false; |
| 5763 | } |
| 5764 | |
| 5765 | throw new UnsupportedOperationException( |
| 5766 | "startNextMatchingActivity can only be called from a top-level activity"); |
| 5767 | } |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5768 | |
| 5769 | /** |
| 5770 | * Same as calling {@link #startActivityFromChild(Activity, Intent, int, Bundle)} |
| 5771 | * with no options. |
| 5772 | * |
| 5773 | * @param child The activity making the call. |
| 5774 | * @param intent The intent to start. |
| 5775 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 5776 | * |
| 5777 | * @throws android.content.ActivityNotFoundException |
| 5778 | * |
| 5779 | * @see #startActivity |
| 5780 | * @see #startActivityForResult |
| 5781 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5782 | public void startActivityFromChild(@NonNull Activity child, @RequiresPermission Intent intent, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5783 | int requestCode) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 5784 | startActivityFromChild(child, intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5785 | } |
| 5786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5787 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5788 | * This is called when a child activity of this one calls its |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5789 | * {@link #startActivity} or {@link #startActivityForResult} method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5790 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 5792 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5793 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5794 | * @param child The activity making the call. |
| 5795 | * @param intent The intent to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5796 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 5797 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5798 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5799 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5800 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5801 | * @throws android.content.ActivityNotFoundException |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5802 | * |
| 5803 | * @see #startActivity |
| 5804 | * @see #startActivityForResult |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5805 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5806 | public void startActivityFromChild(@NonNull Activity child, @RequiresPermission Intent intent, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5807 | int requestCode, @Nullable Bundle options) { |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5808 | options = transferSpringboardActivityOptions(options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5809 | Instrumentation.ActivityResult ar = |
| 5810 | mInstrumentation.execStartActivity( |
| 5811 | this, mMainThread.getApplicationThread(), mToken, child, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5812 | intent, requestCode, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5813 | if (ar != null) { |
| 5814 | mMainThread.sendActivityResult( |
| 5815 | mToken, child.mEmbeddedID, requestCode, |
| 5816 | ar.getResultCode(), ar.getResultData()); |
| 5817 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5818 | cancelInputsAndStartExitTransition(options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5819 | } |
| 5820 | |
| 5821 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5822 | * Same as calling {@link #startActivityFromFragment(Fragment, Intent, int, Bundle)} |
| 5823 | * with no options. |
| 5824 | * |
| 5825 | * @param fragment The fragment making the call. |
| 5826 | * @param intent The intent to start. |
| 5827 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 5828 | * |
| 5829 | * @throws android.content.ActivityNotFoundException |
| 5830 | * |
| 5831 | * @see Fragment#startActivity |
| 5832 | * @see Fragment#startActivityForResult |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 5833 | * |
| 5834 | * @deprecated Use {@link android.support.v4.app.FragmentActivity#startActivityFromFragment( |
| 5835 | * android.support.v4.app.Fragment,Intent,int)} |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5836 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 5837 | @Deprecated |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5838 | public void startActivityFromFragment(@NonNull Fragment fragment, |
| 5839 | @RequiresPermission Intent intent, int requestCode) { |
George Mount | abb63cb | 2014-06-23 11:17:58 -0700 | [diff] [blame] | 5840 | startActivityFromFragment(fragment, intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5841 | } |
| 5842 | |
| 5843 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5844 | * This is called when a Fragment in this activity calls its |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5845 | * {@link Fragment#startActivity} or {@link Fragment#startActivityForResult} |
| 5846 | * method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5847 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5848 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 5849 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5850 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5851 | * @param fragment The fragment making the call. |
| 5852 | * @param intent The intent to start. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5853 | * @param requestCode Reply request code. < 0 if reply is not requested. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5854 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5855 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5856 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5857 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5858 | * @throws android.content.ActivityNotFoundException |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5859 | * |
| 5860 | * @see Fragment#startActivity |
| 5861 | * @see Fragment#startActivityForResult |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 5862 | * |
| 5863 | * @deprecated Use {@link android.support.v4.app.FragmentActivity#startActivityFromFragment( |
| 5864 | * android.support.v4.app.Fragment,Intent,int,Bundle)} |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5865 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 5866 | @Deprecated |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5867 | public void startActivityFromFragment(@NonNull Fragment fragment, |
| 5868 | @RequiresPermission Intent intent, int requestCode, @Nullable Bundle options) { |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5869 | startActivityForResult(fragment.mWho, intent, requestCode, options); |
| 5870 | } |
| 5871 | |
| 5872 | /** |
| 5873 | * @hide |
| 5874 | */ |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 5875 | public void startActivityAsUserFromFragment(@NonNull Fragment fragment, |
| 5876 | @RequiresPermission Intent intent, int requestCode, @Nullable Bundle options, |
| 5877 | UserHandle user) { |
| 5878 | startActivityForResultAsUser(intent, fragment.mWho, requestCode, options, user); |
| 5879 | } |
| 5880 | |
| 5881 | /** |
| 5882 | * @hide |
| 5883 | */ |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5884 | @Override |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5885 | @UnsupportedAppUsage |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5886 | public void startActivityForResult( |
| 5887 | String who, Intent intent, int requestCode, @Nullable Bundle options) { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 5888 | Uri referrer = onProvideReferrer(); |
| 5889 | if (referrer != null) { |
| 5890 | intent.putExtra(Intent.EXTRA_REFERRER, referrer); |
| 5891 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5892 | options = transferSpringboardActivityOptions(options); |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5893 | Instrumentation.ActivityResult ar = |
| 5894 | mInstrumentation.execStartActivity( |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5895 | this, mMainThread.getApplicationThread(), mToken, who, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5896 | intent, requestCode, options); |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5897 | if (ar != null) { |
| 5898 | mMainThread.sendActivityResult( |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5899 | mToken, who, requestCode, |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5900 | ar.getResultCode(), ar.getResultData()); |
| 5901 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5902 | cancelInputsAndStartExitTransition(options); |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | /** |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5906 | * @hide |
| 5907 | */ |
| 5908 | @Override |
| 5909 | public boolean canStartActivityForResult() { |
| 5910 | return true; |
| 5911 | } |
| 5912 | |
| 5913 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5914 | * Same as calling {@link #startIntentSenderFromChild(Activity, IntentSender, |
| 5915 | * int, Intent, int, int, int, Bundle)} with no options. |
| 5916 | */ |
| 5917 | public void startIntentSenderFromChild(Activity child, IntentSender intent, |
| 5918 | int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, |
| 5919 | int extraFlags) |
| 5920 | throws IntentSender.SendIntentException { |
| 5921 | startIntentSenderFromChild(child, intent, requestCode, fillInIntent, |
| 5922 | flagsMask, flagsValues, extraFlags, null); |
| 5923 | } |
| 5924 | |
| 5925 | /** |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5926 | * Like {@link #startActivityFromChild(Activity, Intent, int)}, but |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5927 | * taking a IntentSender; see |
Dianne Hackborn | ae22c05 | 2009-09-17 18:46:22 -0700 | [diff] [blame] | 5928 | * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int)} |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5929 | * for more information. |
| 5930 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5931 | public void startIntentSenderFromChild(Activity child, IntentSender intent, |
| 5932 | int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5933 | int extraFlags, @Nullable Bundle options) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5934 | throws IntentSender.SendIntentException { |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 5935 | startIntentSenderForResultInner(intent, child.mEmbeddedID, requestCode, fillInIntent, |
| 5936 | flagsMask, flagsValues, options); |
| 5937 | } |
| 5938 | |
| 5939 | /** |
| 5940 | * Like {@link #startIntentSenderFromChild}, but taking a Fragment; see |
| 5941 | * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int)} |
| 5942 | * for more information. |
| 5943 | * |
| 5944 | * @hide |
| 5945 | */ |
| 5946 | public void startIntentSenderFromChildFragment(Fragment child, IntentSender intent, |
| 5947 | int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, |
| 5948 | int extraFlags, @Nullable Bundle options) |
| 5949 | throws IntentSender.SendIntentException { |
| 5950 | startIntentSenderForResultInner(intent, child.mWho, requestCode, fillInIntent, |
| 5951 | flagsMask, flagsValues, options); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5952 | } |
| 5953 | |
| 5954 | /** |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5955 | * Call immediately after one of the flavors of {@link #startActivity(Intent)} |
| 5956 | * or {@link #finish} to specify an explicit transition animation to |
| 5957 | * perform next. |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5958 | * |
| 5959 | * <p>As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN} an alternative |
| 5960 | * to using this with starting activities is to supply the desired animation |
| 5961 | * information through a {@link ActivityOptions} bundle to |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 5962 | * {@link #startActivity(Intent, Bundle)} or a related function. This allows |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5963 | * you to specify a custom animation even when starting an activity from |
| 5964 | * outside the context of the current top activity. |
| 5965 | * |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5966 | * @param enterAnim A resource ID of the animation resource to use for |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 5967 | * the incoming activity. Use 0 for no animation. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5968 | * @param exitAnim A resource ID of the animation resource to use for |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 5969 | * the outgoing activity. Use 0 for no animation. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5970 | */ |
| 5971 | public void overridePendingTransition(int enterAnim, int exitAnim) { |
| 5972 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 5973 | ActivityTaskManager.getService().overridePendingTransition( |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5974 | mToken, getPackageName(), enterAnim, exitAnim); |
| 5975 | } catch (RemoteException e) { |
| 5976 | } |
| 5977 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5978 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5979 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5980 | * Call this to set the result that your activity will return to its |
| 5981 | * caller. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5982 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5983 | * @param resultCode The result code to propagate back to the originating |
| 5984 | * activity, often RESULT_CANCELED or RESULT_OK |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5985 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5986 | * @see #RESULT_CANCELED |
| 5987 | * @see #RESULT_OK |
| 5988 | * @see #RESULT_FIRST_USER |
| 5989 | * @see #setResult(int, Intent) |
| 5990 | */ |
| 5991 | public final void setResult(int resultCode) { |
| 5992 | synchronized (this) { |
| 5993 | mResultCode = resultCode; |
| 5994 | mResultData = null; |
| 5995 | } |
| 5996 | } |
| 5997 | |
| 5998 | /** |
| 5999 | * Call this to set the result that your activity will return to its |
| 6000 | * caller. |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 6001 | * |
| 6002 | * <p>As of {@link android.os.Build.VERSION_CODES#GINGERBREAD}, the Intent |
| 6003 | * you supply here can have {@link Intent#FLAG_GRANT_READ_URI_PERMISSION |
| 6004 | * Intent.FLAG_GRANT_READ_URI_PERMISSION} and/or {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 6005 | * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} set. This will grant the |
| 6006 | * Activity receiving the result access to the specific URIs in the Intent. |
| 6007 | * Access will remain until the Activity has finished (it will remain across the hosting |
| 6008 | * process being killed and other temporary destruction) and will be added |
| 6009 | * to any existing set of URI permissions it already holds. |
| 6010 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6011 | * @param resultCode The result code to propagate back to the originating |
| 6012 | * activity, often RESULT_CANCELED or RESULT_OK |
| 6013 | * @param data The data to propagate back to the originating activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6014 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6015 | * @see #RESULT_CANCELED |
| 6016 | * @see #RESULT_OK |
| 6017 | * @see #RESULT_FIRST_USER |
| 6018 | * @see #setResult(int) |
| 6019 | */ |
| 6020 | public final void setResult(int resultCode, Intent data) { |
| 6021 | synchronized (this) { |
| 6022 | mResultCode = resultCode; |
| 6023 | mResultData = data; |
| 6024 | } |
| 6025 | } |
| 6026 | |
| 6027 | /** |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 6028 | * Return information about who launched this activity. If the launching Intent |
| 6029 | * contains an {@link android.content.Intent#EXTRA_REFERRER Intent.EXTRA_REFERRER}, |
| 6030 | * that will be returned as-is; otherwise, if known, an |
| 6031 | * {@link Intent#URI_ANDROID_APP_SCHEME android-app:} referrer URI containing the |
| 6032 | * package name that started the Intent will be returned. This may return null if no |
| 6033 | * referrer can be identified -- it is neither explicitly specified, nor is it known which |
| 6034 | * application package was involved. |
| 6035 | * |
| 6036 | * <p>If called while inside the handling of {@link #onNewIntent}, this function will |
| 6037 | * return the referrer that submitted that new intent to the activity. Otherwise, it |
| 6038 | * always returns the referrer of the original Intent.</p> |
| 6039 | * |
| 6040 | * <p>Note that this is <em>not</em> a security feature -- you can not trust the |
| 6041 | * referrer information, applications can spoof it.</p> |
| 6042 | */ |
| 6043 | @Nullable |
| 6044 | public Uri getReferrer() { |
| 6045 | Intent intent = getIntent(); |
Adam Powell | d3c63a6 | 2016-06-09 12:36:16 -0700 | [diff] [blame] | 6046 | try { |
| 6047 | Uri referrer = intent.getParcelableExtra(Intent.EXTRA_REFERRER); |
| 6048 | if (referrer != null) { |
| 6049 | return referrer; |
| 6050 | } |
| 6051 | String referrerName = intent.getStringExtra(Intent.EXTRA_REFERRER_NAME); |
| 6052 | if (referrerName != null) { |
| 6053 | return Uri.parse(referrerName); |
| 6054 | } |
| 6055 | } catch (BadParcelableException e) { |
| 6056 | Log.w(TAG, "Cannot read referrer from intent;" |
| 6057 | + " intent extras contain unknown custom Parcelable objects"); |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 6058 | } |
| 6059 | if (mReferrer != null) { |
| 6060 | return new Uri.Builder().scheme("android-app").authority(mReferrer).build(); |
| 6061 | } |
| 6062 | return null; |
| 6063 | } |
| 6064 | |
| 6065 | /** |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 6066 | * Override to generate the desired referrer for the content currently being shown |
| 6067 | * by the app. The default implementation returns null, meaning the referrer will simply |
| 6068 | * be the android-app: of the package name of this activity. Return a non-null Uri to |
| 6069 | * have that supplied as the {@link Intent#EXTRA_REFERRER} of any activities started from it. |
| 6070 | */ |
| 6071 | public Uri onProvideReferrer() { |
| 6072 | return null; |
| 6073 | } |
| 6074 | |
| 6075 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6076 | * Return the name of the package that invoked this activity. This is who |
| 6077 | * the data in {@link #setResult setResult()} will be sent to. You can |
| 6078 | * use this information to validate that the recipient is allowed to |
| 6079 | * receive the data. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6080 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 6081 | * <p class="note">Note: if the calling activity is not expecting a result (that is it |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6082 | * did not use the {@link #startActivityForResult} |
| 6083 | * form that includes a request code), then the calling package will be |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 6084 | * null.</p> |
| 6085 | * |
| 6086 | * <p class="note">Note: prior to {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, |
| 6087 | * the result from this method was unstable. If the process hosting the calling |
| 6088 | * package was no longer running, it would return null instead of the proper package |
| 6089 | * name. You can use {@link #getCallingActivity()} and retrieve the package name |
| 6090 | * from that instead.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6091 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6092 | * @return The package of the activity that will receive your |
| 6093 | * reply, or null if none. |
| 6094 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6095 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6096 | public String getCallingPackage() { |
| 6097 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6098 | return ActivityTaskManager.getService().getCallingPackage(mToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6099 | } catch (RemoteException e) { |
| 6100 | return null; |
| 6101 | } |
| 6102 | } |
| 6103 | |
| 6104 | /** |
| 6105 | * Return the name of the activity that invoked this activity. This is |
| 6106 | * who the data in {@link #setResult setResult()} will be sent to. You |
| 6107 | * can use this information to validate that the recipient is allowed to |
| 6108 | * receive the data. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6109 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 6110 | * <p class="note">Note: if the calling activity is not expecting a result (that is it |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6111 | * did not use the {@link #startActivityForResult} |
| 6112 | * form that includes a request code), then the calling package will be |
| 6113 | * null. |
| 6114 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 6115 | * @return The ComponentName of the activity that will receive your |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6116 | * reply, or null if none. |
| 6117 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6118 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6119 | public ComponentName getCallingActivity() { |
| 6120 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6121 | return ActivityTaskManager.getService().getCallingActivity(mToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6122 | } catch (RemoteException e) { |
| 6123 | return null; |
| 6124 | } |
| 6125 | } |
| 6126 | |
| 6127 | /** |
| 6128 | * Control whether this activity's main window is visible. This is intended |
| 6129 | * only for the special case of an activity that is not going to show a |
| 6130 | * UI itself, but can't just finish prior to onResume() because it needs |
| 6131 | * to wait for a service binding or such. Setting this to false allows |
| 6132 | * you to prevent your UI from being shown during that time. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6133 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6134 | * <p>The default value for this is taken from the |
| 6135 | * {@link android.R.attr#windowNoDisplay} attribute of the activity's theme. |
| 6136 | */ |
| 6137 | public void setVisible(boolean visible) { |
| 6138 | if (mVisibleFromClient != visible) { |
| 6139 | mVisibleFromClient = visible; |
| 6140 | if (mVisibleFromServer) { |
| 6141 | if (visible) makeVisible(); |
| 6142 | else mDecor.setVisibility(View.INVISIBLE); |
| 6143 | } |
| 6144 | } |
| 6145 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6146 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6147 | void makeVisible() { |
| 6148 | if (!mWindowAdded) { |
| 6149 | ViewManager wm = getWindowManager(); |
| 6150 | wm.addView(mDecor, getWindow().getAttributes()); |
| 6151 | mWindowAdded = true; |
| 6152 | } |
| 6153 | mDecor.setVisibility(View.VISIBLE); |
| 6154 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6155 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6156 | /** |
| 6157 | * Check to see whether this activity is in the process of finishing, |
| 6158 | * either because you called {@link #finish} on it or someone else |
| 6159 | * has requested that it finished. This is often used in |
| 6160 | * {@link #onPause} to determine whether the activity is simply pausing or |
| 6161 | * completely finishing. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6162 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6163 | * @return If the activity is finishing, returns true; else returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6164 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6165 | * @see #finish |
| 6166 | */ |
| 6167 | public boolean isFinishing() { |
| 6168 | return mFinished; |
| 6169 | } |
| 6170 | |
| 6171 | /** |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 6172 | * Returns true if the final {@link #onDestroy()} call has been made |
| 6173 | * on the Activity, so this instance is now dead. |
| 6174 | */ |
| 6175 | public boolean isDestroyed() { |
| 6176 | return mDestroyed; |
| 6177 | } |
| 6178 | |
| 6179 | /** |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 6180 | * Check to see whether this activity is in the process of being destroyed in order to be |
| 6181 | * recreated with a new configuration. This is often used in |
| 6182 | * {@link #onStop} to determine whether the state needs to be cleaned up or will be passed |
| 6183 | * on to the next instance of the activity via {@link #onRetainNonConfigurationInstance()}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6184 | * |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 6185 | * @return If the activity is being torn down in order to be recreated with a new configuration, |
| 6186 | * returns true; else returns false. |
| 6187 | */ |
| 6188 | public boolean isChangingConfigurations() { |
| 6189 | return mChangingConfigurations; |
| 6190 | } |
| 6191 | |
| 6192 | /** |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 6193 | * Cause this Activity to be recreated with a new instance. This results |
| 6194 | * in essentially the same flow as when the Activity is created due to |
| 6195 | * a configuration change -- the current instance will go through its |
| 6196 | * lifecycle to {@link #onDestroy} and a new instance then created after it. |
| 6197 | */ |
| 6198 | public void recreate() { |
| 6199 | if (mParent != null) { |
| 6200 | throw new IllegalStateException("Can only be called on top-level activity"); |
| 6201 | } |
Wale Ogunwale | 0527d91 | 2018-05-16 17:23:48 -0700 | [diff] [blame] | 6202 | if (Looper.myLooper() != mMainThread.getLooper()) { |
| 6203 | throw new IllegalStateException("Must be called from main thread"); |
| 6204 | } |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 6205 | mMainThread.scheduleRelaunchActivity(mToken); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 6206 | } |
| 6207 | |
| 6208 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 6209 | * Finishes the current activity and specifies whether to remove the task associated with this |
| 6210 | * activity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6211 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6212 | @UnsupportedAppUsage |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 6213 | private void finish(int finishTask) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6214 | if (mParent == null) { |
| 6215 | int resultCode; |
| 6216 | Intent resultData; |
| 6217 | synchronized (this) { |
| 6218 | resultCode = mResultCode; |
| 6219 | resultData = mResultData; |
| 6220 | } |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 6221 | if (false) Log.v(TAG, "Finishing self: token=" + mToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6222 | try { |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 6223 | if (resultData != null) { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 6224 | resultData.prepareToLeaveProcess(this); |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 6225 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6226 | if (ActivityTaskManager.getService() |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 6227 | .finishActivity(mToken, resultCode, resultData, finishTask)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6228 | mFinished = true; |
| 6229 | } |
| 6230 | } catch (RemoteException e) { |
| 6231 | // Empty |
| 6232 | } |
| 6233 | } else { |
| 6234 | mParent.finishFromChild(this); |
| 6235 | } |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 6236 | |
| 6237 | // Activity was launched when user tapped a link in the Autofill Save UI - Save UI must |
| 6238 | // be restored now. |
| 6239 | if (mIntent != null && mIntent.hasExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN)) { |
| 6240 | getAutofillManager().onPendingSaveUi(AutofillManager.PENDING_UI_OPERATION_RESTORE, |
| 6241 | mIntent.getIBinderExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN)); |
| 6242 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6243 | } |
| 6244 | |
| 6245 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 6246 | * Call this when your activity is done and should be closed. The |
| 6247 | * ActivityResult is propagated back to whoever launched you via |
| 6248 | * onActivityResult(). |
| 6249 | */ |
| 6250 | public void finish() { |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 6251 | finish(DONT_FINISH_TASK_WITH_ACTIVITY); |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 6252 | } |
| 6253 | |
| 6254 | /** |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 6255 | * Finish this activity as well as all activities immediately below it |
| 6256 | * in the current task that have the same affinity. This is typically |
| 6257 | * used when an application can be launched on to another task (such as |
| 6258 | * from an ACTION_VIEW of a content type it understands) and the user |
| 6259 | * has used the up navigation to switch out of the current task and in |
| 6260 | * to its own task. In this case, if the user has navigated down into |
| 6261 | * any other activities of the second application, all of those should |
| 6262 | * be removed from the original task as part of the task switch. |
| 6263 | * |
| 6264 | * <p>Note that this finish does <em>not</em> allow you to deliver results |
| 6265 | * to the previous activity, and an exception will be thrown if you are trying |
| 6266 | * to do so.</p> |
| 6267 | */ |
| 6268 | public void finishAffinity() { |
| 6269 | if (mParent != null) { |
| 6270 | throw new IllegalStateException("Can not be called from an embedded activity"); |
| 6271 | } |
| 6272 | if (mResultCode != RESULT_CANCELED || mResultData != null) { |
| 6273 | throw new IllegalStateException("Can not be called to deliver a result"); |
| 6274 | } |
| 6275 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6276 | if (ActivityTaskManager.getService().finishActivityAffinity(mToken)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 6277 | mFinished = true; |
| 6278 | } |
| 6279 | } catch (RemoteException e) { |
| 6280 | // Empty |
| 6281 | } |
| 6282 | } |
| 6283 | |
| 6284 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6285 | * This is called when a child activity of this one calls its |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6286 | * {@link #finish} method. The default implementation simply calls |
| 6287 | * finish() on this activity (the parent), finishing the entire group. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6288 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6289 | * @param child The activity making the call. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6290 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6291 | * @see #finish |
| 6292 | */ |
| 6293 | public void finishFromChild(Activity child) { |
| 6294 | finish(); |
| 6295 | } |
| 6296 | |
| 6297 | /** |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 6298 | * Reverses the Activity Scene entry Transition and triggers the calling Activity |
| 6299 | * to reverse its exit Transition. When the exit Transition completes, |
| 6300 | * {@link #finish()} is called. If no entry Transition was used, finish() is called |
| 6301 | * immediately and the Activity exit Transition is run. |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6302 | * @see android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, android.util.Pair[]) |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 6303 | */ |
Craig Mautner | 73f843d | 2014-05-19 09:42:28 -0700 | [diff] [blame] | 6304 | public void finishAfterTransition() { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6305 | if (!mActivityTransitionState.startExitBackTransition(this)) { |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 6306 | finish(); |
| 6307 | } |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 6308 | } |
| 6309 | |
| 6310 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6311 | * Force finish another activity that you had previously started with |
| 6312 | * {@link #startActivityForResult}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6313 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6314 | * @param requestCode The request code of the activity that you had |
| 6315 | * given to startActivityForResult(). If there are multiple |
| 6316 | * activities started with this request code, they |
| 6317 | * will all be finished. |
| 6318 | */ |
| 6319 | public void finishActivity(int requestCode) { |
| 6320 | if (mParent == null) { |
| 6321 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6322 | ActivityTaskManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6323 | .finishSubActivity(mToken, mEmbeddedID, requestCode); |
| 6324 | } catch (RemoteException e) { |
| 6325 | // Empty |
| 6326 | } |
| 6327 | } else { |
| 6328 | mParent.finishActivityFromChild(this, requestCode); |
| 6329 | } |
| 6330 | } |
| 6331 | |
| 6332 | /** |
| 6333 | * This is called when a child activity of this one calls its |
| 6334 | * finishActivity(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6335 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6336 | * @param child The activity making the call. |
| 6337 | * @param requestCode Request code that had been used to start the |
| 6338 | * activity. |
| 6339 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6340 | public void finishActivityFromChild(@NonNull Activity child, int requestCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6341 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6342 | ActivityTaskManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6343 | .finishSubActivity(mToken, child.mEmbeddedID, requestCode); |
| 6344 | } catch (RemoteException e) { |
| 6345 | // Empty |
| 6346 | } |
| 6347 | } |
| 6348 | |
| 6349 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 6350 | * Call this when your activity is done and should be closed and the task should be completely |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 6351 | * removed as a part of finishing the root activity of the task. |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 6352 | */ |
| 6353 | public void finishAndRemoveTask() { |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 6354 | finish(FINISH_TASK_WITH_ROOT_ACTIVITY); |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 6355 | } |
| 6356 | |
| 6357 | /** |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6358 | * Ask that the local app instance of this activity be released to free up its memory. |
| 6359 | * This is asking for the activity to be destroyed, but does <b>not</b> finish the activity -- |
| 6360 | * a new instance of the activity will later be re-created if needed due to the user |
| 6361 | * navigating back to it. |
| 6362 | * |
| 6363 | * @return Returns true if the activity was in a state that it has started the process |
| 6364 | * of destroying its current instance; returns false if for any reason this could not |
| 6365 | * be done: it is currently visible to the user, it is already being destroyed, it is |
| 6366 | * being finished, it hasn't yet saved its state, etc. |
| 6367 | */ |
| 6368 | public boolean releaseInstance() { |
| 6369 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6370 | return ActivityTaskManager.getService().releaseActivityInstance(mToken); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6371 | } catch (RemoteException e) { |
| 6372 | // Empty |
| 6373 | } |
| 6374 | return false; |
| 6375 | } |
| 6376 | |
| 6377 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6378 | * Called when an activity you launched exits, giving you the requestCode |
| 6379 | * you started it with, the resultCode it returned, and any additional |
| 6380 | * data from it. The <var>resultCode</var> will be |
| 6381 | * {@link #RESULT_CANCELED} if the activity explicitly returned that, |
| 6382 | * didn't return any result, or crashed during its operation. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6383 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6384 | * <p>You will receive this call immediately before onResume() when your |
| 6385 | * activity is re-starting. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6386 | * |
Ricardo Cervera | 92f6a74 | 2014-04-04 11:17:06 -0700 | [diff] [blame] | 6387 | * <p>This method is never invoked if your activity sets |
| 6388 | * {@link android.R.styleable#AndroidManifestActivity_noHistory noHistory} to |
| 6389 | * <code>true</code>. |
Ricardo Cervera | 93f94c2 | 2015-01-16 09:54:30 -0800 | [diff] [blame] | 6390 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6391 | * @param requestCode The integer request code originally supplied to |
| 6392 | * startActivityForResult(), allowing you to identify who this |
| 6393 | * result came from. |
| 6394 | * @param resultCode The integer result code returned by the child activity |
| 6395 | * through its setResult(). |
| 6396 | * @param data An Intent, which can return result data to the caller |
| 6397 | * (various data can be attached to Intent "extras"). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6398 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6399 | * @see #startActivityForResult |
| 6400 | * @see #createPendingResult |
| 6401 | * @see #setResult(int) |
| 6402 | */ |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 6403 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6404 | } |
| 6405 | |
| 6406 | /** |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6407 | * Called when an activity you launched with an activity transition exposes this |
| 6408 | * Activity through a returning activity transition, giving you the resultCode |
| 6409 | * and any additional data from it. This method will only be called if the activity |
| 6410 | * set a result code other than {@link #RESULT_CANCELED} and it supports activity |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 6411 | * transitions with {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6412 | * |
| 6413 | * <p>The purpose of this function is to let the called Activity send a hint about |
| 6414 | * its state so that this underlying Activity can prepare to be exposed. A call to |
| 6415 | * this method does not guarantee that the called Activity has or will be exiting soon. |
| 6416 | * It only indicates that it will expose this Activity's Window and it has |
| 6417 | * some data to pass to prepare it.</p> |
| 6418 | * |
| 6419 | * @param resultCode The integer result code returned by the child activity |
| 6420 | * through its setResult(). |
| 6421 | * @param data An Intent, which can return result data to the caller |
| 6422 | * (various data can be attached to Intent "extras"). |
| 6423 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 6424 | public void onActivityReenter(int resultCode, Intent data) { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6425 | } |
| 6426 | |
| 6427 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6428 | * Create a new PendingIntent object which you can hand to others |
| 6429 | * for them to use to send result data back to your |
| 6430 | * {@link #onActivityResult} callback. The created object will be either |
| 6431 | * one-shot (becoming invalid after a result is sent back) or multiple |
| 6432 | * (allowing any number of results to be sent through it). |
| 6433 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6434 | * @param requestCode Private request code for the sender that will be |
| 6435 | * associated with the result data when it is returned. The sender can not |
| 6436 | * modify this value, allowing you to identify incoming results. |
| 6437 | * @param data Default data to supply in the result, which may be modified |
| 6438 | * by the sender. |
| 6439 | * @param flags May be {@link PendingIntent#FLAG_ONE_SHOT PendingIntent.FLAG_ONE_SHOT}, |
| 6440 | * {@link PendingIntent#FLAG_NO_CREATE PendingIntent.FLAG_NO_CREATE}, |
| 6441 | * {@link PendingIntent#FLAG_CANCEL_CURRENT PendingIntent.FLAG_CANCEL_CURRENT}, |
| 6442 | * {@link PendingIntent#FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT}, |
| 6443 | * or any of the flags as supported by |
| 6444 | * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts |
| 6445 | * of the intent that can be supplied when the actual send happens. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6446 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6447 | * @return Returns an existing or new PendingIntent matching the given |
| 6448 | * parameters. May return null only if |
| 6449 | * {@link PendingIntent#FLAG_NO_CREATE PendingIntent.FLAG_NO_CREATE} has been |
| 6450 | * supplied. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6451 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6452 | * @see PendingIntent |
| 6453 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6454 | public PendingIntent createPendingResult(int requestCode, @NonNull Intent data, |
| 6455 | @PendingIntent.Flags int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6456 | String packageName = getPackageName(); |
| 6457 | try { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 6458 | data.prepareToLeaveProcess(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6459 | IIntentSender target = |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6460 | ActivityManager.getService().getIntentSender( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6461 | ActivityManager.INTENT_SENDER_ACTIVITY_RESULT, packageName, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6462 | mParent == null ? mToken : mParent.mToken, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 6463 | mEmbeddedID, requestCode, new Intent[] { data }, null, flags, null, |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 6464 | getUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6465 | return target != null ? new PendingIntent(target) : null; |
| 6466 | } catch (RemoteException e) { |
| 6467 | // Empty |
| 6468 | } |
| 6469 | return null; |
| 6470 | } |
| 6471 | |
| 6472 | /** |
| 6473 | * Change the desired orientation of this activity. If the activity |
| 6474 | * is currently in the foreground or otherwise impacting the screen |
| 6475 | * orientation, the screen will immediately be changed (possibly causing |
| 6476 | * the activity to be restarted). Otherwise, this will be used the next |
| 6477 | * time the activity is visible. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6478 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6479 | * @param requestedOrientation An orientation constant as used in |
| 6480 | * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}. |
| 6481 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6482 | public void setRequestedOrientation(@ActivityInfo.ScreenOrientation int requestedOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6483 | if (mParent == null) { |
| 6484 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6485 | ActivityTaskManager.getService().setRequestedOrientation( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6486 | mToken, requestedOrientation); |
| 6487 | } catch (RemoteException e) { |
| 6488 | // Empty |
| 6489 | } |
| 6490 | } else { |
| 6491 | mParent.setRequestedOrientation(requestedOrientation); |
| 6492 | } |
| 6493 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6495 | /** |
| 6496 | * Return the current requested orientation of the activity. This will |
| 6497 | * either be the orientation requested in its component's manifest, or |
| 6498 | * the last requested orientation given to |
| 6499 | * {@link #setRequestedOrientation(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6500 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6501 | * @return Returns an orientation constant as used in |
| 6502 | * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}. |
| 6503 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6504 | @ActivityInfo.ScreenOrientation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6505 | public int getRequestedOrientation() { |
| 6506 | if (mParent == null) { |
| 6507 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6508 | return ActivityTaskManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6509 | .getRequestedOrientation(mToken); |
| 6510 | } catch (RemoteException e) { |
| 6511 | // Empty |
| 6512 | } |
| 6513 | } else { |
| 6514 | return mParent.getRequestedOrientation(); |
| 6515 | } |
| 6516 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 6517 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6519 | /** |
| 6520 | * Return the identifier of the task this activity is in. This identifier |
| 6521 | * will remain the same for the lifetime of the activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6522 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6523 | * @return Task identifier, an opaque integer. |
| 6524 | */ |
| 6525 | public int getTaskId() { |
| 6526 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6527 | return ActivityTaskManager.getService().getTaskForActivity(mToken, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6528 | } catch (RemoteException e) { |
| 6529 | return -1; |
| 6530 | } |
| 6531 | } |
| 6532 | |
| 6533 | /** |
| 6534 | * Return whether this activity is the root of a task. The root is the |
| 6535 | * first activity in a task. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6536 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6537 | * @return True if this is the root activity, else false. |
| 6538 | */ |
Winson Chung | 4d8681f | 2017-05-23 16:22:08 -0700 | [diff] [blame] | 6539 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6540 | public boolean isTaskRoot() { |
| 6541 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6542 | return ActivityTaskManager.getService().getTaskForActivity(mToken, true) >= 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6543 | } catch (RemoteException e) { |
| 6544 | return false; |
| 6545 | } |
| 6546 | } |
| 6547 | |
| 6548 | /** |
| 6549 | * Move the task containing this activity to the back of the activity |
| 6550 | * stack. The activity's order within the task is unchanged. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6551 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6552 | * @param nonRoot If false then this only works if the activity is the root |
| 6553 | * of a task; if true it will work for any activity in |
| 6554 | * a task. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6555 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6556 | * @return If the task was moved (or it was already at the |
| 6557 | * back) true is returned, else false. |
| 6558 | */ |
| 6559 | public boolean moveTaskToBack(boolean nonRoot) { |
| 6560 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6561 | return ActivityTaskManager.getService().moveActivityTaskToBack(mToken, nonRoot); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6562 | } catch (RemoteException e) { |
| 6563 | // Empty |
| 6564 | } |
| 6565 | return false; |
| 6566 | } |
| 6567 | |
| 6568 | /** |
| 6569 | * Returns class name for this activity with the package prefix removed. |
| 6570 | * This is the default name used to read and write settings. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6571 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6572 | * @return The local class name. |
| 6573 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6574 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6575 | public String getLocalClassName() { |
| 6576 | final String pkg = getPackageName(); |
| 6577 | final String cls = mComponent.getClassName(); |
| 6578 | int packageLen = pkg.length(); |
| 6579 | if (!cls.startsWith(pkg) || cls.length() <= packageLen |
| 6580 | || cls.charAt(packageLen) != '.') { |
| 6581 | return cls; |
| 6582 | } |
| 6583 | return cls.substring(packageLen+1); |
| 6584 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6585 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6586 | /** |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 6587 | * Returns the complete component name of this activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6588 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6589 | * @return Returns the complete component name for this activity |
| 6590 | */ |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 6591 | public ComponentName getComponentName() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6592 | return mComponent; |
| 6593 | } |
| 6594 | |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 6595 | /** @hide */ |
| 6596 | @Override |
| 6597 | public final ComponentName autofillClientGetComponentName() { |
| 6598 | return getComponentName(); |
| 6599 | } |
| 6600 | |
Felipe Leme | cbf7f26 | 2019-04-17 13:57:59 -0700 | [diff] [blame] | 6601 | /** @hide */ |
| 6602 | @Override |
| 6603 | public final ComponentName contentCaptureClientGetComponentName() { |
| 6604 | return getComponentName(); |
| 6605 | } |
| 6606 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6607 | /** |
| 6608 | * Retrieve a {@link SharedPreferences} object for accessing preferences |
| 6609 | * that are private to this activity. This simply calls the underlying |
| 6610 | * {@link #getSharedPreferences(String, int)} method by passing in this activity's |
| 6611 | * class name as the preferences name. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6612 | * |
| 6613 | * @param mode Operating mode. Use {@link #MODE_PRIVATE} for the default |
Jeff Sharkey | 634dc42 | 2016-01-30 17:44:15 -0700 | [diff] [blame] | 6614 | * operation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6615 | * |
| 6616 | * @return Returns the single SharedPreferences instance that can be used |
| 6617 | * to retrieve and modify the preference values. |
| 6618 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 6619 | public SharedPreferences getPreferences(@Context.PreferencesMode int mode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6620 | return getSharedPreferences(getLocalClassName(), mode); |
| 6621 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6622 | |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 6623 | private void ensureSearchManager() { |
| 6624 | if (mSearchManager != null) { |
| 6625 | return; |
| 6626 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6627 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 6628 | try { |
| 6629 | mSearchManager = new SearchManager(this, null); |
| 6630 | } catch (ServiceNotFoundException e) { |
| 6631 | throw new IllegalStateException(e); |
| 6632 | } |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 6633 | } |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6635 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6636 | public Object getSystemService(@ServiceName @NonNull String name) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6637 | if (getBaseContext() == null) { |
| 6638 | throw new IllegalStateException( |
| 6639 | "System services not available to Activities before onCreate()"); |
| 6640 | } |
| 6641 | |
| 6642 | if (WINDOW_SERVICE.equals(name)) { |
| 6643 | return mWindowManager; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 6644 | } else if (SEARCH_SERVICE.equals(name)) { |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 6645 | ensureSearchManager(); |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 6646 | return mSearchManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6647 | } |
| 6648 | return super.getSystemService(name); |
| 6649 | } |
| 6650 | |
| 6651 | /** |
| 6652 | * Change the title associated with this activity. If this is a |
| 6653 | * top-level activity, the title for its window will change. If it |
| 6654 | * is an embedded activity, the parent can do whatever it wants |
| 6655 | * with it. |
| 6656 | */ |
| 6657 | public void setTitle(CharSequence title) { |
| 6658 | mTitle = title; |
| 6659 | onTitleChanged(title, mTitleColor); |
| 6660 | |
| 6661 | if (mParent != null) { |
| 6662 | mParent.onChildTitleChanged(this, title); |
| 6663 | } |
| 6664 | } |
| 6665 | |
| 6666 | /** |
| 6667 | * Change the title associated with this activity. If this is a |
| 6668 | * top-level activity, the title for its window will change. If it |
| 6669 | * is an embedded activity, the parent can do whatever it wants |
| 6670 | * with it. |
| 6671 | */ |
| 6672 | public void setTitle(int titleId) { |
| 6673 | setTitle(getText(titleId)); |
| 6674 | } |
| 6675 | |
Alan Viverette | 2525d9c | 2013-11-15 14:42:19 -0800 | [diff] [blame] | 6676 | /** |
| 6677 | * Change the color of the title associated with this activity. |
| 6678 | * <p> |
| 6679 | * This method is deprecated starting in API Level 11 and replaced by action |
| 6680 | * bar styles. For information on styling the Action Bar, read the <a |
| 6681 | * href="{@docRoot} guide/topics/ui/actionbar.html">Action Bar</a> developer |
| 6682 | * guide. |
| 6683 | * |
| 6684 | * @deprecated Use action bar styles instead. |
| 6685 | */ |
| 6686 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6687 | public void setTitleColor(int textColor) { |
| 6688 | mTitleColor = textColor; |
| 6689 | onTitleChanged(mTitle, textColor); |
| 6690 | } |
| 6691 | |
| 6692 | public final CharSequence getTitle() { |
| 6693 | return mTitle; |
| 6694 | } |
| 6695 | |
| 6696 | public final int getTitleColor() { |
| 6697 | return mTitleColor; |
| 6698 | } |
| 6699 | |
| 6700 | protected void onTitleChanged(CharSequence title, int color) { |
| 6701 | if (mTitleReady) { |
| 6702 | final Window win = getWindow(); |
| 6703 | if (win != null) { |
| 6704 | win.setTitle(title); |
| 6705 | if (color != 0) { |
| 6706 | win.setTitleColor(color); |
| 6707 | } |
| 6708 | } |
Adam Powell | af2d859 | 2014-08-26 18:06:40 -0700 | [diff] [blame] | 6709 | if (mActionBar != null) { |
| 6710 | mActionBar.setWindowTitle(title); |
| 6711 | } |
Adam Powell | a557fdc | 2014-08-21 18:05:53 -0700 | [diff] [blame] | 6712 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6713 | } |
| 6714 | |
| 6715 | protected void onChildTitleChanged(Activity childActivity, CharSequence title) { |
| 6716 | } |
| 6717 | |
| 6718 | /** |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 6719 | * Sets information describing the task with this activity for presentation inside the Recents |
| 6720 | * System UI. When {@link ActivityManager#getRecentTasks} is called, the activities of each task |
| 6721 | * are traversed in order from the topmost activity to the bottommost. The traversal continues |
| 6722 | * for each property until a suitable value is found. For each task the taskDescription will be |
| 6723 | * returned in {@link android.app.ActivityManager.TaskDescription}. |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6724 | * |
| 6725 | * @see ActivityManager#getRecentTasks |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 6726 | * @see android.app.ActivityManager.TaskDescription |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6727 | * |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 6728 | * @param taskDescription The TaskDescription properties that describe the task with this activity |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6729 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 6730 | public void setTaskDescription(ActivityManager.TaskDescription taskDescription) { |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 6731 | if (mTaskDescription != taskDescription) { |
Jorim Jaggi | f4156ea | 2017-04-10 18:39:04 -0700 | [diff] [blame] | 6732 | mTaskDescription.copyFromPreserveHiddenFields(taskDescription); |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 6733 | // Scale the icon down to something reasonable if it is provided |
| 6734 | if (taskDescription.getIconFilename() == null && taskDescription.getIcon() != null) { |
| 6735 | final int size = ActivityManager.getLauncherLargeIconSizeInner(this); |
| 6736 | final Bitmap icon = Bitmap.createScaledBitmap(taskDescription.getIcon(), size, size, |
| 6737 | true); |
| 6738 | mTaskDescription.setIcon(icon); |
| 6739 | } |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6740 | } |
| 6741 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6742 | ActivityTaskManager.getService().setTaskDescription(mToken, mTaskDescription); |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6743 | } catch (RemoteException e) { |
| 6744 | } |
| 6745 | } |
| 6746 | |
| 6747 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6748 | * Sets the visibility of the progress bar in the title. |
| 6749 | * <p> |
| 6750 | * In order for the progress bar to be shown, the feature must be requested |
| 6751 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6752 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6753 | * @param visible Whether to show the progress bars in the title. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6754 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6755 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6756 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6757 | public final void setProgressBarVisibility(boolean visible) { |
| 6758 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, visible ? Window.PROGRESS_VISIBILITY_ON : |
| 6759 | Window.PROGRESS_VISIBILITY_OFF); |
| 6760 | } |
| 6761 | |
| 6762 | /** |
| 6763 | * Sets the visibility of the indeterminate progress bar in the title. |
| 6764 | * <p> |
| 6765 | * In order for the progress bar to be shown, the feature must be requested |
| 6766 | * via {@link #requestWindowFeature(int)}. |
| 6767 | * |
| 6768 | * @param visible Whether to show the progress bars in the title. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6769 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6770 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6771 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6772 | public final void setProgressBarIndeterminateVisibility(boolean visible) { |
| 6773 | getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, |
| 6774 | visible ? Window.PROGRESS_VISIBILITY_ON : Window.PROGRESS_VISIBILITY_OFF); |
| 6775 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6777 | /** |
| 6778 | * Sets whether the horizontal progress bar in the title should be indeterminate (the circular |
| 6779 | * is always indeterminate). |
| 6780 | * <p> |
| 6781 | * In order for the progress bar to be shown, the feature must be requested |
| 6782 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6783 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6784 | * @param indeterminate Whether the horizontal progress bar should be indeterminate. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6785 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6786 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6787 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6788 | public final void setProgressBarIndeterminate(boolean indeterminate) { |
| 6789 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 6790 | indeterminate ? Window.PROGRESS_INDETERMINATE_ON |
| 6791 | : Window.PROGRESS_INDETERMINATE_OFF); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6792 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6794 | /** |
| 6795 | * Sets the progress for the progress bars in the title. |
| 6796 | * <p> |
| 6797 | * In order for the progress bar to be shown, the feature must be requested |
| 6798 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6799 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6800 | * @param progress The progress for the progress bar. Valid ranges are from |
| 6801 | * 0 to 10000 (both inclusive). If 10000 is given, the progress |
| 6802 | * bar will be completely filled and will fade out. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6803 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6804 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6805 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6806 | public final void setProgress(int progress) { |
| 6807 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, progress + Window.PROGRESS_START); |
| 6808 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6809 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6810 | /** |
| 6811 | * Sets the secondary progress for the progress bar in the title. This |
| 6812 | * progress is drawn between the primary progress (set via |
| 6813 | * {@link #setProgress(int)} and the background. It can be ideal for media |
| 6814 | * scenarios such as showing the buffering progress while the default |
| 6815 | * progress shows the play progress. |
| 6816 | * <p> |
| 6817 | * In order for the progress bar to be shown, the feature must be requested |
| 6818 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6819 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6820 | * @param secondaryProgress The secondary progress for the progress bar. Valid ranges are from |
| 6821 | * 0 to 10000 (both inclusive). |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6822 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6823 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6824 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6825 | public final void setSecondaryProgress(int secondaryProgress) { |
| 6826 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, |
| 6827 | secondaryProgress + Window.PROGRESS_SECONDARY_START); |
| 6828 | } |
| 6829 | |
| 6830 | /** |
| 6831 | * Suggests an audio stream whose volume should be changed by the hardware |
| 6832 | * volume controls. |
| 6833 | * <p> |
| 6834 | * The suggested audio stream will be tied to the window of this Activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6835 | * Volume requests which are received while the Activity is in the |
| 6836 | * foreground will affect this stream. |
| 6837 | * <p> |
| 6838 | * It is not guaranteed that the hardware volume controls will always change |
| 6839 | * this stream's volume (for example, if a call is in progress, its stream's |
| 6840 | * volume may be changed instead). To reset back to the default, use |
| 6841 | * {@link AudioManager#USE_DEFAULT_STREAM_TYPE}. |
| 6842 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6843 | * @param streamType The type of the audio stream whose volume should be |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6844 | * changed by the hardware volume controls. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6845 | */ |
| 6846 | public final void setVolumeControlStream(int streamType) { |
| 6847 | getWindow().setVolumeControlStream(streamType); |
| 6848 | } |
| 6849 | |
| 6850 | /** |
| 6851 | * Gets the suggested audio stream whose volume should be changed by the |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6852 | * hardware volume controls. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6853 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6854 | * @return The suggested audio stream type whose volume should be changed by |
| 6855 | * the hardware volume controls. |
| 6856 | * @see #setVolumeControlStream(int) |
| 6857 | */ |
| 6858 | public final int getVolumeControlStream() { |
| 6859 | return getWindow().getVolumeControlStream(); |
| 6860 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6861 | |
| 6862 | /** |
| 6863 | * Sets a {@link MediaController} to send media keys and volume changes to. |
| 6864 | * <p> |
| 6865 | * The controller will be tied to the window of this Activity. Media key and |
| 6866 | * volume events which are received while the Activity is in the foreground |
| 6867 | * will be forwarded to the controller and used to invoke transport controls |
| 6868 | * or adjust the volume. This may be used instead of or in addition to |
| 6869 | * {@link #setVolumeControlStream} to affect a specific session instead of a |
| 6870 | * specific stream. |
| 6871 | * <p> |
| 6872 | * It is not guaranteed that the hardware volume controls will always change |
| 6873 | * this session's volume (for example, if a call is in progress, its |
| 6874 | * stream's volume may be changed instead). To reset back to the default use |
| 6875 | * null as the controller. |
| 6876 | * |
| 6877 | * @param controller The controller for the session which should receive |
| 6878 | * media keys and volume changes. |
| 6879 | */ |
| 6880 | public final void setMediaController(MediaController controller) { |
| 6881 | getWindow().setMediaController(controller); |
| 6882 | } |
| 6883 | |
| 6884 | /** |
| 6885 | * Gets the controller which should be receiving media key and volume events |
| 6886 | * while this activity is in the foreground. |
| 6887 | * |
| 6888 | * @return The controller which should receive events. |
| 6889 | * @see #setMediaController(android.media.session.MediaController) |
| 6890 | */ |
| 6891 | public final MediaController getMediaController() { |
| 6892 | return getWindow().getMediaController(); |
| 6893 | } |
| 6894 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6895 | /** |
| 6896 | * Runs the specified action on the UI thread. If the current thread is the UI |
| 6897 | * thread, then the action is executed immediately. If the current thread is |
| 6898 | * not the UI thread, the action is posted to the event queue of the UI thread. |
| 6899 | * |
| 6900 | * @param action the action to run on the UI thread |
| 6901 | */ |
| 6902 | public final void runOnUiThread(Runnable action) { |
| 6903 | if (Thread.currentThread() != mUiThread) { |
| 6904 | mHandler.post(action); |
| 6905 | } else { |
| 6906 | action.run(); |
| 6907 | } |
| 6908 | } |
| 6909 | |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 6910 | /** @hide */ |
| 6911 | @Override |
| 6912 | public final void autofillClientRunOnUiThread(Runnable action) { |
| 6913 | runOnUiThread(action); |
| 6914 | } |
| 6915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6916 | /** |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6917 | * Standard implementation of |
| 6918 | * {@link android.view.LayoutInflater.Factory#onCreateView} used when |
| 6919 | * inflating with the LayoutInflater returned by {@link #getSystemService}. |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6920 | * This implementation does nothing and is for |
| 6921 | * pre-{@link android.os.Build.VERSION_CODES#HONEYCOMB} apps. Newer apps |
| 6922 | * should use {@link #onCreateView(View, String, Context, AttributeSet)}. |
| 6923 | * |
| 6924 | * @see android.view.LayoutInflater#createView |
| 6925 | * @see android.view.Window#getLayoutInflater |
| 6926 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6927 | @Nullable |
Ian Lake | 0c807f4 | 2018-09-12 14:03:27 -0700 | [diff] [blame] | 6928 | public View onCreateView(@NonNull String name, @NonNull Context context, |
| 6929 | @NonNull AttributeSet attrs) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6930 | return null; |
| 6931 | } |
| 6932 | |
| 6933 | /** |
| 6934 | * Standard implementation of |
| 6935 | * {@link android.view.LayoutInflater.Factory2#onCreateView(View, String, Context, AttributeSet)} |
| 6936 | * used when inflating with the LayoutInflater returned by {@link #getSystemService}. |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6937 | * This implementation handles <fragment> tags to embed fragments inside |
| 6938 | * of the activity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6939 | * |
| 6940 | * @see android.view.LayoutInflater#createView |
| 6941 | * @see android.view.Window#getLayoutInflater |
| 6942 | */ |
Ian Lake | 0c807f4 | 2018-09-12 14:03:27 -0700 | [diff] [blame] | 6943 | @Nullable |
| 6944 | public View onCreateView(@Nullable View parent, @NonNull String name, |
| 6945 | @NonNull Context context, @NonNull AttributeSet attrs) { |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6946 | if (!"fragment".equals(name)) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6947 | return onCreateView(name, context, attrs); |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6948 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6949 | |
Adam Powell | 371a809 | 2014-06-20 12:51:12 -0700 | [diff] [blame] | 6950 | return mFragments.onCreateView(parent, name, context, attrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6951 | } |
| 6952 | |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6953 | /** |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6954 | * Print the Activity's state into the given stream. This gets invoked if |
Jeff Sharkey | 5554b70 | 2012-04-11 18:30:51 -0700 | [diff] [blame] | 6955 | * you run "adb shell dumpsys activity <activity_component_name>". |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6956 | * |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 6957 | * @param prefix Desired prefix to prepend at each line of output. |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6958 | * @param fd The raw file descriptor that the dump is being sent to. |
| 6959 | * @param writer The PrintWriter to which you should dump your state. This will be |
| 6960 | * closed for you after you return. |
| 6961 | * @param args additional arguments to the dump request. |
| 6962 | */ |
Ian Lake | 140fe12 | 2018-09-13 14:59:38 -0700 | [diff] [blame] | 6963 | public void dump(@NonNull String prefix, @Nullable FileDescriptor fd, |
| 6964 | @NonNull PrintWriter writer, @Nullable String[] args) { |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 6965 | dumpInner(prefix, fd, writer, args); |
| 6966 | } |
| 6967 | |
Ian Lake | 140fe12 | 2018-09-13 14:59:38 -0700 | [diff] [blame] | 6968 | void dumpInner(@NonNull String prefix, @Nullable FileDescriptor fd, |
| 6969 | @NonNull PrintWriter writer, @Nullable String[] args) { |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 6970 | if (args != null && args.length > 0) { |
| 6971 | // Handle special cases |
| 6972 | switch (args[0]) { |
| 6973 | case "--autofill": |
| 6974 | dumpAutofillManager(prefix, writer); |
| 6975 | return; |
Felipe Leme | b718e03 | 2018-12-10 09:44:23 -0800 | [diff] [blame] | 6976 | case "--contentcapture": |
| 6977 | dumpContentCaptureManager(prefix, writer); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 6978 | return; |
| 6979 | } |
Felipe Leme | b546ca7 | 2018-08-15 08:44:12 -0700 | [diff] [blame] | 6980 | } |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 6981 | writer.print(prefix); writer.print("Local Activity "); |
| 6982 | writer.print(Integer.toHexString(System.identityHashCode(this))); |
| 6983 | writer.println(" State:"); |
| 6984 | String innerPrefix = prefix + " "; |
| 6985 | writer.print(innerPrefix); writer.print("mResumed="); |
| 6986 | writer.print(mResumed); writer.print(" mStopped="); |
| 6987 | writer.print(mStopped); writer.print(" mFinished="); |
| 6988 | writer.println(mFinished); |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 6989 | writer.print(innerPrefix); writer.print("mChangingConfigurations="); |
| 6990 | writer.println(mChangingConfigurations); |
| 6991 | writer.print(innerPrefix); writer.print("mCurrentConfig="); |
| 6992 | writer.println(mCurrentConfig); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6993 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 6994 | mFragments.dumpLoaders(innerPrefix, fd, writer, args); |
| 6995 | mFragments.getFragmentManager().dump(innerPrefix, fd, writer, args); |
Dianne Hackborn | 57dd737 | 2015-07-27 18:11:14 -0700 | [diff] [blame] | 6996 | if (mVoiceInteractor != null) { |
| 6997 | mVoiceInteractor.dump(innerPrefix, fd, writer, args); |
| 6998 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6999 | |
Michael Wright | 5f48dc7 | 2013-11-01 12:42:49 -0700 | [diff] [blame] | 7000 | if (getWindow() != null && |
| 7001 | getWindow().peekDecorView() != null && |
| 7002 | getWindow().peekDecorView().getViewRootImpl() != null) { |
| 7003 | getWindow().peekDecorView().getViewRootImpl().dump(prefix, fd, writer, args); |
| 7004 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 7005 | |
| 7006 | mHandler.getLooper().dump(new PrintWriterPrinter(writer), prefix); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 7007 | |
Felipe Leme | b546ca7 | 2018-08-15 08:44:12 -0700 | [diff] [blame] | 7008 | dumpAutofillManager(prefix, writer); |
Felipe Leme | b718e03 | 2018-12-10 09:44:23 -0800 | [diff] [blame] | 7009 | dumpContentCaptureManager(prefix, writer); |
Felipe Leme | b546ca7 | 2018-08-15 08:44:12 -0700 | [diff] [blame] | 7010 | |
| 7011 | ResourcesManager.getInstance().dump(prefix, writer); |
| 7012 | } |
| 7013 | |
| 7014 | void dumpAutofillManager(String prefix, PrintWriter writer) { |
Felipe Leme | 9d16dff | 2018-01-29 18:12:43 -0800 | [diff] [blame] | 7015 | final AutofillManager afm = getAutofillManager(); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 7016 | if (afm != null) { |
Felipe Leme | b546ca7 | 2018-08-15 08:44:12 -0700 | [diff] [blame] | 7017 | afm.dump(prefix, writer); |
Svet Ganov | 47b37aa | 2018-02-16 00:11:39 -0800 | [diff] [blame] | 7018 | writer.print(prefix); writer.print("Autofill Compat Mode: "); |
| 7019 | writer.println(isAutofillCompatibilityEnabled()); |
Felipe Leme | 686128e | 2017-10-17 14:02:20 -0700 | [diff] [blame] | 7020 | } else { |
| 7021 | writer.print(prefix); writer.println("No AutofillManager"); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 7022 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 7023 | } |
| 7024 | |
Felipe Leme | b718e03 | 2018-12-10 09:44:23 -0800 | [diff] [blame] | 7025 | void dumpContentCaptureManager(String prefix, PrintWriter writer) { |
| 7026 | final ContentCaptureManager cm = getContentCaptureManager(); |
| 7027 | if (cm != null) { |
| 7028 | cm.dump(prefix, writer); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 7029 | } else { |
Felipe Leme | b718e03 | 2018-12-10 09:44:23 -0800 | [diff] [blame] | 7030 | writer.print(prefix); writer.println("No ContentCaptureManager"); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 7031 | } |
| 7032 | } |
| 7033 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 7034 | /** |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 7035 | * Bit indicating that this activity is "immersive" and should not be |
| 7036 | * interrupted by notifications if possible. |
| 7037 | * |
| 7038 | * This value is initially set by the manifest property |
| 7039 | * <code>android:immersive</code> but may be changed at runtime by |
| 7040 | * {@link #setImmersive}. |
| 7041 | * |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 7042 | * @see #setImmersive(boolean) |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 7043 | * @see android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 7044 | */ |
| 7045 | public boolean isImmersive() { |
| 7046 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7047 | return ActivityTaskManager.getService().isImmersive(mToken); |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 7048 | } catch (RemoteException e) { |
| 7049 | return false; |
| 7050 | } |
| 7051 | } |
| 7052 | |
| 7053 | /** |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 7054 | * Indication of whether this is the highest level activity in this task. Can be used to |
| 7055 | * determine whether an activity launched by this activity was placed in the same task or |
| 7056 | * another task. |
| 7057 | * |
| 7058 | * @return true if this is the topmost, non-finishing activity in its task. |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 7059 | */ |
Sunny Goyal | d85bed5 | 2018-09-25 12:01:01 -0700 | [diff] [blame] | 7060 | final boolean isTopOfTask() { |
George Mount | f43ea5d | 2016-05-26 09:52:53 -0700 | [diff] [blame] | 7061 | if (mToken == null || mWindow == null) { |
George Mount | d0ca0e0 | 2016-03-29 10:32:56 -0700 | [diff] [blame] | 7062 | return false; |
| 7063 | } |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 7064 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7065 | return ActivityTaskManager.getService().isTopOfTask(getActivityToken()); |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 7066 | } catch (RemoteException e) { |
| 7067 | return false; |
| 7068 | } |
| 7069 | } |
| 7070 | |
| 7071 | /** |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 7072 | * Convert a translucent themed Activity {@link android.R.attr#windowIsTranslucent} to a |
| 7073 | * fullscreen opaque Activity. |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7074 | * <p> |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 7075 | * Call this whenever the background of a translucent Activity has changed to become opaque. |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7076 | * Doing so will allow the {@link android.view.Surface} of the Activity behind to be released. |
| 7077 | * <p> |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 7078 | * This call has no effect on non-translucent activities or on activities with the |
| 7079 | * {@link android.R.attr#windowIsFloating} attribute. |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7080 | * |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 7081 | * @see #convertToTranslucent(android.app.Activity.TranslucentConversionListener, |
| 7082 | * ActivityOptions) |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7083 | * @see TranslucentConversionListener |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 7084 | * |
| 7085 | * @hide |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 7086 | */ |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7087 | @SystemApi |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7088 | public void convertFromTranslucent() { |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 7089 | try { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7090 | mTranslucentCallback = null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7091 | if (ActivityTaskManager.getService().convertFromTranslucent(mToken)) { |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 7092 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, true); |
| 7093 | } |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 7094 | } catch (RemoteException e) { |
| 7095 | // pass |
| 7096 | } |
| 7097 | } |
| 7098 | |
| 7099 | /** |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7100 | * Convert a translucent themed Activity {@link android.R.attr#windowIsTranslucent} back from |
| 7101 | * opaque to translucent following a call to {@link #convertFromTranslucent()}. |
| 7102 | * <p> |
| 7103 | * Calling this allows the Activity behind this one to be seen again. Once all such Activities |
| 7104 | * have been redrawn {@link TranslucentConversionListener#onTranslucentConversionComplete} will |
| 7105 | * be called indicating that it is safe to make this activity translucent again. Until |
| 7106 | * {@link TranslucentConversionListener#onTranslucentConversionComplete} is called the image |
| 7107 | * behind the frontmost Activity will be indeterminate. |
| 7108 | * <p> |
| 7109 | * This call has no effect on non-translucent activities or on activities with the |
| 7110 | * {@link android.R.attr#windowIsFloating} attribute. |
| 7111 | * |
| 7112 | * @param callback the method to call when all visible Activities behind this one have been |
| 7113 | * drawn and it is safe to make this Activity translucent again. |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7114 | * @param options activity options delivered to the activity below this one. The options |
| 7115 | * are retrieved using {@link #getActivityOptions}. |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 7116 | * @return <code>true</code> if Window was opaque and will become translucent or |
| 7117 | * <code>false</code> if window was translucent and no change needed to be made. |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7118 | * |
| 7119 | * @see #convertFromTranslucent() |
| 7120 | * @see TranslucentConversionListener |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 7121 | * |
| 7122 | * @hide |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7123 | */ |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7124 | @SystemApi |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 7125 | public boolean convertToTranslucent(TranslucentConversionListener callback, |
Jose Lima | 5517ea7 | 2014-06-10 12:31:43 -0700 | [diff] [blame] | 7126 | ActivityOptions options) { |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7127 | boolean drawComplete; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7128 | try { |
| 7129 | mTranslucentCallback = callback; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7130 | mChangeCanvasToTranslucent = ActivityTaskManager.getService().convertToTranslucent( |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 7131 | mToken, options == null ? null : options.toBundle()); |
George Mount | 9e18397 | 2014-09-03 12:35:09 -0700 | [diff] [blame] | 7132 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, false); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7133 | drawComplete = true; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7134 | } catch (RemoteException e) { |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7135 | // Make callback return as though it timed out. |
| 7136 | mChangeCanvasToTranslucent = false; |
| 7137 | drawComplete = false; |
| 7138 | } |
| 7139 | if (!mChangeCanvasToTranslucent && mTranslucentCallback != null) { |
| 7140 | // Window is already translucent. |
| 7141 | mTranslucentCallback.onTranslucentConversionComplete(drawComplete); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7142 | } |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 7143 | return mChangeCanvasToTranslucent; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7144 | } |
| 7145 | |
| 7146 | /** @hide */ |
| 7147 | void onTranslucentConversionComplete(boolean drawComplete) { |
| 7148 | if (mTranslucentCallback != null) { |
| 7149 | mTranslucentCallback.onTranslucentConversionComplete(drawComplete); |
| 7150 | mTranslucentCallback = null; |
| 7151 | } |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 7152 | if (mChangeCanvasToTranslucent) { |
| 7153 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, false); |
| 7154 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7155 | } |
| 7156 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 7157 | /** @hide */ |
| 7158 | public void onNewActivityOptions(ActivityOptions options) { |
| 7159 | mActivityTransitionState.setEnterActivityOptions(this, options); |
| 7160 | if (!mStopped) { |
| 7161 | mActivityTransitionState.enterReady(this); |
| 7162 | } |
| 7163 | } |
| 7164 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7165 | /** |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7166 | * Retrieve the ActivityOptions passed in from the launching activity or passed back |
| 7167 | * from an activity launched by this activity in its call to {@link |
| 7168 | * #convertToTranslucent(TranslucentConversionListener, ActivityOptions)} |
| 7169 | * |
| 7170 | * @return The ActivityOptions passed to {@link #convertToTranslucent}. |
| 7171 | * @hide |
| 7172 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7173 | @UnsupportedAppUsage |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7174 | ActivityOptions getActivityOptions() { |
| 7175 | try { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 7176 | return ActivityOptions.fromBundle( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7177 | ActivityTaskManager.getService().getActivityOptions(mToken)); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7178 | } catch (RemoteException e) { |
| 7179 | } |
| 7180 | return null; |
| 7181 | } |
| 7182 | |
| 7183 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7184 | * Activities that want to remain visible behind a translucent activity above them must call |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 7185 | * this method anytime between the start of {@link #onResume()} and the return from |
| 7186 | * {@link #onPause()}. If this call is successful then the activity will remain visible after |
| 7187 | * {@link #onPause()} is called, and is allowed to continue playing media in the background. |
| 7188 | * |
| 7189 | * <p>The actions of this call are reset each time that this activity is brought to the |
| 7190 | * front. That is, every time {@link #onResume()} is called the activity will be assumed |
| 7191 | * to not have requested visible behind. Therefore, if you want this activity to continue to |
| 7192 | * be visible in the background you must call this method again. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7193 | * |
| 7194 | * <p>Only fullscreen opaque activities may make this call. I.e. this call is a nop |
| 7195 | * for dialog and translucent activities. |
| 7196 | * |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 7197 | * <p>Under all circumstances, the activity must stop playing and release resources prior to or |
| 7198 | * within a call to {@link #onVisibleBehindCanceled()} or if this call returns false. |
| 7199 | * |
| 7200 | * <p>False will be returned any time this method is called between the return of onPause and |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7201 | * the next call to onResume. |
| 7202 | * |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7203 | * @deprecated This method's functionality is no longer supported as of |
| 7204 | * {@link android.os.Build.VERSION_CODES#O} and will be removed in a future release. |
| 7205 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7206 | * @param visible true to notify the system that the activity wishes to be visible behind other |
| 7207 | * translucent activities, false to indicate otherwise. Resources must be |
| 7208 | * released when passing false to this method. |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7209 | * |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 7210 | * @return the resulting visibiity state. If true the activity will remain visible beyond |
| 7211 | * {@link #onPause()} if the next activity is translucent or not fullscreen. If false |
| 7212 | * then the activity may not count on being visible behind other translucent activities, |
| 7213 | * and must stop any media playback and release resources. |
| 7214 | * Returning false may occur in lieu of a call to {@link #onVisibleBehindCanceled()} so |
| 7215 | * the return value must be checked. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7216 | * |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 7217 | * @see #onVisibleBehindCanceled() |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7218 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7219 | @Deprecated |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7220 | public boolean requestVisibleBehind(boolean visible) { |
Robert Carr | 8661c5e | 2017-06-27 13:46:14 -0700 | [diff] [blame] | 7221 | return false; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7222 | } |
| 7223 | |
| 7224 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7225 | * Called when a translucent activity over this activity is becoming opaque or another |
| 7226 | * activity is being launched. Activities that override this method must call |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 7227 | * <code>super.onVisibleBehindCanceled()</code> or a SuperNotCalledException will be thrown. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7228 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7229 | * <p>When this method is called the activity has 500 msec to release any resources it may be |
| 7230 | * using while visible in the background. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7231 | * If the activity has not returned from this method in 500 msec the system will destroy |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7232 | * the activity and kill the process in order to recover the resources for another |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7233 | * process. Otherwise {@link #onStop()} will be called following return. |
| 7234 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7235 | * @see #requestVisibleBehind(boolean) |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7236 | * |
| 7237 | * @deprecated This method's functionality is no longer supported as of |
| 7238 | * {@link android.os.Build.VERSION_CODES#O} and will be removed in a future release. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7239 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7240 | @Deprecated |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 7241 | @CallSuper |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 7242 | public void onVisibleBehindCanceled() { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7243 | mCalled = true; |
| 7244 | } |
| 7245 | |
| 7246 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7247 | * Translucent activities may call this to determine if there is an activity below them that |
| 7248 | * is currently set to be visible in the background. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7249 | * |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7250 | * @deprecated This method's functionality is no longer supported as of |
| 7251 | * {@link android.os.Build.VERSION_CODES#O} and will be removed in a future release. |
| 7252 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7253 | * @return true if an activity below is set to visible according to the most recent call to |
| 7254 | * {@link #requestVisibleBehind(boolean)}, false otherwise. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7255 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7256 | * @see #requestVisibleBehind(boolean) |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 7257 | * @see #onVisibleBehindCanceled() |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7258 | * @see #onBackgroundVisibleBehindChanged(boolean) |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7259 | * @hide |
| 7260 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7261 | @Deprecated |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7262 | @SystemApi |
| 7263 | public boolean isBackgroundVisibleBehind() { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7264 | return false; |
| 7265 | } |
| 7266 | |
| 7267 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7268 | * The topmost foreground activity will receive this call when the background visibility state |
| 7269 | * of the activity below it changes. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7270 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7271 | * This call may be a consequence of {@link #requestVisibleBehind(boolean)} or might be |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7272 | * due to a background activity finishing itself. |
| 7273 | * |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7274 | * @deprecated This method's functionality is no longer supported as of |
| 7275 | * {@link android.os.Build.VERSION_CODES#O} and will be removed in a future release. |
| 7276 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7277 | * @param visible true if a background activity is visible, false otherwise. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7278 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7279 | * @see #requestVisibleBehind(boolean) |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 7280 | * @see #onVisibleBehindCanceled() |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7281 | * @hide |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7282 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7283 | @Deprecated |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7284 | @SystemApi |
| 7285 | public void onBackgroundVisibleBehindChanged(boolean visible) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7286 | } |
| 7287 | |
| 7288 | /** |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 7289 | * Activities cannot draw during the period that their windows are animating in. In order |
| 7290 | * to know when it is safe to begin drawing they can override this method which will be |
| 7291 | * called when the entering animation has completed. |
| 7292 | */ |
| 7293 | public void onEnterAnimationComplete() { |
| 7294 | } |
| 7295 | |
| 7296 | /** |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 7297 | * @hide |
| 7298 | */ |
| 7299 | public void dispatchEnterAnimationComplete() { |
chaviw | feb2e1e | 2018-12-19 17:24:11 -0800 | [diff] [blame] | 7300 | mEnterAnimationComplete = true; |
| 7301 | mInstrumentation.onEnterAnimationComplete(); |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 7302 | onEnterAnimationComplete(); |
| 7303 | if (getWindow() != null && getWindow().getDecorView() != null) { |
Felipe Leme | 0129769 | 2019-01-29 18:16:23 -0800 | [diff] [blame] | 7304 | View decorView = getWindow().getDecorView(); |
| 7305 | decorView.getViewTreeObserver().dispatchOnEnterAnimationComplete(); |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 7306 | } |
| 7307 | } |
| 7308 | |
| 7309 | /** |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 7310 | * Adjust the current immersive mode setting. |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 7311 | * |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 7312 | * Note that changing this value will have no effect on the activity's |
| 7313 | * {@link android.content.pm.ActivityInfo} structure; that is, if |
| 7314 | * <code>android:immersive</code> is set to <code>true</code> |
| 7315 | * in the application's manifest entry for this activity, the {@link |
| 7316 | * android.content.pm.ActivityInfo#flags ActivityInfo.flags} member will |
| 7317 | * always have its {@link android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 7318 | * FLAG_IMMERSIVE} bit set. |
| 7319 | * |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 7320 | * @see #isImmersive() |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 7321 | * @see android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 7322 | */ |
| 7323 | public void setImmersive(boolean i) { |
| 7324 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7325 | ActivityTaskManager.getService().setImmersive(mToken, i); |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 7326 | } catch (RemoteException e) { |
| 7327 | // pass |
| 7328 | } |
| 7329 | } |
| 7330 | |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 7331 | /** |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 7332 | * Enable or disable virtual reality (VR) mode for this Activity. |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 7333 | * |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 7334 | * <p>VR mode is a hint to Android system to switch to a mode optimized for VR applications |
| 7335 | * while this Activity has user focus.</p> |
| 7336 | * |
| 7337 | * <p>It is recommended that applications additionally declare |
| 7338 | * {@link android.R.attr#enableVrMode} in their manifest to allow for smooth activity |
| 7339 | * transitions when switching between VR activities.</p> |
| 7340 | * |
| 7341 | * <p>If the requested {@link android.service.vr.VrListenerService} component is not available, |
| 7342 | * VR mode will not be started. Developers can handle this case as follows:</p> |
| 7343 | * |
| 7344 | * <pre> |
| 7345 | * String servicePackage = "com.whatever.app"; |
| 7346 | * String serviceClass = "com.whatever.app.MyVrListenerService"; |
| 7347 | * |
| 7348 | * // Name of the component of the VrListenerService to start. |
| 7349 | * ComponentName serviceComponent = new ComponentName(servicePackage, serviceClass); |
| 7350 | * |
| 7351 | * try { |
| 7352 | * setVrModeEnabled(true, myComponentName); |
| 7353 | * } catch (PackageManager.NameNotFoundException e) { |
| 7354 | * List<ApplicationInfo> installed = getPackageManager().getInstalledApplications(0); |
| 7355 | * boolean isInstalled = false; |
| 7356 | * for (ApplicationInfo app : installed) { |
| 7357 | * if (app.packageName.equals(servicePackage)) { |
| 7358 | * isInstalled = true; |
| 7359 | * break; |
| 7360 | * } |
| 7361 | * } |
| 7362 | * if (isInstalled) { |
| 7363 | * // Package is installed, but not enabled in Settings. Let user enable it. |
| 7364 | * startActivity(new Intent(Settings.ACTION_VR_LISTENER_SETTINGS)); |
| 7365 | * } else { |
| 7366 | * // Package is not installed. Send an intent to download this. |
| 7367 | * sentIntentToLaunchAppStore(servicePackage); |
| 7368 | * } |
| 7369 | * } |
| 7370 | * </pre> |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 7371 | * |
| 7372 | * @param enabled {@code true} to enable this mode. |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 7373 | * @param requestedComponent the name of the component to use as a |
| 7374 | * {@link android.service.vr.VrListenerService} while VR mode is enabled. |
| 7375 | * |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 7376 | * @throws android.content.pm.PackageManager.NameNotFoundException if the given component |
| 7377 | * to run as a {@link android.service.vr.VrListenerService} is not installed, or has |
| 7378 | * not been enabled in user settings. |
| 7379 | * |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 7380 | * @see android.content.pm.PackageManager#FEATURE_VR_MODE_HIGH_PERFORMANCE |
| 7381 | * @see android.service.vr.VrListenerService |
| 7382 | * @see android.provider.Settings#ACTION_VR_LISTENER_SETTINGS |
| 7383 | * @see android.R.attr#enableVrMode |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 7384 | */ |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 7385 | public void setVrModeEnabled(boolean enabled, @NonNull ComponentName requestedComponent) |
| 7386 | throws PackageManager.NameNotFoundException { |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 7387 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7388 | if (ActivityTaskManager.getService().setVrMode(mToken, enabled, requestedComponent) |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 7389 | != 0) { |
| 7390 | throw new PackageManager.NameNotFoundException( |
| 7391 | requestedComponent.flattenToString()); |
| 7392 | } |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 7393 | } catch (RemoteException e) { |
| 7394 | // pass |
| 7395 | } |
| 7396 | } |
| 7397 | |
| 7398 | /** |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 7399 | * Start an action mode of the default type {@link ActionMode#TYPE_PRIMARY}. |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 7400 | * |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 7401 | * @param callback Callback that will manage lifecycle events for this action mode |
| 7402 | * @return The ActionMode that was started, or null if it was canceled |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 7403 | * |
| 7404 | * @see ActionMode |
| 7405 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 7406 | @Nullable |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 7407 | public ActionMode startActionMode(ActionMode.Callback callback) { |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 7408 | return mWindow.getDecorView().startActionMode(callback); |
| 7409 | } |
| 7410 | |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 7411 | /** |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 7412 | * Start an action mode of the given type. |
| 7413 | * |
| 7414 | * @param callback Callback that will manage lifecycle events for this action mode |
| 7415 | * @param type One of {@link ActionMode#TYPE_PRIMARY} or {@link ActionMode#TYPE_FLOATING}. |
| 7416 | * @return The ActionMode that was started, or null if it was canceled |
| 7417 | * |
| 7418 | * @see ActionMode |
| 7419 | */ |
| 7420 | @Nullable |
| 7421 | public ActionMode startActionMode(ActionMode.Callback callback, int type) { |
| 7422 | return mWindow.getDecorView().startActionMode(callback, type); |
| 7423 | } |
| 7424 | |
| 7425 | /** |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 7426 | * Give the Activity a chance to control the UI for an action mode requested |
| 7427 | * by the system. |
| 7428 | * |
| 7429 | * <p>Note: If you are looking for a notification callback that an action mode |
| 7430 | * has been started for this activity, see {@link #onActionModeStarted(ActionMode)}.</p> |
| 7431 | * |
| 7432 | * @param callback The callback that should control the new action mode |
| 7433 | * @return The new action mode, or <code>null</code> if the activity does not want to |
| 7434 | * provide special handling for this action mode. (It will be handled by the system.) |
| 7435 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 7436 | @Nullable |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7437 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 7438 | public ActionMode onWindowStartingActionMode(ActionMode.Callback callback) { |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 7439 | // Only Primary ActionModes are represented in the ActionBar. |
| 7440 | if (mActionModeTypeStarting == ActionMode.TYPE_PRIMARY) { |
| 7441 | initWindowDecorActionBar(); |
| 7442 | if (mActionBar != null) { |
| 7443 | return mActionBar.startActionMode(callback); |
| 7444 | } |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 7445 | } |
| 7446 | return null; |
| 7447 | } |
| 7448 | |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 7449 | /** |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 7450 | * {@inheritDoc} |
| 7451 | */ |
| 7452 | @Nullable |
| 7453 | @Override |
| 7454 | public ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int type) { |
| 7455 | try { |
| 7456 | mActionModeTypeStarting = type; |
| 7457 | return onWindowStartingActionMode(callback); |
| 7458 | } finally { |
| 7459 | mActionModeTypeStarting = ActionMode.TYPE_PRIMARY; |
| 7460 | } |
| 7461 | } |
| 7462 | |
| 7463 | /** |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 7464 | * Notifies the Activity that an action mode has been started. |
| 7465 | * Activity subclasses overriding this method should call the superclass implementation. |
| 7466 | * |
| 7467 | * @param mode The new action mode. |
| 7468 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 7469 | @CallSuper |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7470 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 7471 | public void onActionModeStarted(ActionMode mode) { |
| 7472 | } |
| 7473 | |
| 7474 | /** |
| 7475 | * Notifies the activity that an action mode has finished. |
| 7476 | * Activity subclasses overriding this method should call the superclass implementation. |
| 7477 | * |
| 7478 | * @param mode The action mode that just finished. |
| 7479 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 7480 | @CallSuper |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7481 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 7482 | public void onActionModeFinished(ActionMode mode) { |
| 7483 | } |
| 7484 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7485 | /** |
| 7486 | * Returns true if the app should recreate the task when navigating 'up' from this activity |
| 7487 | * by using targetIntent. |
| 7488 | * |
| 7489 | * <p>If this method returns false the app can trivially call |
| 7490 | * {@link #navigateUpTo(Intent)} using the same parameters to correctly perform |
| 7491 | * up navigation. If this method returns false, the app should synthesize a new task stack |
| 7492 | * by using {@link TaskStackBuilder} or another similar mechanism to perform up navigation.</p> |
| 7493 | * |
| 7494 | * @param targetIntent An intent representing the target destination for up navigation |
| 7495 | * @return true if navigating up should recreate a new task stack, false if the same task |
| 7496 | * should be used for the destination |
| 7497 | */ |
| 7498 | public boolean shouldUpRecreateTask(Intent targetIntent) { |
| 7499 | try { |
| 7500 | PackageManager pm = getPackageManager(); |
| 7501 | ComponentName cn = targetIntent.getComponent(); |
| 7502 | if (cn == null) { |
| 7503 | cn = targetIntent.resolveActivity(pm); |
| 7504 | } |
| 7505 | ActivityInfo info = pm.getActivityInfo(cn, 0); |
| 7506 | if (info.taskAffinity == null) { |
| 7507 | return false; |
| 7508 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7509 | return ActivityTaskManager.getService().shouldUpRecreateTask(mToken, info.taskAffinity); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7510 | } catch (RemoteException e) { |
| 7511 | return false; |
| 7512 | } catch (NameNotFoundException e) { |
| 7513 | return false; |
| 7514 | } |
| 7515 | } |
| 7516 | |
| 7517 | /** |
| 7518 | * Navigate from this activity to the activity specified by upIntent, finishing this activity |
| 7519 | * in the process. If the activity indicated by upIntent already exists in the task's history, |
| 7520 | * this activity and all others before the indicated activity in the history stack will be |
Adam Powell | 35c064b | 2012-05-02 11:37:15 -0700 | [diff] [blame] | 7521 | * finished. |
| 7522 | * |
| 7523 | * <p>If the indicated activity does not appear in the history stack, this will finish |
| 7524 | * each activity in this task until the root activity of the task is reached, resulting in |
| 7525 | * an "in-app home" behavior. This can be useful in apps with a complex navigation hierarchy |
| 7526 | * when an activity may be reached by a path not passing through a canonical parent |
| 7527 | * activity.</p> |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7528 | * |
| 7529 | * <p>This method should be used when performing up navigation from within the same task |
| 7530 | * as the destination. If up navigation should cross tasks in some cases, see |
| 7531 | * {@link #shouldUpRecreateTask(Intent)}.</p> |
| 7532 | * |
| 7533 | * @param upIntent An intent representing the target destination for up navigation |
| 7534 | * |
| 7535 | * @return true if up navigation successfully reached the activity indicated by upIntent and |
| 7536 | * upIntent was delivered to it. false if an instance of the indicated activity could |
| 7537 | * not be found and this activity was simply finished normally. |
| 7538 | */ |
| 7539 | public boolean navigateUpTo(Intent upIntent) { |
| 7540 | if (mParent == null) { |
| 7541 | ComponentName destInfo = upIntent.getComponent(); |
| 7542 | if (destInfo == null) { |
| 7543 | destInfo = upIntent.resolveActivity(getPackageManager()); |
| 7544 | if (destInfo == null) { |
| 7545 | return false; |
| 7546 | } |
| 7547 | upIntent = new Intent(upIntent); |
| 7548 | upIntent.setComponent(destInfo); |
| 7549 | } |
| 7550 | int resultCode; |
| 7551 | Intent resultData; |
| 7552 | synchronized (this) { |
| 7553 | resultCode = mResultCode; |
| 7554 | resultData = mResultData; |
| 7555 | } |
| 7556 | if (resultData != null) { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 7557 | resultData.prepareToLeaveProcess(this); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7558 | } |
| 7559 | try { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 7560 | upIntent.prepareToLeaveProcess(this); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7561 | return ActivityTaskManager.getService().navigateUpTo(mToken, upIntent, |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7562 | resultCode, resultData); |
| 7563 | } catch (RemoteException e) { |
| 7564 | return false; |
| 7565 | } |
| 7566 | } else { |
| 7567 | return mParent.navigateUpToFromChild(this, upIntent); |
| 7568 | } |
| 7569 | } |
| 7570 | |
| 7571 | /** |
| 7572 | * This is called when a child activity of this one calls its |
| 7573 | * {@link #navigateUpTo} method. The default implementation simply calls |
| 7574 | * navigateUpTo(upIntent) on this activity (the parent). |
| 7575 | * |
| 7576 | * @param child The activity making the call. |
| 7577 | * @param upIntent An intent representing the target destination for up navigation |
| 7578 | * |
| 7579 | * @return true if up navigation successfully reached the activity indicated by upIntent and |
| 7580 | * upIntent was delivered to it. false if an instance of the indicated activity could |
| 7581 | * not be found and this activity was simply finished normally. |
| 7582 | */ |
| 7583 | public boolean navigateUpToFromChild(Activity child, Intent upIntent) { |
| 7584 | return navigateUpTo(upIntent); |
| 7585 | } |
| 7586 | |
| 7587 | /** |
| 7588 | * Obtain an {@link Intent} that will launch an explicit target activity specified by |
| 7589 | * this activity's logical parent. The logical parent is named in the application's manifest |
| 7590 | * by the {@link android.R.attr#parentActivityName parentActivityName} attribute. |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 7591 | * Activity subclasses may override this method to modify the Intent returned by |
| 7592 | * super.getParentActivityIntent() or to implement a different mechanism of retrieving |
| 7593 | * the parent intent entirely. |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7594 | * |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 7595 | * @return a new Intent targeting the defined parent of this activity or null if |
| 7596 | * there is no valid parent. |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7597 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 7598 | @Nullable |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7599 | public Intent getParentActivityIntent() { |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 7600 | final String parentName = mActivityInfo.parentActivityName; |
| 7601 | if (TextUtils.isEmpty(parentName)) { |
| 7602 | return null; |
| 7603 | } |
Adam Powell | 5a4010c | 2012-09-16 15:14:05 -0700 | [diff] [blame] | 7604 | |
| 7605 | // If the parent itself has no parent, generate a main activity intent. |
| 7606 | final ComponentName target = new ComponentName(this, parentName); |
| 7607 | try { |
| 7608 | final ActivityInfo parentInfo = getPackageManager().getActivityInfo(target, 0); |
| 7609 | final String parentActivity = parentInfo.parentActivityName; |
| 7610 | final Intent parentIntent = parentActivity == null |
| 7611 | ? Intent.makeMainActivity(target) |
| 7612 | : new Intent().setComponent(target); |
| 7613 | return parentIntent; |
| 7614 | } catch (NameNotFoundException e) { |
| 7615 | Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName + |
| 7616 | "' in manifest"); |
| 7617 | return null; |
| 7618 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7619 | } |
| 7620 | |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7621 | /** |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 7622 | * When {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7623 | * android.view.View, String)} was used to start an Activity, <var>callback</var> |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7624 | * will be called to handle shared elements on the <i>launched</i> Activity. This requires |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 7625 | * {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7626 | * |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7627 | * @param callback Used to manipulate shared element transitions on the launched Activity. |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7628 | */ |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7629 | public void setEnterSharedElementCallback(SharedElementCallback callback) { |
| 7630 | if (callback == null) { |
| 7631 | callback = SharedElementCallback.NULL_CALLBACK; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7632 | } |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7633 | mEnterTransitionListener = callback; |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7634 | } |
| 7635 | |
| 7636 | /** |
| 7637 | * When {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7638 | * android.view.View, String)} was used to start an Activity, <var>callback</var> |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7639 | * will be called to handle shared elements on the <i>launching</i> Activity. Most |
| 7640 | * calls will only come when returning from the started Activity. |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 7641 | * This requires {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7642 | * |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7643 | * @param callback Used to manipulate shared element transitions on the launching Activity. |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7644 | */ |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7645 | public void setExitSharedElementCallback(SharedElementCallback callback) { |
| 7646 | if (callback == null) { |
| 7647 | callback = SharedElementCallback.NULL_CALLBACK; |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7648 | } |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7649 | mExitTransitionListener = callback; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7650 | } |
| 7651 | |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 7652 | /** |
| 7653 | * Postpone the entering activity transition when Activity was started with |
| 7654 | * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
| 7655 | * android.util.Pair[])}. |
| 7656 | * <p>This method gives the Activity the ability to delay starting the entering and |
| 7657 | * shared element transitions until all data is loaded. Until then, the Activity won't |
| 7658 | * draw into its window, leaving the window transparent. This may also cause the |
| 7659 | * returning animation to be delayed until data is ready. This method should be |
| 7660 | * called in {@link #onCreate(android.os.Bundle)} or in |
| 7661 | * {@link #onActivityReenter(int, android.content.Intent)}. |
| 7662 | * {@link #startPostponedEnterTransition()} must be called to allow the Activity to |
| 7663 | * start the transitions. If the Activity did not use |
| 7664 | * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
| 7665 | * android.util.Pair[])}, then this method does nothing.</p> |
| 7666 | */ |
| 7667 | public void postponeEnterTransition() { |
| 7668 | mActivityTransitionState.postponeEnterTransition(); |
| 7669 | } |
| 7670 | |
| 7671 | /** |
| 7672 | * Begin postponed transitions after {@link #postponeEnterTransition()} was called. |
| 7673 | * If postponeEnterTransition() was called, you must call startPostponedEnterTransition() |
| 7674 | * to have your Activity start drawing. |
| 7675 | */ |
| 7676 | public void startPostponedEnterTransition() { |
| 7677 | mActivityTransitionState.startPostponedEnterTransition(); |
| 7678 | } |
| 7679 | |
Vladislav Kaznacheev | b23a757 | 2015-12-18 12:23:43 -0800 | [diff] [blame] | 7680 | /** |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 7681 | * Create {@link DragAndDropPermissions} object bound to this activity and controlling the |
| 7682 | * access permissions for content URIs associated with the {@link DragEvent}. |
Vladislav Kaznacheev | b23a757 | 2015-12-18 12:23:43 -0800 | [diff] [blame] | 7683 | * @param event Drag event |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 7684 | * @return The {@link DragAndDropPermissions} object used to control access to the content URIs. |
| 7685 | * Null if no content URIs are associated with the event or if permissions could not be granted. |
Vladislav Kaznacheev | b23a757 | 2015-12-18 12:23:43 -0800 | [diff] [blame] | 7686 | */ |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 7687 | public DragAndDropPermissions requestDragAndDropPermissions(DragEvent event) { |
| 7688 | DragAndDropPermissions dragAndDropPermissions = DragAndDropPermissions.obtain(event); |
| 7689 | if (dragAndDropPermissions != null && dragAndDropPermissions.take(getActivityToken())) { |
| 7690 | return dragAndDropPermissions; |
Vladislav Kaznacheev | b23a757 | 2015-12-18 12:23:43 -0800 | [diff] [blame] | 7691 | } |
| 7692 | return null; |
| 7693 | } |
| 7694 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7695 | // ------------------ Internal API ------------------ |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7696 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 7697 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7698 | final void setParent(Activity parent) { |
| 7699 | mParent = parent; |
| 7700 | } |
| 7701 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7702 | @UnsupportedAppUsage |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 7703 | final void attach(Context context, ActivityThread aThread, |
| 7704 | Instrumentation instr, IBinder token, int ident, |
| 7705 | Application application, Intent intent, ActivityInfo info, |
| 7706 | CharSequence title, Activity parent, String id, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 7707 | NonConfigurationInstances lastNonConfigurationInstances, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 7708 | Configuration config, String referrer, IVoiceInteractor voiceInteractor, |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 7709 | Window window, ActivityConfigCallback activityConfigCallback, IBinder assistToken) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7710 | attachBaseContext(context); |
| 7711 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7712 | mFragments.attachHost(null /*parent*/); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7713 | |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 7714 | mWindow = new PhoneWindow(this, window, activityConfigCallback); |
Skuhne | ce2faa5 | 2015-08-11 10:36:38 -0700 | [diff] [blame] | 7715 | mWindow.setWindowControllerCallback(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7716 | mWindow.setCallback(this); |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 7717 | mWindow.setOnWindowDismissedCallback(this); |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 7718 | mWindow.getLayoutInflater().setPrivateFactory(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7719 | if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) { |
| 7720 | mWindow.setSoftInputMode(info.softInputMode); |
| 7721 | } |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 7722 | if (info.uiOptions != 0) { |
| 7723 | mWindow.setUiOptions(info.uiOptions); |
| 7724 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7725 | mUiThread = Thread.currentThread(); |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7726 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7727 | mMainThread = aThread; |
| 7728 | mInstrumentation = instr; |
| 7729 | mToken = token; |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 7730 | mAssistToken = assistToken; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 7731 | mIdent = ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7732 | mApplication = application; |
| 7733 | mIntent = intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 7734 | mReferrer = referrer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7735 | mComponent = intent.getComponent(); |
| 7736 | mActivityInfo = info; |
| 7737 | mTitle = title; |
| 7738 | mParent = parent; |
| 7739 | mEmbeddedID = id; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 7740 | mLastNonConfigurationInstances = lastNonConfigurationInstances; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 7741 | if (voiceInteractor != null) { |
| 7742 | if (lastNonConfigurationInstances != null) { |
| 7743 | mVoiceInteractor = lastNonConfigurationInstances.voiceInteractor; |
| 7744 | } else { |
| 7745 | mVoiceInteractor = new VoiceInteractor(voiceInteractor, this, this, |
| 7746 | Looper.myLooper()); |
| 7747 | } |
| 7748 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7749 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7750 | mWindow.setWindowManager( |
| 7751 | (WindowManager)context.getSystemService(Context.WINDOW_SERVICE), |
| 7752 | mToken, mComponent.flattenToString(), |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 7753 | (info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7754 | if (mParent != null) { |
| 7755 | mWindow.setContainer(mParent.getWindow()); |
| 7756 | } |
| 7757 | mWindowManager = mWindow.getWindowManager(); |
| 7758 | mCurrentConfig = config; |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 7759 | |
| 7760 | mWindow.setColorMode(info.colorMode); |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7761 | |
Felipe Leme | a4f39cd | 2019-02-19 15:08:59 -0800 | [diff] [blame] | 7762 | setAutofillOptions(application.getAutofillOptions()); |
Felipe Leme | 326f15a | 2019-02-19 09:42:24 -0800 | [diff] [blame] | 7763 | setContentCaptureOptions(application.getContentCaptureOptions()); |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7764 | } |
| 7765 | |
| 7766 | private void enableAutofillCompatibilityIfNeeded() { |
| 7767 | if (isAutofillCompatibilityEnabled()) { |
| 7768 | final AutofillManager afm = getSystemService(AutofillManager.class); |
| 7769 | if (afm != null) { |
| 7770 | afm.enableCompatibilityMode(); |
| 7771 | } |
| 7772 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7773 | } |
| 7774 | |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 7775 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7776 | @UnsupportedAppUsage |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 7777 | public final IBinder getActivityToken() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7778 | return mParent != null ? mParent.getActivityToken() : mToken; |
| 7779 | } |
| 7780 | |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 7781 | /** @hide */ |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 7782 | public final IBinder getAssistToken() { |
| 7783 | return mParent != null ? mParent.getAssistToken() : mAssistToken; |
| 7784 | } |
| 7785 | |
| 7786 | /** @hide */ |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 7787 | @VisibleForTesting |
| 7788 | public final ActivityThread getActivityThread() { |
| 7789 | return mMainThread; |
| 7790 | } |
| 7791 | |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7792 | final void performCreate(Bundle icicle) { |
| 7793 | performCreate(icicle, null); |
| 7794 | } |
| 7795 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7796 | @UnsupportedAppUsage |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7797 | final void performCreate(Bundle icicle, PersistableBundle persistentState) { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7798 | dispatchActivityPreCreated(icicle); |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7799 | mCanEnterPictureInPicture = true; |
| 7800 | restoreHasCurrentPermissionRequest(icicle); |
| 7801 | if (persistentState != null) { |
| 7802 | onCreate(icicle, persistentState); |
| 7803 | } else { |
| 7804 | onCreate(icicle); |
| 7805 | } |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7806 | writeEventLog(LOG_AM_ON_CREATE_CALLED, "performCreate"); |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7807 | mActivityTransitionState.readState(icicle); |
| 7808 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 7809 | mVisibleFromClient = !mWindow.getWindowStyle().getBoolean( |
| 7810 | com.android.internal.R.styleable.Window_windowNoDisplay, false); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 7811 | mFragments.dispatchActivityCreated(); |
Eino-Ville Talvala | 563df3b | 2016-06-06 22:04:54 +0000 | [diff] [blame] | 7812 | mActivityTransitionState.setEnterActivityOptions(this, getActivityOptions()); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7813 | dispatchActivityPostCreated(icicle); |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7814 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7815 | |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 7816 | final void performNewIntent(@NonNull Intent intent) { |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7817 | mCanEnterPictureInPicture = true; |
| 7818 | onNewIntent(intent); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7819 | } |
| 7820 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7821 | final void performStart(String reason) { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7822 | dispatchActivityPreStarted(); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 7823 | mActivityTransitionState.setEnterActivityOptions(this, getActivityOptions()); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 7824 | mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7825 | mCalled = false; |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 7826 | mFragments.execPendingActions(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7827 | mInstrumentation.callActivityOnStart(this); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7828 | writeEventLog(LOG_AM_ON_START_CALLED, reason); |
| 7829 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7830 | if (!mCalled) { |
| 7831 | throw new SuperNotCalledException( |
| 7832 | "Activity " + mComponent.toShortString() + |
| 7833 | " did not call through to super.onStart()"); |
| 7834 | } |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7835 | mFragments.dispatchStart(); |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7836 | mFragments.reportLoaderStart(); |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 7837 | |
Elliott Hughes | e14fa97 | 2019-10-02 11:35:53 -0700 | [diff] [blame] | 7838 | // Warn app developers if the dynamic linker logged anything during startup. |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 7839 | boolean isAppDebuggable = |
| 7840 | (mApplication.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
Elliott Hughes | e14fa97 | 2019-10-02 11:35:53 -0700 | [diff] [blame] | 7841 | if (isAppDebuggable) { |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 7842 | String dlwarning = getDlWarning(); |
| 7843 | if (dlwarning != null) { |
Adam Powell | d93f3b1 | 2016-03-03 08:43:37 -0800 | [diff] [blame] | 7844 | String appName = getApplicationInfo().loadLabel(getPackageManager()) |
| 7845 | .toString(); |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 7846 | String warning = "Detected problems with app native libraries\n" + |
| 7847 | "(please consult log for detail):\n" + dlwarning; |
| 7848 | if (isAppDebuggable) { |
| 7849 | new AlertDialog.Builder(this). |
| 7850 | setTitle(appName). |
| 7851 | setMessage(warning). |
| 7852 | setPositiveButton(android.R.string.ok, null). |
| 7853 | setCancelable(false). |
| 7854 | show(); |
| 7855 | } else { |
| 7856 | Toast.makeText(this, appName + "\n" + warning, Toast.LENGTH_LONG).show(); |
| 7857 | } |
| 7858 | } |
| 7859 | } |
| 7860 | |
Tim Van Patten | ddc4391 | 2018-12-18 17:47:52 -0700 | [diff] [blame] | 7861 | GraphicsEnvironment.getInstance().showAngleInUseDialogBox(this); |
| 7862 | |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 7863 | mActivityTransitionState.enterReady(this); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7864 | dispatchActivityPostStarted(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7865 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7866 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 7867 | /** |
| 7868 | * Restart the activity. |
| 7869 | * @param start Indicates whether the activity should also be started after restart. |
| 7870 | * The option to not start immediately is needed in case a transaction with |
| 7871 | * multiple lifecycle transitions is in progress. |
| 7872 | */ |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7873 | final void performRestart(boolean start, String reason) { |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 7874 | mCanEnterPictureInPicture = true; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 7875 | mFragments.noteStateNotSaved(); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 7876 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 7877 | if (mToken != null && mParent == null) { |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 7878 | // No need to check mStopped, the roots will check if they were actually stopped. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 7879 | WindowManagerGlobal.getInstance().setStoppedState(mToken, false /* stopped */); |
| 7880 | } |
| 7881 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7882 | if (mStopped) { |
| 7883 | mStopped = false; |
Dianne Hackborn | 185e3e2 | 2011-06-03 15:26:01 -0700 | [diff] [blame] | 7884 | |
| 7885 | synchronized (mManagedCursors) { |
| 7886 | final int N = mManagedCursors.size(); |
| 7887 | for (int i=0; i<N; i++) { |
| 7888 | ManagedCursor mc = mManagedCursors.get(i); |
| 7889 | if (mc.mReleased || mc.mUpdated) { |
| 7890 | if (!mc.mCursor.requery()) { |
Dianne Hackborn | a5445d3 | 2011-09-01 14:38:24 -0700 | [diff] [blame] | 7891 | if (getApplicationInfo().targetSdkVersion |
| 7892 | >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
| 7893 | throw new IllegalStateException( |
| 7894 | "trying to requery an already closed cursor " |
| 7895 | + mc.mCursor); |
| 7896 | } |
Dianne Hackborn | 185e3e2 | 2011-06-03 15:26:01 -0700 | [diff] [blame] | 7897 | } |
| 7898 | mc.mReleased = false; |
| 7899 | mc.mUpdated = false; |
| 7900 | } |
| 7901 | } |
| 7902 | } |
| 7903 | |
| 7904 | mCalled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7905 | mInstrumentation.callActivityOnRestart(this); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7906 | writeEventLog(LOG_AM_ON_RESTART_CALLED, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7907 | if (!mCalled) { |
| 7908 | throw new SuperNotCalledException( |
| 7909 | "Activity " + mComponent.toShortString() + |
| 7910 | " did not call through to super.onRestart()"); |
| 7911 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 7912 | if (start) { |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7913 | performStart(reason); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 7914 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7915 | } |
| 7916 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7917 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7918 | final void performResume(boolean followedByPause, String reason) { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7919 | dispatchActivityPreResumed(); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7920 | performRestart(true /* start */, reason); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7921 | |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 7922 | mFragments.execPendingActions(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7923 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 7924 | mLastNonConfigurationInstances = null; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7925 | |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 7926 | if (mAutoFillResetNeeded) { |
| 7927 | // When Activity is destroyed in paused state, and relaunch activity, there will be |
| 7928 | // extra onResume and onPause event, ignore the first onResume and onPause. |
| 7929 | // see ActivityThread.handleRelaunchActivity() |
| 7930 | mAutoFillIgnoreFirstResumePause = followedByPause; |
| 7931 | if (mAutoFillIgnoreFirstResumePause && DEBUG_LIFECYCLE) { |
| 7932 | Slog.v(TAG, "autofill will ignore first pause when relaunching " + this); |
| 7933 | } |
| 7934 | } |
| 7935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7936 | mCalled = false; |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 7937 | // mResumed is set by the instrumentation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7938 | mInstrumentation.callActivityOnResume(this); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7939 | writeEventLog(LOG_AM_ON_RESUME_CALLED, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7940 | if (!mCalled) { |
| 7941 | throw new SuperNotCalledException( |
| 7942 | "Activity " + mComponent.toShortString() + |
| 7943 | " did not call through to super.onResume()"); |
| 7944 | } |
| 7945 | |
Todd Kennedy | ee8c9c6 | 2014-12-10 14:22:59 -0800 | [diff] [blame] | 7946 | // invisible activities must be finished before onResume() completes |
| 7947 | if (!mVisibleFromClient && !mFinished) { |
| 7948 | Log.w(TAG, "An activity without a UI must call finish() before onResume() completes"); |
| 7949 | if (getApplicationInfo().targetSdkVersion |
| 7950 | > android.os.Build.VERSION_CODES.LOLLIPOP_MR1) { |
| 7951 | throw new IllegalStateException( |
| 7952 | "Activity " + mComponent.toShortString() + |
| 7953 | " did not call finish() prior to onResume() completing"); |
| 7954 | } |
| 7955 | } |
| 7956 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7957 | // Now really resume, and install the current status bar and menu. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7958 | mCalled = false; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7959 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7960 | mFragments.dispatchResume(); |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 7961 | mFragments.execPendingActions(); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 7962 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7963 | onPostResume(); |
| 7964 | if (!mCalled) { |
| 7965 | throw new SuperNotCalledException( |
| 7966 | "Activity " + mComponent.toShortString() + |
| 7967 | " did not call through to super.onPostResume()"); |
| 7968 | } |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7969 | dispatchActivityPostResumed(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7970 | } |
| 7971 | |
| 7972 | final void performPause() { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7973 | dispatchActivityPrePaused(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 7974 | mDoReportFullyDrawn = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7975 | mFragments.dispatchPause(); |
Dianne Hackborn | e794e9f | 2010-08-24 12:32:10 -0700 | [diff] [blame] | 7976 | mCalled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7977 | onPause(); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7978 | writeEventLog(LOG_AM_ON_PAUSE_CALLED, "performPause"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 7979 | mResumed = false; |
Dianne Hackborn | e794e9f | 2010-08-24 12:32:10 -0700 | [diff] [blame] | 7980 | if (!mCalled && getApplicationInfo().targetSdkVersion |
| 7981 | >= android.os.Build.VERSION_CODES.GINGERBREAD) { |
| 7982 | throw new SuperNotCalledException( |
| 7983 | "Activity " + mComponent.toShortString() + |
| 7984 | " did not call through to super.onPause()"); |
| 7985 | } |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7986 | dispatchActivityPostPaused(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7987 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7988 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7989 | final void performUserLeaving() { |
| 7990 | onUserInteraction(); |
| 7991 | onUserLeaveHint(); |
| 7992 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7993 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7994 | final void performStop(boolean preserveWindow, String reason) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 7995 | mDoReportFullyDrawn = false; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7996 | mFragments.doLoaderStop(mChangingConfigurations /*retain*/); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 7997 | |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7998 | // Disallow entering picture-in-picture after the activity has been stopped |
| 7999 | mCanEnterPictureInPicture = false; |
| 8000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8001 | if (!mStopped) { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 8002 | dispatchActivityPreStopped(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8003 | if (mWindow != null) { |
| 8004 | mWindow.closeAllPanels(); |
| 8005 | } |
| 8006 | |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 8007 | // If we're preserving the window, don't setStoppedState to true, since we |
| 8008 | // need the window started immediately again. Stopping the window will |
| 8009 | // destroys hardware resources and causes flicker. |
| 8010 | if (!preserveWindow && mToken != null && mParent == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 8011 | WindowManagerGlobal.getInstance().setStoppedState(mToken, true); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 8012 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 8013 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 8014 | mFragments.dispatchStop(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 8015 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8016 | mCalled = false; |
| 8017 | mInstrumentation.callActivityOnStop(this); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 8018 | writeEventLog(LOG_AM_ON_STOP_CALLED, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8019 | if (!mCalled) { |
| 8020 | throw new SuperNotCalledException( |
| 8021 | "Activity " + mComponent.toShortString() + |
| 8022 | " did not call through to super.onStop()"); |
| 8023 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 8024 | |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 8025 | synchronized (mManagedCursors) { |
| 8026 | final int N = mManagedCursors.size(); |
| 8027 | for (int i=0; i<N; i++) { |
| 8028 | ManagedCursor mc = mManagedCursors.get(i); |
| 8029 | if (!mc.mReleased) { |
| 8030 | mc.mCursor.deactivate(); |
| 8031 | mc.mReleased = true; |
| 8032 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8033 | } |
| 8034 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 8035 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8036 | mStopped = true; |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 8037 | dispatchActivityPostStopped(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8038 | } |
| 8039 | mResumed = false; |
| 8040 | } |
| 8041 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 8042 | final void performDestroy() { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 8043 | dispatchActivityPreDestroyed(); |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 8044 | mDestroyed = true; |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 8045 | mWindow.destroy(); |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 8046 | mFragments.dispatchDestroy(); |
| 8047 | onDestroy(); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 8048 | writeEventLog(LOG_AM_ON_DESTROY_CALLED, "performDestroy"); |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 8049 | mFragments.doLoaderDestroy(); |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 8050 | if (mVoiceInteractor != null) { |
| 8051 | mVoiceInteractor.detachActivity(); |
| 8052 | } |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 8053 | dispatchActivityPostDestroyed(); |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 8054 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 8055 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 8056 | final void dispatchMultiWindowModeChanged(boolean isInMultiWindowMode, |
| 8057 | Configuration newConfig) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 8058 | if (DEBUG_LIFECYCLE) Slog.v(TAG, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 8059 | "dispatchMultiWindowModeChanged " + this + ": " + isInMultiWindowMode |
| 8060 | + " " + newConfig); |
| 8061 | mFragments.dispatchMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 8062 | if (mWindow != null) { |
| 8063 | mWindow.onMultiWindowModeChanged(); |
| 8064 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 8065 | onMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 8066 | } |
| 8067 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 8068 | final void dispatchPictureInPictureModeChanged(boolean isInPictureInPictureMode, |
| 8069 | Configuration newConfig) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 8070 | if (DEBUG_LIFECYCLE) Slog.v(TAG, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 8071 | "dispatchPictureInPictureModeChanged " + this + ": " + isInPictureInPictureMode |
| 8072 | + " " + newConfig); |
| 8073 | mFragments.dispatchPictureInPictureModeChanged(isInPictureInPictureMode, newConfig); |
Winson Chung | 4d8681f | 2017-05-23 16:22:08 -0700 | [diff] [blame] | 8074 | if (mWindow != null) { |
| 8075 | mWindow.onPictureInPictureModeChanged(isInPictureInPictureMode); |
| 8076 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 8077 | onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig); |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 8078 | } |
| 8079 | |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 8080 | /** |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 8081 | * @hide |
| 8082 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 8083 | @UnsupportedAppUsage |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 8084 | public final boolean isResumed() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8085 | return mResumed; |
| 8086 | } |
| 8087 | |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 8088 | private void storeHasCurrentPermissionRequest(Bundle bundle) { |
| 8089 | if (bundle != null && mHasCurrentPermissionsRequest) { |
| 8090 | bundle.putBoolean(HAS_CURENT_PERMISSIONS_REQUEST_KEY, true); |
| 8091 | } |
| 8092 | } |
| 8093 | |
| 8094 | private void restoreHasCurrentPermissionRequest(Bundle bundle) { |
| 8095 | if (bundle != null) { |
| 8096 | mHasCurrentPermissionsRequest = bundle.getBoolean( |
| 8097 | HAS_CURENT_PERMISSIONS_REQUEST_KEY, false); |
| 8098 | } |
| 8099 | } |
| 8100 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 8101 | @UnsupportedAppUsage |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 8102 | void dispatchActivityResult(String who, int requestCode, int resultCode, Intent data, |
| 8103 | String reason) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 8104 | if (false) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8105 | TAG, "Dispatching result: who=" + who + ", reqCode=" + requestCode |
| 8106 | + ", resCode=" + resultCode + ", data=" + data); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 8107 | mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8108 | if (who == null) { |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 8109 | onActivityResult(requestCode, resultCode, data); |
| 8110 | } else if (who.startsWith(REQUEST_PERMISSIONS_WHO_PREFIX)) { |
| 8111 | who = who.substring(REQUEST_PERMISSIONS_WHO_PREFIX.length()); |
| 8112 | if (TextUtils.isEmpty(who)) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 8113 | dispatchRequestPermissionsResult(requestCode, data); |
| 8114 | } else { |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 8115 | Fragment frag = mFragments.findFragmentByWho(who); |
| 8116 | if (frag != null) { |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 8117 | dispatchRequestPermissionsResultToFragment(requestCode, data, frag); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 8118 | } |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 8119 | } |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 8120 | } else if (who.startsWith("@android:view:")) { |
| 8121 | ArrayList<ViewRootImpl> views = WindowManagerGlobal.getInstance().getRootViews( |
| 8122 | getActivityToken()); |
| 8123 | for (ViewRootImpl viewRoot : views) { |
| 8124 | if (viewRoot.getView() != null |
| 8125 | && viewRoot.getView().dispatchActivityResult( |
| 8126 | who, requestCode, resultCode, data)) { |
| 8127 | return; |
| 8128 | } |
| 8129 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 8130 | } else if (who.startsWith(AUTO_FILL_AUTH_WHO_PREFIX)) { |
Svet Ganov | 00c771dc | 2017-02-19 00:06:22 -0800 | [diff] [blame] | 8131 | Intent resultData = (resultCode == Activity.RESULT_OK) ? data : null; |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 8132 | getAutofillManager().onAuthenticationResult(requestCode, resultData, getCurrentFocus()); |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 8133 | } else { |
| 8134 | Fragment frag = mFragments.findFragmentByWho(who); |
| 8135 | if (frag != null) { |
| 8136 | frag.onActivityResult(requestCode, resultCode, data); |
| 8137 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8138 | } |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 8139 | writeEventLog(LOG_AM_ON_ACTIVITY_RESULT_CALLED, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8140 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 8141 | |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8142 | /** |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8143 | * Request to put this activity in a mode where the user is locked to a restricted set of |
| 8144 | * applications. |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8145 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8146 | * <p>If {@link DevicePolicyManager#isLockTaskPermitted(String)} returns {@code true} |
| 8147 | * for this component, the current task will be launched directly into LockTask mode. Only apps |
| 8148 | * whitelisted by {@link DevicePolicyManager#setLockTaskPackages(ComponentName, String[])} can |
| 8149 | * be launched while LockTask mode is active. The user will not be able to leave this mode |
| 8150 | * until this activity calls {@link #stopLockTask()}. Calling this method while the device is |
| 8151 | * already in LockTask mode has no effect. |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8152 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8153 | * <p>Otherwise, the current task will be launched into screen pinning mode. In this case, the |
| 8154 | * system will prompt the user with a dialog requesting permission to use this mode. |
| 8155 | * The user can exit at any time through instructions shown on the request dialog. Calling |
| 8156 | * {@link #stopLockTask()} will also terminate this mode. |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 8157 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8158 | * <p><strong>Note:</strong> this method can only be called when the activity is foreground. |
| 8159 | * That is, between {@link #onResume()} and {@link #onPause()}. |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 8160 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8161 | * @see #stopLockTask() |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 8162 | * @see android.R.attr#lockTaskMode |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8163 | */ |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 8164 | public void startLockTask() { |
| 8165 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 8166 | ActivityTaskManager.getService().startLockTaskModeByToken(mToken); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 8167 | } catch (RemoteException e) { |
| 8168 | } |
| 8169 | } |
| 8170 | |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8171 | /** |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8172 | * Stop the current task from being locked. |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8173 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8174 | * <p>Called to end the LockTask or screen pinning mode started by {@link #startLockTask()}. |
| 8175 | * This can only be called by activities that have called {@link #startLockTask()} previously. |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8176 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8177 | * <p><strong>Note:</strong> If the device is in LockTask mode that is not initially started |
| 8178 | * by this activity, then calling this method will not terminate the LockTask mode, but only |
| 8179 | * finish its own task. The device will remain in LockTask mode, until the activity which |
| 8180 | * started the LockTask mode calls this method, or until its whitelist authorization is revoked |
| 8181 | * by {@link DevicePolicyManager#setLockTaskPackages(ComponentName, String[])}. |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 8182 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8183 | * @see #startLockTask() |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 8184 | * @see android.R.attr#lockTaskMode |
| 8185 | * @see ActivityManager#getLockTaskModeState() |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8186 | */ |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 8187 | public void stopLockTask() { |
| 8188 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 8189 | ActivityTaskManager.getService().stopLockTaskModeByToken(mToken); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 8190 | } catch (RemoteException e) { |
| 8191 | } |
| 8192 | } |
| 8193 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 8194 | /** |
Craig Mautner | c21ae9e | 2015-04-15 09:45:42 -0700 | [diff] [blame] | 8195 | * Shows the user the system defined message for telling the user how to exit |
| 8196 | * lock task mode. The task containing this activity must be in lock task mode at the time |
| 8197 | * of this call for the message to be displayed. |
| 8198 | */ |
| 8199 | public void showLockTaskEscapeMessage() { |
| 8200 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 8201 | ActivityTaskManager.getService().showLockTaskEscapeMessage(mToken); |
Craig Mautner | c21ae9e | 2015-04-15 09:45:42 -0700 | [diff] [blame] | 8202 | } catch (RemoteException e) { |
| 8203 | } |
| 8204 | } |
| 8205 | |
| 8206 | /** |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 8207 | * Check whether the caption on freeform windows is displayed directly on the content. |
| 8208 | * |
| 8209 | * @return True if caption is displayed on content, false if it pushes the content down. |
| 8210 | * |
Elliot Waite | d5ed3bc | 2017-01-25 15:22:55 -0800 | [diff] [blame] | 8211 | * @see #setOverlayWithDecorCaptionEnabled(boolean) |
Wale Ogunwale | 724ca14 | 2017-04-24 13:40:34 -0700 | [diff] [blame] | 8212 | * @hide |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 8213 | */ |
| 8214 | public boolean isOverlayWithDecorCaptionEnabled() { |
| 8215 | return mWindow.isOverlayWithDecorCaptionEnabled(); |
| 8216 | } |
| 8217 | |
| 8218 | /** |
Filip Gruszczynski | 6325065 | 2015-11-18 14:43:01 -0800 | [diff] [blame] | 8219 | * Set whether the caption should displayed directly on the content rather than push it down. |
| 8220 | * |
| 8221 | * This affects only freeform windows since they display the caption and only the main |
| 8222 | * window of the activity. The caption is used to drag the window around and also shows |
| 8223 | * maximize and close action buttons. |
Wale Ogunwale | 724ca14 | 2017-04-24 13:40:34 -0700 | [diff] [blame] | 8224 | * @hide |
Filip Gruszczynski | 6325065 | 2015-11-18 14:43:01 -0800 | [diff] [blame] | 8225 | */ |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 8226 | public void setOverlayWithDecorCaptionEnabled(boolean enabled) { |
| 8227 | mWindow.setOverlayWithDecorCaptionEnabled(enabled); |
Filip Gruszczynski | 6325065 | 2015-11-18 14:43:01 -0800 | [diff] [blame] | 8228 | } |
| 8229 | |
| 8230 | /** |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 8231 | * Interface for informing a translucent {@link Activity} once all visible activities below it |
| 8232 | * have completed drawing. This is necessary only after an {@link Activity} has been made |
| 8233 | * opaque using {@link Activity#convertFromTranslucent()} and before it has been drawn |
| 8234 | * translucent again following a call to {@link |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 8235 | * Activity#convertToTranslucent(android.app.Activity.TranslucentConversionListener, |
| 8236 | * ActivityOptions)} |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 8237 | * |
| 8238 | * @hide |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 8239 | */ |
Jose Lima | 1491485 | 2014-08-14 09:14:12 -0700 | [diff] [blame] | 8240 | @SystemApi |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 8241 | public interface TranslucentConversionListener { |
| 8242 | /** |
| 8243 | * Callback made following {@link Activity#convertToTranslucent} once all visible Activities |
| 8244 | * below the top one have been redrawn. Following this callback it is safe to make the top |
| 8245 | * Activity translucent because the underlying Activity has been drawn. |
| 8246 | * |
| 8247 | * @param drawComplete True if the background Activity has drawn itself. False if a timeout |
| 8248 | * occurred waiting for the Activity to complete drawing. |
| 8249 | * |
| 8250 | * @see Activity#convertFromTranslucent() |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 8251 | * @see Activity#convertToTranslucent(TranslucentConversionListener, ActivityOptions) |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 8252 | */ |
| 8253 | public void onTranslucentConversionComplete(boolean drawComplete); |
| 8254 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 8255 | |
| 8256 | private void dispatchRequestPermissionsResult(int requestCode, Intent data) { |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 8257 | mHasCurrentPermissionsRequest = false; |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 8258 | // If the package installer crashed we may have not data - best effort. |
| 8259 | String[] permissions = (data != null) ? data.getStringArrayExtra( |
| 8260 | PackageManager.EXTRA_REQUEST_PERMISSIONS_NAMES) : new String[0]; |
| 8261 | final int[] grantResults = (data != null) ? data.getIntArrayExtra( |
| 8262 | PackageManager.EXTRA_REQUEST_PERMISSIONS_RESULTS) : new int[0]; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 8263 | onRequestPermissionsResult(requestCode, permissions, grantResults); |
| 8264 | } |
| 8265 | |
| 8266 | private void dispatchRequestPermissionsResultToFragment(int requestCode, Intent data, |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 8267 | Fragment fragment) { |
| 8268 | // If the package installer crashed we may have not data - best effort. |
| 8269 | String[] permissions = (data != null) ? data.getStringArrayExtra( |
| 8270 | PackageManager.EXTRA_REQUEST_PERMISSIONS_NAMES) : new String[0]; |
| 8271 | final int[] grantResults = (data != null) ? data.getIntArrayExtra( |
| 8272 | PackageManager.EXTRA_REQUEST_PERMISSIONS_RESULTS) : new int[0]; |
| 8273 | fragment.onRequestPermissionsResult(requestCode, permissions, grantResults); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 8274 | } |
| 8275 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 8276 | /** @hide */ |
| 8277 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8278 | public final void autofillClientAuthenticate(int authenticationId, IntentSender intent, |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 8279 | Intent fillInIntent) { |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 8280 | try { |
| 8281 | startIntentSenderForResultInner(intent, AUTO_FILL_AUTH_WHO_PREFIX, |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 8282 | authenticationId, fillInIntent, 0, 0, null); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 8283 | } catch (IntentSender.SendIntentException e) { |
| 8284 | Log.e(TAG, "authenticate() failed for intent:" + intent, e); |
| 8285 | } |
| 8286 | } |
| 8287 | |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 8288 | /** @hide */ |
| 8289 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8290 | public final void autofillClientResetableStateAvailable() { |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 8291 | mAutoFillResetNeeded = true; |
| 8292 | } |
| 8293 | |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 8294 | /** @hide */ |
| 8295 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8296 | public final boolean autofillClientRequestShowFillUi(@NonNull View anchor, int width, |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 8297 | int height, @Nullable Rect anchorBounds, IAutofillWindowPresenter presenter) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 8298 | final boolean wasShowing; |
| 8299 | |
| 8300 | if (mAutofillPopupWindow == null) { |
| 8301 | wasShowing = false; |
| 8302 | mAutofillPopupWindow = new AutofillPopupWindow(presenter); |
| 8303 | } else { |
| 8304 | wasShowing = mAutofillPopupWindow.isShowing(); |
| 8305 | } |
Svet Ganov | 374cae1 | 2017-05-10 13:42:33 -0700 | [diff] [blame] | 8306 | mAutofillPopupWindow.update(anchor, 0, 0, width, height, anchorBounds); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 8307 | |
| 8308 | return !wasShowing && mAutofillPopupWindow.isShowing(); |
| 8309 | } |
| 8310 | |
| 8311 | /** @hide */ |
| 8312 | @Override |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 8313 | public final void autofillClientDispatchUnhandledKey(@NonNull View anchor, |
| 8314 | @NonNull KeyEvent keyEvent) { |
| 8315 | ViewRootImpl rootImpl = anchor.getViewRootImpl(); |
| 8316 | if (rootImpl != null) { |
| 8317 | // dont care if anchorView is current focus, for example a custom view may only receive |
| 8318 | // touchEvent, not focusable but can still trigger autofill window. The Key handling |
| 8319 | // might be inside parent of the custom view. |
| 8320 | rootImpl.dispatchKeyFromAutofill(keyEvent); |
| 8321 | } |
| 8322 | } |
| 8323 | |
| 8324 | /** @hide */ |
| 8325 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8326 | public final boolean autofillClientRequestHideFillUi() { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 8327 | if (mAutofillPopupWindow == null) { |
| 8328 | return false; |
| 8329 | } |
| 8330 | mAutofillPopupWindow.dismiss(); |
| 8331 | mAutofillPopupWindow = null; |
| 8332 | return true; |
| 8333 | } |
| 8334 | |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 8335 | /** @hide */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 8336 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8337 | public final boolean autofillClientIsFillUiShowing() { |
| 8338 | return mAutofillPopupWindow != null && mAutofillPopupWindow.isShowing(); |
| 8339 | } |
| 8340 | |
| 8341 | /** @hide */ |
| 8342 | @Override |
| 8343 | @NonNull |
| 8344 | public final View[] autofillClientFindViewsByAutofillIdTraversal( |
| 8345 | @NonNull AutofillId[] autofillId) { |
| 8346 | final View[] views = new View[autofillId.length]; |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 8347 | final ArrayList<ViewRootImpl> roots = |
| 8348 | WindowManagerGlobal.getInstance().getRootViews(getActivityToken()); |
| 8349 | |
| 8350 | for (int rootNum = 0; rootNum < roots.size(); rootNum++) { |
| 8351 | final View rootView = roots.get(rootNum).getView(); |
| 8352 | |
| 8353 | if (rootView != null) { |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8354 | final int viewCount = autofillId.length; |
| 8355 | for (int viewNum = 0; viewNum < viewCount; viewNum++) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 8356 | if (views[viewNum] == null) { |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 8357 | views[viewNum] = rootView.findViewByAutofillIdTraversal( |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8358 | autofillId[viewNum].getViewId()); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 8359 | } |
| 8360 | } |
| 8361 | } |
| 8362 | } |
| 8363 | |
| 8364 | return views; |
| 8365 | } |
| 8366 | |
| 8367 | /** @hide */ |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 8368 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8369 | @Nullable |
| 8370 | public final View autofillClientFindViewByAutofillIdTraversal(AutofillId autofillId) { |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 8371 | final ArrayList<ViewRootImpl> roots = |
| 8372 | WindowManagerGlobal.getInstance().getRootViews(getActivityToken()); |
| 8373 | for (int rootNum = 0; rootNum < roots.size(); rootNum++) { |
| 8374 | final View rootView = roots.get(rootNum).getView(); |
| 8375 | |
| 8376 | if (rootView != null) { |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8377 | final View view = rootView.findViewByAutofillIdTraversal(autofillId.getViewId()); |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 8378 | if (view != null) { |
| 8379 | return view; |
| 8380 | } |
| 8381 | } |
| 8382 | } |
| 8383 | |
| 8384 | return null; |
| 8385 | } |
| 8386 | |
| 8387 | /** @hide */ |
| 8388 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8389 | public final @NonNull boolean[] autofillClientGetViewVisibility( |
| 8390 | @NonNull AutofillId[] autofillIds) { |
| 8391 | final int autofillIdCount = autofillIds.length; |
| 8392 | final boolean[] visible = new boolean[autofillIdCount]; |
| 8393 | for (int i = 0; i < autofillIdCount; i++) { |
| 8394 | final AutofillId autofillId = autofillIds[i]; |
| 8395 | final View view = autofillClientFindViewByAutofillIdTraversal(autofillId); |
| 8396 | if (view != null) { |
Felipe Leme | a75333c | 2019-01-22 15:45:32 -0800 | [diff] [blame] | 8397 | if (!autofillId.isVirtualInt()) { |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8398 | visible[i] = view.isVisibleToUser(); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 8399 | } else { |
Felipe Leme | a75333c | 2019-01-22 15:45:32 -0800 | [diff] [blame] | 8400 | visible[i] = view.isVisibleToUserForAutofill(autofillId.getVirtualChildIntId()); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 8401 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 8402 | } |
| 8403 | } |
Felipe Leme | 5b32ebe | 2018-02-15 12:52:19 -0800 | [diff] [blame] | 8404 | if (android.view.autofill.Helper.sVerbose) { |
| 8405 | Log.v(TAG, "autofillClientGetViewVisibility(): " + Arrays.toString(visible)); |
| 8406 | } |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8407 | return visible; |
| 8408 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 8409 | |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8410 | /** @hide */ |
| 8411 | public final @Nullable View autofillClientFindViewByAccessibilityIdTraversal(int viewId, |
| 8412 | int windowId) { |
| 8413 | final ArrayList<ViewRootImpl> roots = WindowManagerGlobal.getInstance() |
| 8414 | .getRootViews(getActivityToken()); |
| 8415 | for (int rootNum = 0; rootNum < roots.size(); rootNum++) { |
| 8416 | final View rootView = roots.get(rootNum).getView(); |
| 8417 | if (rootView != null && rootView.getAccessibilityWindowId() == windowId) { |
| 8418 | final View view = rootView.findViewByAccessibilityIdTraversal(viewId); |
| 8419 | if (view != null) { |
| 8420 | return view; |
| 8421 | } |
| 8422 | } |
| 8423 | } |
| 8424 | return null; |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 8425 | } |
| 8426 | |
| 8427 | /** @hide */ |
| 8428 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8429 | public final @Nullable IBinder autofillClientGetActivityToken() { |
| 8430 | return getActivityToken(); |
| 8431 | } |
| 8432 | |
| 8433 | /** @hide */ |
| 8434 | @Override |
| 8435 | public final boolean autofillClientIsVisibleForAutofill() { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 8436 | return !mStopped; |
| 8437 | } |
| 8438 | |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 8439 | /** @hide */ |
| 8440 | @Override |
Felipe Leme | 42b9793 | 2018-02-20 13:04:31 -0800 | [diff] [blame] | 8441 | public final boolean autofillClientIsCompatibilityModeEnabled() { |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8442 | return isAutofillCompatibilityEnabled(); |
| 8443 | } |
| 8444 | |
| 8445 | /** @hide */ |
| 8446 | @Override |
| 8447 | public final boolean isDisablingEnterExitEventForAutofill() { |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 8448 | return mAutoFillIgnoreFirstResumePause || !mResumed; |
| 8449 | } |
| 8450 | |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 8451 | /** |
| 8452 | * If set to true, this indicates to the system that it should never take a |
| 8453 | * screenshot of the activity to be used as a representation while it is not in a started state. |
| 8454 | * <p> |
| 8455 | * Note that the system may use the window background of the theme instead to represent |
| 8456 | * the window when it is not running. |
| 8457 | * <p> |
| 8458 | * Also note that in comparison to {@link android.view.WindowManager.LayoutParams#FLAG_SECURE}, |
| 8459 | * this only affects the behavior when the activity's screenshot would be used as a |
| 8460 | * representation when the activity is not in a started state, i.e. in Overview. The system may |
| 8461 | * still take screenshots of the activity in other contexts; for example, when the user takes a |
| 8462 | * screenshot of the entire screen, or when the active |
| 8463 | * {@link android.service.voice.VoiceInteractionService} requests a screenshot via |
| 8464 | * {@link android.service.voice.VoiceInteractionSession#SHOW_WITH_SCREENSHOT}. |
| 8465 | * |
| 8466 | * @param disable {@code true} to disable preview screenshots; {@code false} otherwise. |
| 8467 | * @hide |
| 8468 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 8469 | @UnsupportedAppUsage |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 8470 | public void setDisablePreviewScreenshots(boolean disable) { |
| 8471 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 8472 | ActivityTaskManager.getService().setDisablePreviewScreenshots(mToken, disable); |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 8473 | } catch (RemoteException e) { |
Issei Suzuki | ae7b493 | 2019-03-12 10:03:21 -0700 | [diff] [blame] | 8474 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 8475 | } |
| 8476 | } |
| 8477 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 8478 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 8479 | * Specifies whether an {@link Activity} should be shown on top of the lock screen whenever |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 8480 | * the lockscreen is up and the activity is resumed. Normally an activity will be transitioned |
| 8481 | * to the stopped state if it is started while the lockscreen is up, but with this flag set the |
| 8482 | * activity will remain in the resumed state visible on-top of the lock screen. This value can |
| 8483 | * be set as a manifest attribute using {@link android.R.attr#showWhenLocked}. |
| 8484 | * |
| 8485 | * @param showWhenLocked {@code true} to show the {@link Activity} on top of the lock screen; |
| 8486 | * {@code false} otherwise. |
| 8487 | * @see #setTurnScreenOn(boolean) |
| 8488 | * @see android.R.attr#turnScreenOn |
| 8489 | * @see android.R.attr#showWhenLocked |
| 8490 | */ |
| 8491 | public void setShowWhenLocked(boolean showWhenLocked) { |
| 8492 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 8493 | ActivityTaskManager.getService().setShowWhenLocked(mToken, showWhenLocked); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 8494 | } catch (RemoteException e) { |
Issei Suzuki | ae7b493 | 2019-03-12 10:03:21 -0700 | [diff] [blame] | 8495 | throw e.rethrowFromSystemServer(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 8496 | } |
| 8497 | } |
| 8498 | |
| 8499 | /** |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 8500 | * Specifies whether this {@link Activity} should be shown on top of the lock screen whenever |
| 8501 | * the lockscreen is up and this activity has another activity behind it with the showWhenLock |
| 8502 | * attribute set. That is, this activity is only visible on the lock screen if there is another |
| 8503 | * activity with the showWhenLock attribute visible at the same time on the lock screen. A use |
| 8504 | * case for this is permission dialogs, that should only be visible on the lock screen if their |
| 8505 | * requesting activity is also visible. This value can be set as a manifest attribute using |
| 8506 | * android.R.attr#inheritShowWhenLocked. |
| 8507 | * |
| 8508 | * @param inheritShowWhenLocked {@code true} to show the {@link Activity} on top of the lock |
| 8509 | * screen when this activity has another activity behind it with |
| 8510 | * the showWhenLock attribute set; {@code false} otherwise. |
| 8511 | * @see #setShowWhenLocked(boolean) |
Issei Suzuki | 7c09f0b | 2019-02-28 14:45:50 +0100 | [diff] [blame] | 8512 | * @see android.R.attr#inheritShowWhenLocked |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 8513 | */ |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 8514 | public void setInheritShowWhenLocked(boolean inheritShowWhenLocked) { |
| 8515 | try { |
| 8516 | ActivityTaskManager.getService().setInheritShowWhenLocked( |
| 8517 | mToken, inheritShowWhenLocked); |
| 8518 | } catch (RemoteException e) { |
Issei Suzuki | ae7b493 | 2019-03-12 10:03:21 -0700 | [diff] [blame] | 8519 | throw e.rethrowFromSystemServer(); |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 8520 | } |
| 8521 | } |
| 8522 | |
| 8523 | /** |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 8524 | * Specifies whether the screen should be turned on when the {@link Activity} is resumed. |
| 8525 | * Normally an activity will be transitioned to the stopped state if it is started while the |
| 8526 | * screen if off, but with this flag set the activity will cause the screen to turn on if the |
| 8527 | * activity will be visible and resumed due to the screen coming on. The screen will not be |
| 8528 | * turned on if the activity won't be visible after the screen is turned on. This flag is |
| 8529 | * normally used in conjunction with the {@link android.R.attr#showWhenLocked} flag to make sure |
| 8530 | * the activity is visible after the screen is turned on when the lockscreen is up. In addition, |
| 8531 | * if this flag is set and the activity calls {@link |
| 8532 | * KeyguardManager#requestDismissKeyguard(Activity, KeyguardManager.KeyguardDismissCallback)} |
| 8533 | * the screen will turn on. |
| 8534 | * |
| 8535 | * @param turnScreenOn {@code true} to turn on the screen; {@code false} otherwise. |
| 8536 | * |
| 8537 | * @see #setShowWhenLocked(boolean) |
| 8538 | * @see android.R.attr#turnScreenOn |
| 8539 | * @see android.R.attr#showWhenLocked |
| 8540 | */ |
| 8541 | public void setTurnScreenOn(boolean turnScreenOn) { |
| 8542 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 8543 | ActivityTaskManager.getService().setTurnScreenOn(mToken, turnScreenOn); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 8544 | } catch (RemoteException e) { |
Issei Suzuki | ae7b493 | 2019-03-12 10:03:21 -0700 | [diff] [blame] | 8545 | throw e.rethrowFromSystemServer(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 8546 | } |
| 8547 | } |
| 8548 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 8549 | /** |
| 8550 | * Registers remote animations per transition type for this activity. |
| 8551 | * |
| 8552 | * @param definition The remote animation definition that defines which transition whould run |
| 8553 | * which remote animation. |
| 8554 | * @hide |
| 8555 | */ |
| 8556 | @RequiresPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS) |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 8557 | @UnsupportedAppUsage |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 8558 | public void registerRemoteAnimations(RemoteAnimationDefinition definition) { |
| 8559 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 8560 | ActivityTaskManager.getService().registerRemoteAnimations(mToken, definition); |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 8561 | } catch (RemoteException e) { |
Issei Suzuki | ae7b493 | 2019-03-12 10:03:21 -0700 | [diff] [blame] | 8562 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 8563 | } |
| 8564 | } |
| 8565 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 8566 | /** Log a lifecycle event for current user id and component class. */ |
| 8567 | private void writeEventLog(int event, String reason) { |
| 8568 | EventLog.writeEvent(event, UserHandle.myUserId(), getComponentName().getClassName(), |
| 8569 | reason); |
| 8570 | } |
| 8571 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 8572 | class HostCallbacks extends FragmentHostCallback<Activity> { |
| 8573 | public HostCallbacks() { |
| 8574 | super(Activity.this /*activity*/); |
| 8575 | } |
| 8576 | |
| 8577 | @Override |
| 8578 | public void onDump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 8579 | Activity.this.dump(prefix, fd, writer, args); |
| 8580 | } |
| 8581 | |
| 8582 | @Override |
| 8583 | public boolean onShouldSaveFragmentState(Fragment fragment) { |
| 8584 | return !isFinishing(); |
| 8585 | } |
| 8586 | |
| 8587 | @Override |
| 8588 | public LayoutInflater onGetLayoutInflater() { |
| 8589 | final LayoutInflater result = Activity.this.getLayoutInflater(); |
| 8590 | if (onUseFragmentManagerInflaterFactory()) { |
| 8591 | return result.cloneInContext(Activity.this); |
| 8592 | } |
| 8593 | return result; |
| 8594 | } |
| 8595 | |
| 8596 | @Override |
| 8597 | public boolean onUseFragmentManagerInflaterFactory() { |
| 8598 | // Newer platform versions use the child fragment manager's LayoutInflaterFactory. |
| 8599 | return getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP; |
| 8600 | } |
| 8601 | |
| 8602 | @Override |
| 8603 | public Activity onGetHost() { |
| 8604 | return Activity.this; |
| 8605 | } |
| 8606 | |
| 8607 | @Override |
| 8608 | public void onInvalidateOptionsMenu() { |
| 8609 | Activity.this.invalidateOptionsMenu(); |
| 8610 | } |
| 8611 | |
| 8612 | @Override |
| 8613 | public void onStartActivityFromFragment(Fragment fragment, Intent intent, int requestCode, |
| 8614 | Bundle options) { |
| 8615 | Activity.this.startActivityFromFragment(fragment, intent, requestCode, options); |
| 8616 | } |
| 8617 | |
| 8618 | @Override |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 8619 | public void onStartActivityAsUserFromFragment( |
| 8620 | Fragment fragment, Intent intent, int requestCode, Bundle options, |
| 8621 | UserHandle user) { |
| 8622 | Activity.this.startActivityAsUserFromFragment( |
| 8623 | fragment, intent, requestCode, options, user); |
| 8624 | } |
| 8625 | |
| 8626 | @Override |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 8627 | public void onStartIntentSenderFromFragment(Fragment fragment, IntentSender intent, |
| 8628 | int requestCode, @Nullable Intent fillInIntent, int flagsMask, int flagsValues, |
| 8629 | int extraFlags, Bundle options) throws IntentSender.SendIntentException { |
| 8630 | if (mParent == null) { |
| 8631 | startIntentSenderForResultInner(intent, fragment.mWho, requestCode, fillInIntent, |
| 8632 | flagsMask, flagsValues, options); |
| 8633 | } else if (options != null) { |
| 8634 | mParent.startIntentSenderFromChildFragment(fragment, intent, requestCode, |
| 8635 | fillInIntent, flagsMask, flagsValues, extraFlags, options); |
| 8636 | } |
| 8637 | } |
| 8638 | |
| 8639 | @Override |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 8640 | public void onRequestPermissionsFromFragment(Fragment fragment, String[] permissions, |
| 8641 | int requestCode) { |
| 8642 | String who = REQUEST_PERMISSIONS_WHO_PREFIX + fragment.mWho; |
| 8643 | Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions); |
| 8644 | startActivityForResult(who, intent, requestCode, null); |
| 8645 | } |
| 8646 | |
| 8647 | @Override |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 8648 | public boolean onHasWindowAnimations() { |
| 8649 | return getWindow() != null; |
| 8650 | } |
| 8651 | |
| 8652 | @Override |
| 8653 | public int onGetWindowAnimations() { |
| 8654 | final Window w = getWindow(); |
| 8655 | return (w == null) ? 0 : w.getAttributes().windowAnimations; |
| 8656 | } |
| 8657 | |
Todd Kennedy | 434bd65 | 2015-05-04 12:29:50 -0700 | [diff] [blame] | 8658 | @Override |
| 8659 | public void onAttachFragment(Fragment fragment) { |
| 8660 | Activity.this.onAttachFragment(fragment); |
| 8661 | } |
| 8662 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 8663 | @Nullable |
| 8664 | @Override |
Alan Viverette | 04fd470 | 2017-04-13 16:37:06 -0400 | [diff] [blame] | 8665 | public <T extends View> T onFindViewById(int id) { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 8666 | return Activity.this.findViewById(id); |
| 8667 | } |
| 8668 | |
| 8669 | @Override |
| 8670 | public boolean onHasView() { |
| 8671 | final Window w = getWindow(); |
| 8672 | return (w != null && w.peekDecorView() != null); |
| 8673 | } |
| 8674 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8675 | } |