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; |
Tim Van Patten | ddc4391 | 2018-12-18 17:47:52 -0700 | [diff] [blame] | 68 | import android.os.GraphicsEnvironment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.os.Handler; |
| 70 | import android.os.IBinder; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 71 | import android.os.Looper; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 72 | import android.os.Parcelable; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 73 | import android.os.PersistableBundle; |
Nicholas Sauer | 28348ed74 | 2019-02-15 11:58:32 -0800 | [diff] [blame] | 74 | import android.os.Process; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 75 | import android.os.RemoteException; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 76 | import android.os.ServiceManager.ServiceNotFoundException; |
Brad Fitzpatrick | 7580357 | 2011-01-13 14:21:03 -0800 | [diff] [blame] | 77 | import android.os.StrictMode; |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 78 | import android.os.SystemProperties; |
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; |
Adam He | 328c0e3 | 2019-01-03 15:19:22 -0800 | [diff] [blame] | 128 | import android.view.contentcapture.ContentCaptureContext; |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 129 | import android.view.contentcapture.ContentCaptureManager; |
Adam He | 6240eab | 2019-02-25 13:34:45 -0800 | [diff] [blame] | 130 | import android.view.contentcapture.ContentCaptureManager.ContentCaptureClient; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | import android.widget.AdapterView; |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 132 | import android.widget.Toast; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 133 | import android.widget.Toolbar; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 134 | |
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 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 142 | import java.io.FileDescriptor; |
| 143 | import java.io.PrintWriter; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 144 | import java.lang.annotation.Retention; |
| 145 | import java.lang.annotation.RetentionPolicy; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 146 | import java.util.ArrayList; |
Felipe Leme | 5b32ebe | 2018-02-15 12:52:19 -0800 | [diff] [blame] | 147 | import java.util.Arrays; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 148 | import java.util.HashMap; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 149 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | |
Bryce Lee | e83f34cd | 2017-10-31 19:50:54 -0700 | [diff] [blame] | 151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | /** |
| 153 | * An activity is a single, focused thing that the user can do. Almost all |
| 154 | * activities interact with the user, so the Activity class takes care of |
| 155 | * creating a window for you in which you can place your UI with |
| 156 | * {@link #setContentView}. While activities are often presented to the user |
| 157 | * as full-screen windows, they can also be used in other ways: as floating |
| 158 | * windows (via a theme with {@link android.R.attr#windowIsFloating} set) |
| 159 | * or embedded inside of another activity (using {@link ActivityGroup}). |
| 160 | * |
| 161 | * There are two methods almost all subclasses of Activity will implement: |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 162 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | * <ul> |
| 164 | * <li> {@link #onCreate} is where you initialize your activity. Most |
| 165 | * importantly, here you will usually call {@link #setContentView(int)} |
| 166 | * with a layout resource defining your UI, and using {@link #findViewById} |
| 167 | * to retrieve the widgets in that UI that you need to interact with |
| 168 | * programmatically. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 169 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | * <li> {@link #onPause} is where you deal with the user leaving your |
| 171 | * activity. Most importantly, any changes made by the user should at this |
| 172 | * point be committed (usually to the |
| 173 | * {@link android.content.ContentProvider} holding the data). |
| 174 | * </ul> |
| 175 | * |
| 176 | * <p>To be of use with {@link android.content.Context#startActivity Context.startActivity()}, all |
| 177 | * activity classes must have a corresponding |
| 178 | * {@link android.R.styleable#AndroidManifestActivity <activity>} |
| 179 | * declaration in their package's <code>AndroidManifest.xml</code>.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 180 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | * <p>Topics covered here: |
| 182 | * <ol> |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 183 | * <li><a href="#Fragments">Fragments</a> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | * <li><a href="#ActivityLifecycle">Activity Lifecycle</a> |
| 185 | * <li><a href="#ConfigurationChanges">Configuration Changes</a> |
| 186 | * <li><a href="#StartingActivities">Starting Activities and Getting Results</a> |
| 187 | * <li><a href="#SavingPersistentState">Saving Persistent State</a> |
| 188 | * <li><a href="#Permissions">Permissions</a> |
| 189 | * <li><a href="#ProcessLifecycle">Process Lifecycle</a> |
| 190 | * </ol> |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 191 | * |
| 192 | * <div class="special reference"> |
| 193 | * <h3>Developer Guides</h3> |
| 194 | * <p>The Activity class is an important part of an application's overall lifecycle, |
| 195 | * and the way activities are launched and put together is a fundamental |
| 196 | * part of the platform's application model. For a detailed perspective on the structure of an |
| 197 | * Android application and how activities behave, please read the |
| 198 | * <a href="{@docRoot}guide/topics/fundamentals.html">Application Fundamentals</a> and |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 199 | * <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] | 200 | * developer guides.</p> |
| 201 | * |
| 202 | * <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] | 203 | * <a href="{@docRoot}guide/components/activities.html">Activities</a> |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 204 | * developer guide.</p> |
| 205 | * </div> |
| 206 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 207 | * <a name="Fragments"></a> |
| 208 | * <h3>Fragments</h3> |
| 209 | * |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 210 | * <p>The {@link android.support.v4.app.FragmentActivity} subclass |
| 211 | * 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] | 212 | * modularize their code, build more sophisticated user interfaces for larger |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 213 | * screens, and help scale their application between small and large screens.</p> |
| 214 | * |
| 215 | * <p>For more information about using fragments, read the |
| 216 | * <a href="{@docRoot}guide/components/fragments.html">Fragments</a> developer guide.</p> |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 217 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | * <a name="ActivityLifecycle"></a> |
| 219 | * <h3>Activity Lifecycle</h3> |
| 220 | * |
| 221 | * <p>Activities in the system are managed as an <em>activity stack</em>. |
| 222 | * When a new activity is started, it is placed on the top of the stack |
| 223 | * and becomes the running activity -- the previous activity always remains |
| 224 | * below it in the stack, and will not come to the foreground again until |
| 225 | * the new activity exits.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 226 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | * <p>An activity has essentially four states:</p> |
| 228 | * <ul> |
Trevor Johns | 682c24e | 2016-04-12 10:13:47 -0700 | [diff] [blame] | 229 | * <li> If an activity is in the foreground of the screen (at the top of |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | * the stack), |
| 231 | * it is <em>active</em> or <em>running</em>. </li> |
| 232 | * <li>If an activity has lost focus but is still visible (that is, a new non-full-sized |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 233 | * or transparent activity has focus on top of your activity), it |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | * is <em>paused</em>. A paused activity is completely alive (it |
| 235 | * maintains all state and member information and remains attached to |
| 236 | * the window manager), but can be killed by the system in extreme |
| 237 | * low memory situations. |
| 238 | * <li>If an activity is completely obscured by another activity, |
| 239 | * it is <em>stopped</em>. It still retains all state and member information, |
| 240 | * however, it is no longer visible to the user so its window is hidden |
| 241 | * and it will often be killed by the system when memory is needed |
| 242 | * elsewhere.</li> |
| 243 | * <li>If an activity is paused or stopped, the system can drop the activity |
| 244 | * from memory by either asking it to finish, or simply killing its |
| 245 | * process. When it is displayed again to the user, it must be |
| 246 | * completely restarted and restored to its previous state.</li> |
| 247 | * </ul> |
| 248 | * |
| 249 | * <p>The following diagram shows the important state paths of an Activity. |
| 250 | * The square rectangles represent callback methods you can implement to |
| 251 | * perform operations when the Activity moves between states. The colored |
| 252 | * ovals are major states the Activity can be in.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 253 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | * <p><img src="../../../images/activity_lifecycle.png" |
| 255 | * alt="State diagram for an Android Activity Lifecycle." border="0" /></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 256 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | * <p>There are three key loops you may be interested in monitoring within your |
| 258 | * activity: |
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 | * <ul> |
| 261 | * <li>The <b>entire lifetime</b> of an activity happens between the first call |
| 262 | * to {@link android.app.Activity#onCreate} through to a single final call |
| 263 | * to {@link android.app.Activity#onDestroy}. An activity will do all setup |
| 264 | * of "global" state in onCreate(), and release all remaining resources in |
| 265 | * onDestroy(). For example, if it has a thread running in the background |
| 266 | * to download data from the network, it may create that thread in onCreate() |
| 267 | * and then stop the thread in onDestroy(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 268 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | * <li>The <b>visible lifetime</b> of an activity happens between a call to |
| 270 | * {@link android.app.Activity#onStart} until a corresponding call to |
| 271 | * {@link android.app.Activity#onStop}. During this time the user can see the |
| 272 | * activity on-screen, though it may not be in the foreground and interacting |
| 273 | * with the user. Between these two methods you can maintain resources that |
| 274 | * are needed to show the activity to the user. For example, you can register |
| 275 | * a {@link android.content.BroadcastReceiver} in onStart() to monitor for changes |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 276 | * that impact your UI, and unregister it in onStop() when the user no |
| 277 | * 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] | 278 | * can be called multiple times, as the activity becomes visible and hidden |
| 279 | * to the user. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 280 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | * <li>The <b>foreground lifetime</b> of an activity happens between a call to |
| 282 | * {@link android.app.Activity#onResume} until a corresponding call to |
| 283 | * {@link android.app.Activity#onPause}. During this time the activity is |
| 284 | * in front of all other activities and interacting with the user. An activity |
| 285 | * can frequently go between the resumed and paused states -- for example when |
| 286 | * the device goes to sleep, when an activity result is delivered, when a new |
| 287 | * intent is delivered -- so the code in these methods should be fairly |
| 288 | * lightweight. |
| 289 | * </ul> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 290 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | * <p>The entire lifecycle of an activity is defined by the following |
| 292 | * Activity methods. All of these are hooks that you can override |
| 293 | * to do appropriate work when the activity changes state. All |
| 294 | * activities will implement {@link android.app.Activity#onCreate} |
| 295 | * to do their initial setup; many will also implement |
| 296 | * {@link android.app.Activity#onPause} to commit changes to data and |
| 297 | * otherwise prepare to stop interacting with the user. You should always |
| 298 | * call up to your superclass when implementing these methods.</p> |
| 299 | * |
| 300 | * </p> |
| 301 | * <pre class="prettyprint"> |
| 302 | * public class Activity extends ApplicationContext { |
| 303 | * protected void onCreate(Bundle savedInstanceState); |
| 304 | * |
| 305 | * protected void onStart(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 306 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | * protected void onRestart(); |
| 308 | * |
| 309 | * protected void onResume(); |
| 310 | * |
| 311 | * protected void onPause(); |
| 312 | * |
| 313 | * protected void onStop(); |
| 314 | * |
| 315 | * protected void onDestroy(); |
| 316 | * } |
| 317 | * </pre> |
| 318 | * |
| 319 | * <p>In general the movement through an activity's lifecycle looks like |
| 320 | * this:</p> |
| 321 | * |
| 322 | * <table border="2" width="85%" align="center" frame="hsides" rules="rows"> |
| 323 | * <colgroup align="left" span="3" /> |
| 324 | * <colgroup align="left" /> |
| 325 | * <colgroup align="center" /> |
| 326 | * <colgroup align="center" /> |
| 327 | * |
| 328 | * <thead> |
| 329 | * <tr><th colspan="3">Method</th> <th>Description</th> <th>Killable?</th> <th>Next</th></tr> |
| 330 | * </thead> |
| 331 | * |
| 332 | * <tbody> |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 333 | * <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] | 334 | * <td>Called when the activity is first created. |
| 335 | * This is where you should do all of your normal static set up: |
| 336 | * create views, bind data to lists, etc. This method also |
| 337 | * provides you with a Bundle containing the activity's previously |
| 338 | * frozen state, if there was one. |
| 339 | * <p>Always followed by <code>onStart()</code>.</td> |
| 340 | * <td align="center">No</td> |
| 341 | * <td align="center"><code>onStart()</code></td> |
| 342 | * </tr> |
| 343 | * |
| 344 | * <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] | 345 | * <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] | 346 | * <td>Called after your activity has been stopped, prior to it being |
| 347 | * started again. |
| 348 | * <p>Always followed by <code>onStart()</code></td> |
| 349 | * <td align="center">No</td> |
| 350 | * <td align="center"><code>onStart()</code></td> |
| 351 | * </tr> |
| 352 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 353 | * <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] | 354 | * <td>Called when the activity is becoming visible to the user. |
| 355 | * <p>Followed by <code>onResume()</code> if the activity comes |
| 356 | * to the foreground, or <code>onStop()</code> if it becomes hidden.</td> |
| 357 | * <td align="center">No</td> |
| 358 | * <td align="center"><code>onResume()</code> or <code>onStop()</code></td> |
| 359 | * </tr> |
| 360 | * |
| 361 | * <tr><td rowspan="2" style="border-left: none;"> </td> |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 362 | * <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] | 363 | * <td>Called when the activity will start |
| 364 | * interacting with the user. At this point your activity is at |
| 365 | * the top of the activity stack, with user input going to it. |
| 366 | * <p>Always followed by <code>onPause()</code>.</td> |
| 367 | * <td align="center">No</td> |
| 368 | * <td align="center"><code>onPause()</code></td> |
| 369 | * </tr> |
| 370 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 371 | * <tr><td align="left" border="0">{@link android.app.Activity#onPause onPause()}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | * <td>Called when the system is about to start resuming a previous |
| 373 | * activity. This is typically used to commit unsaved changes to |
| 374 | * persistent data, stop animations and other things that may be consuming |
| 375 | * CPU, etc. Implementations of this method must be very quick because |
| 376 | * the next activity will not be resumed until this method returns. |
| 377 | * <p>Followed by either <code>onResume()</code> if the activity |
| 378 | * returns back to the front, or <code>onStop()</code> if it becomes |
| 379 | * invisible to the user.</td> |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 380 | * <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] | 381 | * <td align="center"><code>onResume()</code> or<br> |
| 382 | * <code>onStop()</code></td> |
| 383 | * </tr> |
| 384 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 385 | * <tr><td colspan="2" align="left" border="0">{@link android.app.Activity#onStop onStop()}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | * <td>Called when the activity is no longer visible to the user, because |
| 387 | * another activity has been resumed and is covering this one. This |
| 388 | * may happen either because a new activity is being started, an existing |
| 389 | * one is being brought in front of this one, or this one is being |
| 390 | * destroyed. |
| 391 | * <p>Followed by either <code>onRestart()</code> if |
| 392 | * this activity is coming back to interact with the user, or |
| 393 | * <code>onDestroy()</code> if this activity is going away.</td> |
| 394 | * <td align="center"><font color="#800000"><strong>Yes</strong></font></td> |
| 395 | * <td align="center"><code>onRestart()</code> or<br> |
| 396 | * <code>onDestroy()</code></td> |
| 397 | * </tr> |
| 398 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 399 | * <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] | 400 | * <td>The final call you receive before your |
| 401 | * activity is destroyed. This can happen either because the |
| 402 | * activity is finishing (someone called {@link Activity#finish} on |
kopriva | fdb0bff | 2018-09-29 15:22:41 -0700 | [diff] [blame] | 403 | * it), or because the system is temporarily destroying this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | * instance of the activity to save space. You can distinguish |
| 405 | * between these two scenarios with the {@link |
| 406 | * Activity#isFinishing} method.</td> |
| 407 | * <td align="center"><font color="#800000"><strong>Yes</strong></font></td> |
| 408 | * <td align="center"><em>nothing</em></td> |
| 409 | * </tr> |
| 410 | * </tbody> |
| 411 | * </table> |
| 412 | * |
| 413 | * <p>Note the "Killable" column in the above table -- for those methods that |
| 414 | * 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] | 415 | * 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] | 416 | * of its code being executed. Because of this, you should use the |
| 417 | * {@link #onPause} method to write any persistent data (such as user edits) |
| 418 | * to storage. In addition, the method |
| 419 | * {@link #onSaveInstanceState(Bundle)} is called before placing the activity |
| 420 | * in such a background state, allowing you to save away any dynamic instance |
| 421 | * state in your activity into the given Bundle, to be later received in |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 422 | * {@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] | 423 | * See the <a href="#ProcessLifecycle">Process Lifecycle</a> |
| 424 | * section for more information on how the lifecycle of a process is tied |
| 425 | * to the activities it is hosting. Note that it is important to save |
| 426 | * persistent data in {@link #onPause} instead of {@link #onSaveInstanceState} |
Daisuke Miyakawa | 5c40f3f | 2011-02-15 13:24:36 -0800 | [diff] [blame] | 427 | * 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] | 428 | * be called in every situation as described in its documentation.</p> |
| 429 | * |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 430 | * <p class="note">Be aware that these semantics will change slightly between |
| 431 | * applications targeting platforms starting with {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 432 | * vs. those targeting prior platforms. Starting with Honeycomb, an application |
| 433 | * is not in the killable state until its {@link #onStop} has returned. This |
| 434 | * impacts when {@link #onSaveInstanceState(Bundle)} may be called (it may be |
Joshua Baxter | 9a841a6 | 2018-03-27 14:42:03 -0700 | [diff] [blame] | 435 | * safely called after {@link #onPause()}) and allows an application to safely |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 436 | * wait until {@link #onStop()} to save persistent state.</p> |
| 437 | * |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 438 | * <p class="note">For applications targeting platforms starting with |
| 439 | * {@link android.os.Build.VERSION_CODES#P} {@link #onSaveInstanceState(Bundle)} |
| 440 | * will always be called after {@link #onStop}, so an application may safely |
| 441 | * perform fragment transactions in {@link #onStop} and will be able to save |
| 442 | * persistent state later.</p> |
| 443 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | * <p>For those methods that are not marked as being killable, the activity's |
| 445 | * process will not be killed by the system starting from the time the method |
| 446 | * is called and continuing after it returns. Thus an activity is in the killable |
| 447 | * state, for example, between after <code>onPause()</code> to the start of |
| 448 | * <code>onResume()</code>.</p> |
| 449 | * |
| 450 | * <a name="ConfigurationChanges"></a> |
| 451 | * <h3>Configuration Changes</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 452 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | * <p>If the configuration of the device (as defined by the |
| 454 | * {@link Configuration Resources.Configuration} class) changes, |
| 455 | * then anything displaying a user interface will need to update to match that |
| 456 | * configuration. Because Activity is the primary mechanism for interacting |
| 457 | * with the user, it includes special support for handling configuration |
| 458 | * changes.</p> |
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>Unless you specify otherwise, a configuration change (such as a change |
| 461 | * in screen orientation, language, input devices, etc) will cause your |
| 462 | * current activity to be <em>destroyed</em>, going through the normal activity |
| 463 | * lifecycle process of {@link #onPause}, |
| 464 | * {@link #onStop}, and {@link #onDestroy} as appropriate. If the activity |
| 465 | * had been in the foreground or visible to the user, once {@link #onDestroy} is |
| 466 | * called in that instance then a new instance of the activity will be |
| 467 | * created, with whatever savedInstanceState the previous instance had generated |
| 468 | * from {@link #onSaveInstanceState}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 469 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | * <p>This is done because any application resource, |
| 471 | * including layout files, can change based on any configuration value. Thus |
| 472 | * the only safe way to handle a configuration change is to re-retrieve all |
| 473 | * resources, including layouts, drawables, and strings. Because activities |
| 474 | * must already know how to save their state and re-create themselves from |
| 475 | * that state, this is a convenient way to have an activity restart itself |
| 476 | * with a new configuration.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 477 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | * <p>In some special cases, you may want to bypass restarting of your |
| 479 | * activity based on one or more types of configuration changes. This is |
| 480 | * done with the {@link android.R.attr#configChanges android:configChanges} |
| 481 | * attribute in its manifest. For any types of configuration changes you say |
| 482 | * that you handle there, you will receive a call to your current activity's |
| 483 | * {@link #onConfigurationChanged} method instead of being restarted. If |
| 484 | * a configuration change involves any that you do not handle, however, the |
| 485 | * activity will still be restarted and {@link #onConfigurationChanged} |
| 486 | * will not be called.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 487 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | * <a name="StartingActivities"></a> |
| 489 | * <h3>Starting Activities and Getting Results</h3> |
| 490 | * |
| 491 | * <p>The {@link android.app.Activity#startActivity} |
| 492 | * method is used to start a |
| 493 | * new activity, which will be placed at the top of the activity stack. It |
| 494 | * takes a single argument, an {@link android.content.Intent Intent}, |
| 495 | * which describes the activity |
| 496 | * to be executed.</p> |
| 497 | * |
| 498 | * <p>Sometimes you want to get a result back from an activity when it |
| 499 | * ends. For example, you may start an activity that lets the user pick |
| 500 | * a person in a list of contacts; when it ends, it returns the person |
| 501 | * that was selected. To do this, you call the |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 502 | * {@link android.app.Activity#startActivityForResult(Intent, int)} |
| 503 | * 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] | 504 | * will come back through your {@link android.app.Activity#onActivityResult} |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 505 | * method.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 506 | * |
| 507 | * <p>When an activity exits, it can call |
| 508 | * {@link android.app.Activity#setResult(int)} |
| 509 | * to return data back to its parent. It must always supply a result code, |
| 510 | * which can be the standard results RESULT_CANCELED, RESULT_OK, or any |
| 511 | * custom values starting at RESULT_FIRST_USER. In addition, it can optionally |
| 512 | * return back an Intent containing any additional data it wants. All of this |
| 513 | * information appears back on the |
| 514 | * parent's <code>Activity.onActivityResult()</code>, along with the integer |
| 515 | * identifier it originally supplied.</p> |
| 516 | * |
| 517 | * <p>If a child activity fails for any reason (such as crashing), the parent |
| 518 | * activity will receive a result with the code RESULT_CANCELED.</p> |
| 519 | * |
| 520 | * <pre class="prettyprint"> |
| 521 | * public class MyActivity extends Activity { |
| 522 | * ... |
| 523 | * |
| 524 | * static final int PICK_CONTACT_REQUEST = 0; |
| 525 | * |
Michael Wright | 5438e4e | 2014-07-25 14:05:42 -0700 | [diff] [blame] | 526 | * public boolean onKeyDown(int keyCode, KeyEvent event) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | * if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { |
| 528 | * // When the user center presses, let them pick a contact. |
| 529 | * startActivityForResult( |
| 530 | * new Intent(Intent.ACTION_PICK, |
| 531 | * new Uri("content://contacts")), |
| 532 | * PICK_CONTACT_REQUEST); |
| 533 | * return true; |
| 534 | * } |
| 535 | * return false; |
| 536 | * } |
| 537 | * |
| 538 | * protected void onActivityResult(int requestCode, int resultCode, |
| 539 | * Intent data) { |
| 540 | * if (requestCode == PICK_CONTACT_REQUEST) { |
| 541 | * if (resultCode == RESULT_OK) { |
| 542 | * // A contact was picked. Here we will just display it |
| 543 | * // to the user. |
| 544 | * startActivity(new Intent(Intent.ACTION_VIEW, data)); |
| 545 | * } |
| 546 | * } |
| 547 | * } |
| 548 | * } |
| 549 | * </pre> |
| 550 | * |
| 551 | * <a name="SavingPersistentState"></a> |
| 552 | * <h3>Saving Persistent State</h3> |
| 553 | * |
kopriva | fc3949e | 2018-09-17 11:35:13 -0700 | [diff] [blame] | 554 | * <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] | 555 | * will deal with: shared document-like data (typically stored in a SQLite |
| 556 | * database using a {@linkplain android.content.ContentProvider content provider}) |
| 557 | * and internal state such as user preferences.</p> |
| 558 | * |
kopriva | fc3949e | 2018-09-17 11:35:13 -0700 | [diff] [blame] | 559 | * <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] | 560 | * "edit in place" user model. That is, any edits a user makes are effectively |
| 561 | * made immediately without requiring an additional confirmation step. |
| 562 | * Supporting this model is generally a simple matter of following two rules:</p> |
| 563 | * |
| 564 | * <ul> |
| 565 | * <li> <p>When creating a new document, the backing database entry or file for |
| 566 | * it is created immediately. For example, if the user chooses to write |
Andrew Solovay | ab8ea9f | 2017-10-06 19:02:28 -0700 | [diff] [blame] | 567 | * 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] | 568 | * 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] | 569 | * 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] | 570 | * <li> <p>When an activity's <code>onPause()</code> method is called, it should |
| 571 | * commit to the backing content provider or file any changes the user |
| 572 | * has made. This ensures that those changes will be seen by any other |
| 573 | * activity that is about to run. You will probably want to commit |
| 574 | * your data even more aggressively at key times during your |
| 575 | * activity's lifecycle: for example before starting a new |
| 576 | * activity, before finishing your own activity, when the user |
| 577 | * switches between input fields, etc.</p> |
| 578 | * </ul> |
| 579 | * |
| 580 | * <p>This model is designed to prevent data loss when a user is navigating |
| 581 | * between activities, and allows the system to safely kill an activity (because |
| 582 | * system resources are needed somewhere else) at any time after it has been |
| 583 | * paused. Note this implies |
| 584 | * that the user pressing BACK from your activity does <em>not</em> |
| 585 | * mean "cancel" -- it means to leave the activity with its current contents |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 586 | * 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] | 587 | * some other mechanism, such as an explicit "revert" or "undo" option.</p> |
| 588 | * |
| 589 | * <p>See the {@linkplain android.content.ContentProvider content package} for |
| 590 | * more information about content providers. These are a key aspect of how |
| 591 | * different activities invoke and propagate data between themselves.</p> |
| 592 | * |
| 593 | * <p>The Activity class also provides an API for managing internal persistent state |
| 594 | * associated with an activity. This can be used, for example, to remember |
| 595 | * the user's preferred initial display in a calendar (day view or week view) |
| 596 | * or the user's default home page in a web browser.</p> |
| 597 | * |
| 598 | * <p>Activity persistent state is managed |
| 599 | * with the method {@link #getPreferences}, |
| 600 | * allowing you to retrieve and |
| 601 | * modify a set of name/value pairs associated with the activity. To use |
| 602 | * preferences that are shared across multiple application components |
| 603 | * (activities, receivers, services, providers), you can use the underlying |
| 604 | * {@link Context#getSharedPreferences Context.getSharedPreferences()} method |
| 605 | * to retrieve a preferences |
| 606 | * object stored under a specific name. |
| 607 | * (Note that it is not possible to share settings data across application |
| 608 | * packages -- for that you will need a content provider.)</p> |
| 609 | * |
| 610 | * <p>Here is an excerpt from a calendar activity that stores the user's |
| 611 | * preferred view mode in its persistent settings:</p> |
| 612 | * |
| 613 | * <pre class="prettyprint"> |
| 614 | * public class CalendarActivity extends Activity { |
| 615 | * ... |
| 616 | * |
| 617 | * static final int DAY_VIEW_MODE = 0; |
| 618 | * static final int WEEK_VIEW_MODE = 1; |
| 619 | * |
| 620 | * private SharedPreferences mPrefs; |
| 621 | * private int mCurViewMode; |
| 622 | * |
| 623 | * protected void onCreate(Bundle savedInstanceState) { |
| 624 | * super.onCreate(savedInstanceState); |
| 625 | * |
| 626 | * SharedPreferences mPrefs = getSharedPreferences(); |
Quddus Chong | 3fa98cb | 2012-04-13 11:17:24 -0700 | [diff] [blame] | 627 | * mCurViewMode = mPrefs.getInt("view_mode", DAY_VIEW_MODE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | * } |
| 629 | * |
| 630 | * protected void onPause() { |
| 631 | * super.onPause(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 632 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | * SharedPreferences.Editor ed = mPrefs.edit(); |
| 634 | * ed.putInt("view_mode", mCurViewMode); |
| 635 | * ed.commit(); |
| 636 | * } |
| 637 | * } |
| 638 | * </pre> |
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 | * <a name="Permissions"></a> |
| 641 | * <h3>Permissions</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 642 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 643 | * <p>The ability to start a particular Activity can be enforced when it is |
| 644 | * declared in its |
| 645 | * manifest's {@link android.R.styleable#AndroidManifestActivity <activity>} |
| 646 | * tag. By doing so, other applications will need to declare a corresponding |
| 647 | * {@link android.R.styleable#AndroidManifestUsesPermission <uses-permission>} |
| 648 | * element in their own manifest to be able to start that activity. |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 649 | * |
| 650 | * <p>When starting an Activity you can set {@link Intent#FLAG_GRANT_READ_URI_PERMISSION |
| 651 | * Intent.FLAG_GRANT_READ_URI_PERMISSION} and/or {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 652 | * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} on the Intent. This will grant the |
| 653 | * Activity access to the specific URIs in the Intent. Access will remain |
| 654 | * until the Activity has finished (it will remain across the hosting |
| 655 | * process being killed and other temporary destruction). As of |
| 656 | * {@link android.os.Build.VERSION_CODES#GINGERBREAD}, if the Activity |
| 657 | * was already created and a new Intent is being delivered to |
| 658 | * {@link #onNewIntent(Intent)}, any newly granted URI permissions will be added |
| 659 | * to the existing ones it holds. |
| 660 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 661 | * <p>See the <a href="{@docRoot}guide/topics/security/security.html">Security and Permissions</a> |
| 662 | * document for more information on permissions and security in general. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 663 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 664 | * <a name="ProcessLifecycle"></a> |
| 665 | * <h3>Process Lifecycle</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 666 | * |
kopriva | 4dddc63 | 2018-03-19 14:13:08 -0700 | [diff] [blame] | 667 | * <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] | 668 | * long as possible, but eventually will need to remove old processes when |
kopriva | 4dddc63 | 2018-03-19 14:13:08 -0700 | [diff] [blame] | 669 | * 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] | 670 | * Lifecycle</a>, the decision about which process to remove is intimately |
kopriva | 4dddc63 | 2018-03-19 14:13:08 -0700 | [diff] [blame] | 671 | * 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] | 672 | * 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] | 673 | * 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] | 674 | * processes (the last ones) before it resorts to killing more important |
| 675 | * processes (the first ones). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 676 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | * <ol> |
| 678 | * <li> <p>The <b>foreground activity</b> (the activity at the top of the screen |
| 679 | * that the user is currently interacting with) is considered the most important. |
| 680 | * Its process will only be killed as a last resort, if it uses more memory |
| 681 | * than is available on the device. Generally at this point the device has |
| 682 | * reached a memory paging state, so this is required in order to keep the user |
| 683 | * interface responsive. |
| 684 | * <li> <p>A <b>visible activity</b> (an activity that is visible to the user |
| 685 | * but not in the foreground, such as one sitting behind a foreground dialog) |
| 686 | * is considered extremely important and will not be killed unless that is |
| 687 | * required to keep the foreground activity running. |
| 688 | * <li> <p>A <b>background activity</b> (an activity that is not visible to |
| 689 | * the user and has been paused) is no longer critical, so the system may |
| 690 | * safely kill its process to reclaim memory for other foreground or |
| 691 | * visible processes. If its process needs to be killed, when the user navigates |
| 692 | * back to the activity (making it visible on the screen again), its |
| 693 | * {@link #onCreate} method will be called with the savedInstanceState it had previously |
| 694 | * supplied in {@link #onSaveInstanceState} so that it can restart itself in the same |
| 695 | * state as the user last left it. |
| 696 | * <li> <p>An <b>empty process</b> is one hosting no activities or other |
| 697 | * application components (such as {@link Service} or |
| 698 | * {@link android.content.BroadcastReceiver} classes). These are killed very |
| 699 | * quickly by the system as memory becomes low. For this reason, any |
| 700 | * background operation you do outside of an activity must be executed in the |
| 701 | * context of an activity BroadcastReceiver or Service to ensure that the system |
| 702 | * knows it needs to keep your process around. |
| 703 | * </ol> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 704 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | * <p>Sometimes an Activity may need to do a long-running operation that exists |
| 706 | * independently of the activity lifecycle itself. An example may be a camera |
| 707 | * application that allows you to upload a picture to a web site. The upload |
| 708 | * 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] | 709 | * 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] | 710 | * should start a {@link Service} in which the upload takes place. This allows |
| 711 | * the system to properly prioritize your process (considering it to be more |
| 712 | * important than other non-visible applications) for the duration of the |
| 713 | * upload, independent of whether the original activity is paused, stopped, |
| 714 | * or finished. |
| 715 | */ |
| 716 | public class Activity extends ContextThemeWrapper |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 717 | implements LayoutInflater.Factory2, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 718 | Window.Callback, KeyEvent.Callback, |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 719 | OnCreateContextMenuListener, ComponentCallbacks2, |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 720 | Window.OnWindowDismissedCallback, WindowControllerCallback, |
Adam He | 6240eab | 2019-02-25 13:34:45 -0800 | [diff] [blame] | 721 | AutofillManager.AutofillClient, ContentCaptureManager.ContentCaptureClient { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | private static final String TAG = "Activity"; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 723 | private static final boolean DEBUG_LIFECYCLE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 724 | |
| 725 | /** Standard activity result: operation canceled. */ |
| 726 | public static final int RESULT_CANCELED = 0; |
| 727 | /** Standard activity result: operation succeeded. */ |
| 728 | public static final int RESULT_OK = -1; |
| 729 | /** Start of user-defined activity results. */ |
| 730 | public static final int RESULT_FIRST_USER = 1; |
| 731 | |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 732 | /** @hide Task isn't finished when activity is finished */ |
| 733 | public static final int DONT_FINISH_TASK_WITH_ACTIVITY = 0; |
Filip Gruszczynski | c29ecc8 | 2015-10-08 11:08:44 -0700 | [diff] [blame] | 734 | /** |
| 735 | * @hide Task is finished if the finishing activity is the root of the task. To preserve the |
| 736 | * past behavior the task is also removed from recents. |
| 737 | */ |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 738 | public static final int FINISH_TASK_WITH_ROOT_ACTIVITY = 1; |
Filip Gruszczynski | c29ecc8 | 2015-10-08 11:08:44 -0700 | [diff] [blame] | 739 | /** |
| 740 | * @hide Task is finished along with the finishing activity, but it is not removed from |
| 741 | * recents. |
| 742 | */ |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 743 | public static final int FINISH_TASK_WITH_ACTIVITY = 2; |
| 744 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 745 | @UnsupportedAppUsage |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 746 | static final String FRAGMENTS_TAG = "android:fragments"; |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 747 | private static final String LAST_AUTOFILL_ID = "android:lastAutofillId"; |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 748 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 749 | private static final String AUTOFILL_RESET_NEEDED = "@android:autofillResetNeeded"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 750 | private static final String WINDOW_HIERARCHY_TAG = "android:viewHierarchyState"; |
| 751 | private static final String SAVED_DIALOG_IDS_KEY = "android:savedDialogIds"; |
| 752 | private static final String SAVED_DIALOGS_TAG = "android:savedDialogs"; |
| 753 | private static final String SAVED_DIALOG_KEY_PREFIX = "android:dialog_"; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 754 | private static final String SAVED_DIALOG_ARGS_KEY_PREFIX = "android:dialog_args_"; |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 755 | private static final String HAS_CURENT_PERMISSIONS_REQUEST_KEY = |
| 756 | "android:hasCurrentPermissionsRequest"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 757 | |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 758 | private static final String REQUEST_PERMISSIONS_WHO_PREFIX = "@android:requestPermissions:"; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 759 | private static final String AUTO_FILL_AUTH_WHO_PREFIX = "@android:autoFillAuth:"; |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 760 | |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 761 | private static final String KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME = "com.android.systemui"; |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 762 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 763 | private static final int LOG_AM_ON_CREATE_CALLED = 30057; |
| 764 | private static final int LOG_AM_ON_START_CALLED = 30059; |
| 765 | private static final int LOG_AM_ON_RESUME_CALLED = 30022; |
| 766 | private static final int LOG_AM_ON_PAUSE_CALLED = 30021; |
| 767 | private static final int LOG_AM_ON_STOP_CALLED = 30049; |
| 768 | private static final int LOG_AM_ON_RESTART_CALLED = 30058; |
| 769 | private static final int LOG_AM_ON_DESTROY_CALLED = 30060; |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 770 | private static final int LOG_AM_ON_ACTIVITY_RESULT_CALLED = 30062; |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 771 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 772 | private static class ManagedDialog { |
| 773 | Dialog mDialog; |
| 774 | Bundle mArgs; |
| 775 | } |
| 776 | private SparseArray<ManagedDialog> mManagedDialogs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 777 | |
| 778 | // 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] | 779 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 780 | private Instrumentation mInstrumentation; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 781 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 782 | private IBinder mToken; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 783 | @UnsupportedAppUsage |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 784 | private int mIdent; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 785 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | /*package*/ String mEmbeddedID; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 787 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | private Application mApplication; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 789 | @UnsupportedAppUsage |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 790 | /*package*/ Intent mIntent; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 791 | @UnsupportedAppUsage |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 792 | /*package*/ String mReferrer; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 793 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | private ComponentName mComponent; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 795 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | /*package*/ ActivityInfo mActivityInfo; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 797 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | /*package*/ ActivityThread mMainThread; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 799 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | Activity mParent; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 801 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 802 | boolean mCalled; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 803 | @UnsupportedAppUsage |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 804 | /*package*/ boolean mResumed; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 805 | @UnsupportedAppUsage |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 806 | /*package*/ boolean mStopped; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 807 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | boolean mFinished; |
| 809 | boolean mStartedActivity; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 810 | @UnsupportedAppUsage |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 811 | private boolean mDestroyed; |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 812 | private boolean mDoReportFullyDrawn = true; |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 813 | private boolean mRestoredFromBundle; |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 814 | |
| 815 | /** {@code true} if the activity lifecycle is in a state which supports picture-in-picture. |
| 816 | * This only affects the client-side exception, the actual state check still happens in AMS. */ |
| 817 | private boolean mCanEnterPictureInPicture = false; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 818 | /** true if the activity is going through a transient pause */ |
| 819 | /*package*/ boolean mTemporaryPause = false; |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 820 | /** true if the activity is being destroyed in order to recreate it with a new configuration */ |
| 821 | /*package*/ boolean mChangingConfigurations = false; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 822 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 823 | /*package*/ int mConfigChangeFlags; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 824 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 825 | /*package*/ Configuration mCurrentConfig; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 826 | private SearchManager mSearchManager; |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 827 | private MenuInflater mMenuInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 829 | /** The autofill manager. Always access via {@link #getAutofillManager()}. */ |
| 830 | @Nullable private AutofillManager mAutofillManager; |
| 831 | |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 832 | /** The content capture manager. Always access via {@link #getContentCaptureManager()}. */ |
| 833 | @Nullable private ContentCaptureManager mContentCaptureManager; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 834 | |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 835 | private final ArrayList<Application.ActivityLifecycleCallbacks> mActivityLifecycleCallbacks = |
| 836 | new ArrayList<Application.ActivityLifecycleCallbacks>(); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 837 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 838 | static final class NonConfigurationInstances { |
| 839 | Object activity; |
| 840 | HashMap<String, Object> children; |
Adam Powell | 44ba79e | 2016-02-04 16:20:37 -0800 | [diff] [blame] | 841 | FragmentManagerNonConfig fragments; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 842 | ArrayMap<String, LoaderManager> loaders; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 843 | VoiceInteractor voiceInteractor; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 844 | } |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 845 | @UnsupportedAppUsage |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 846 | /* package */ NonConfigurationInstances mLastNonConfigurationInstances; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 847 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 848 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | private Window mWindow; |
| 850 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 851 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | private WindowManager mWindowManager; |
| 853 | /*package*/ View mDecor = null; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 854 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | /*package*/ boolean mWindowAdded = false; |
| 856 | /*package*/ boolean mVisibleFromServer = false; |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 857 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 858 | /*package*/ boolean mVisibleFromClient = true; |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 859 | /*package*/ ActionBar mActionBar = null; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 860 | private boolean mEnableDefaultActionBarUp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 862 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 863 | private VoiceInteractor mVoiceInteractor; |
| 864 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 865 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 866 | private CharSequence mTitle; |
| 867 | private int mTitleColor = 0; |
| 868 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 869 | // we must have a handler before the FragmentController is constructed |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 870 | @UnsupportedAppUsage |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 871 | final Handler mHandler = new Handler(); |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 872 | @UnsupportedAppUsage |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 873 | final FragmentController mFragments = FragmentController.createController(new HostCallbacks()); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 874 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 875 | private static final class ManagedCursor { |
| 876 | ManagedCursor(Cursor cursor) { |
| 877 | mCursor = cursor; |
| 878 | mReleased = false; |
| 879 | mUpdated = false; |
| 880 | } |
| 881 | |
| 882 | private final Cursor mCursor; |
| 883 | private boolean mReleased; |
| 884 | private boolean mUpdated; |
| 885 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 887 | @GuardedBy("mManagedCursors") |
| 888 | private final ArrayList<ManagedCursor> mManagedCursors = new ArrayList<>(); |
| 889 | |
| 890 | @GuardedBy("this") |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 891 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 892 | int mResultCode = RESULT_CANCELED; |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 893 | @GuardedBy("this") |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 894 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 895 | Intent mResultData = null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 896 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 897 | private TranslucentConversionListener mTranslucentCallback; |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 898 | private boolean mChangeCanvasToTranslucent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 899 | |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 900 | private SearchEvent mSearchEvent; |
| 901 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | private boolean mTitleReady = false; |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 903 | private int mActionModeTypeStarting = ActionMode.TYPE_PRIMARY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 904 | |
| 905 | private int mDefaultKeyMode = DEFAULT_KEYS_DISABLE; |
| 906 | private SpannableStringBuilder mDefaultKeySsb = null; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 907 | |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 908 | private ActivityManager.TaskDescription mTaskDescription = |
| 909 | new ActivityManager.TaskDescription(); |
| 910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 911 | protected static final int[] FOCUSED_STATE_SET = {com.android.internal.R.attr.state_focused}; |
| 912 | |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 913 | @SuppressWarnings("unused") |
Jeff Brown | 7e44283 | 2011-06-10 18:00:16 -0700 | [diff] [blame] | 914 | private final Object mInstanceTracker = StrictMode.trackActivity(this); |
| 915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | private Thread mUiThread; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 917 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 918 | @UnsupportedAppUsage |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 919 | ActivityTransitionState mActivityTransitionState = new ActivityTransitionState(); |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 920 | SharedElementCallback mEnterTransitionListener = SharedElementCallback.NULL_CALLBACK; |
| 921 | SharedElementCallback mExitTransitionListener = SharedElementCallback.NULL_CALLBACK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 922 | |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 923 | private boolean mHasCurrentPermissionsRequest; |
| 924 | |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 925 | private boolean mAutoFillResetNeeded; |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 926 | private boolean mAutoFillIgnoreFirstResumePause; |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 927 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 928 | /** The last autofill id that was returned from {@link #getNextAutofillId()} */ |
| 929 | private int mLastAutofillId = View.LAST_APP_AUTOFILL_ID; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 930 | |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 931 | private AutofillPopupWindow mAutofillPopupWindow; |
| 932 | |
chaviw | feb2e1e | 2018-12-19 17:24:11 -0800 | [diff] [blame] | 933 | /** @hide */ |
| 934 | boolean mEnterAnimationComplete; |
| 935 | |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 936 | private static native String getDlWarning(); |
| 937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 938 | /** Return the intent that started this activity. */ |
| 939 | public Intent getIntent() { |
| 940 | return mIntent; |
| 941 | } |
| 942 | |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 943 | /** |
| 944 | * Change the intent returned by {@link #getIntent}. This holds a |
| 945 | * reference to the given intent; it does not copy it. Often used in |
| 946 | * conjunction with {@link #onNewIntent}. |
| 947 | * |
| 948 | * @param newIntent The new Intent object to return from getIntent |
| 949 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | * @see #getIntent |
| 951 | * @see #onNewIntent |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 952 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | public void setIntent(Intent newIntent) { |
| 954 | mIntent = newIntent; |
| 955 | } |
| 956 | |
| 957 | /** Return the application that owns this activity. */ |
| 958 | public final Application getApplication() { |
| 959 | return mApplication; |
| 960 | } |
| 961 | |
| 962 | /** Is this activity embedded inside of another activity? */ |
| 963 | public final boolean isChild() { |
| 964 | return mParent != null; |
| 965 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 966 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | /** Return the parent activity if this view is an embedded child. */ |
| 968 | public final Activity getParent() { |
| 969 | return mParent; |
| 970 | } |
| 971 | |
| 972 | /** Retrieve the window manager for showing custom windows. */ |
| 973 | public WindowManager getWindowManager() { |
| 974 | return mWindowManager; |
| 975 | } |
| 976 | |
| 977 | /** |
| 978 | * Retrieve the current {@link android.view.Window} for the activity. |
| 979 | * This can be used to directly access parts of the Window API that |
| 980 | * are not available through Activity/Screen. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 981 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 982 | * @return Window The current window, or null if the activity is not |
| 983 | * visual. |
| 984 | */ |
| 985 | public Window getWindow() { |
| 986 | return mWindow; |
| 987 | } |
| 988 | |
| 989 | /** |
Mark Doliner | 9525f2a | 2014-01-02 11:17:47 -0800 | [diff] [blame] | 990 | * Return the LoaderManager for this activity, creating it if needed. |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 991 | * |
| 992 | * @deprecated Use {@link android.support.v4.app.FragmentActivity#getSupportLoaderManager()} |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 993 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 994 | @Deprecated |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 995 | public LoaderManager getLoaderManager() { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 996 | return mFragments.getLoaderManager(); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 997 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 998 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 999 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1000 | * Calls {@link android.view.Window#getCurrentFocus} on the |
| 1001 | * Window of this Activity to return the currently focused view. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1002 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | * @return View The current View with focus or null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1004 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | * @see #getWindow |
| 1006 | * @see android.view.Window#getCurrentFocus |
| 1007 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1008 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | public View getCurrentFocus() { |
| 1010 | return mWindow != null ? mWindow.getCurrentFocus() : null; |
| 1011 | } |
| 1012 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1013 | /** |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1014 | * (Creates, sets and) returns the autofill manager |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1015 | * |
| 1016 | * @return The autofill manager |
| 1017 | */ |
| 1018 | @NonNull private AutofillManager getAutofillManager() { |
| 1019 | if (mAutofillManager == null) { |
| 1020 | mAutofillManager = getSystemService(AutofillManager.class); |
| 1021 | } |
| 1022 | |
| 1023 | return mAutofillManager; |
| 1024 | } |
| 1025 | |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1026 | /** |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 1027 | * (Creates, sets, and ) returns the content capture manager |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1028 | * |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 1029 | * @return The content capture manager |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1030 | */ |
Adam He | b66babb | 2019-01-08 15:43:53 -0800 | [diff] [blame] | 1031 | @Nullable private ContentCaptureManager getContentCaptureManager() { |
| 1032 | // ContextCapture disabled for system apps |
Felipe Leme | 0c6b23d | 2019-01-15 17:02:49 -0800 | [diff] [blame] | 1033 | if (!UserHandle.isApp(myUid())) return null; |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 1034 | if (mContentCaptureManager == null) { |
| 1035 | mContentCaptureManager = getSystemService(ContentCaptureManager.class); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1036 | } |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 1037 | return mContentCaptureManager; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1038 | } |
| 1039 | |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 1040 | /** @hide */ private static final int CONTENT_CAPTURE_START = 1; |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 1041 | /** @hide */ private static final int CONTENT_CAPTURE_RESUME = 2; |
| 1042 | /** @hide */ private static final int CONTENT_CAPTURE_PAUSE = 3; |
| 1043 | /** @hide */ private static final int CONTENT_CAPTURE_STOP = 4; |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 1044 | |
| 1045 | /** @hide */ |
| 1046 | @IntDef(prefix = { "CONTENT_CAPTURE_" }, value = { |
| 1047 | CONTENT_CAPTURE_START, |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 1048 | CONTENT_CAPTURE_RESUME, |
| 1049 | CONTENT_CAPTURE_PAUSE, |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 1050 | CONTENT_CAPTURE_STOP |
| 1051 | }) |
| 1052 | @Retention(RetentionPolicy.SOURCE) |
| 1053 | @interface ContentCaptureNotificationType{} |
| 1054 | |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1055 | private String getContentCaptureTypeAsString(@ContentCaptureNotificationType int type) { |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 1056 | switch (type) { |
| 1057 | case CONTENT_CAPTURE_START: |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1058 | return "START"; |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 1059 | case CONTENT_CAPTURE_RESUME: |
| 1060 | return "RESUME"; |
| 1061 | case CONTENT_CAPTURE_PAUSE: |
| 1062 | return "PAUSE"; |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 1063 | case CONTENT_CAPTURE_STOP: |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1064 | return "STOP"; |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 1065 | default: |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1066 | return "UNKNOW-" + type; |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | private void notifyContentCaptureManagerIfNeeded(@ContentCaptureNotificationType int type) { |
| 1071 | if (Trace.isTagEnabled(Trace.TRACE_TAG_ACTIVITY_MANAGER)) { |
| 1072 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, |
| 1073 | "notifyContentCapture(" + getContentCaptureTypeAsString(type) + ") for " |
| 1074 | + mComponent.toShortString()); |
| 1075 | } |
| 1076 | try { |
| 1077 | final ContentCaptureManager cm = getContentCaptureManager(); |
| 1078 | if (cm == null) return; |
| 1079 | |
| 1080 | switch (type) { |
| 1081 | case CONTENT_CAPTURE_START: |
| 1082 | //TODO(b/111276913): decide whether the InteractionSessionId should be |
| 1083 | // saved / restored in the activity bundle - probably not |
| 1084 | int flags = 0; |
| 1085 | if ((getWindow().getAttributes().flags |
| 1086 | & WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 1087 | flags |= ContentCaptureContext.FLAG_DISABLED_BY_FLAG_SECURE; |
| 1088 | } |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 1089 | cm.onActivityCreated(mToken, getComponentName(), flags); |
| 1090 | break; |
| 1091 | case CONTENT_CAPTURE_RESUME: |
| 1092 | cm.onActivityResumed(); |
| 1093 | break; |
| 1094 | case CONTENT_CAPTURE_PAUSE: |
| 1095 | cm.onActivityPaused(); |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1096 | break; |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1097 | case CONTENT_CAPTURE_STOP: |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 1098 | cm.onActivityDestroyed(); |
Felipe Leme | b337e1c | 2019-01-18 13:06:17 -0800 | [diff] [blame] | 1099 | break; |
| 1100 | default: |
| 1101 | Log.wtf(TAG, "Invalid @ContentCaptureNotificationType: " + type); |
| 1102 | } |
| 1103 | } finally { |
| 1104 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | |
Felipe Leme | bb567ae | 2017-10-04 09:56:21 -0700 | [diff] [blame] | 1108 | @Override |
| 1109 | protected void attachBaseContext(Context newBase) { |
| 1110 | super.attachBaseContext(newBase); |
Felipe Leme | d247de8 | 2018-05-14 17:51:58 -0700 | [diff] [blame] | 1111 | if (newBase != null) { |
| 1112 | newBase.setAutofillClient(this); |
Felipe Leme | 326f15a | 2019-02-19 09:42:24 -0800 | [diff] [blame] | 1113 | newBase.setContentCaptureOptions(getContentCaptureOptions()); |
Felipe Leme | d247de8 | 2018-05-14 17:51:58 -0700 | [diff] [blame] | 1114 | } |
Felipe Leme | bb567ae | 2017-10-04 09:56:21 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | /** @hide */ |
| 1118 | @Override |
| 1119 | public final AutofillClient getAutofillClient() { |
| 1120 | return this; |
| 1121 | } |
| 1122 | |
Adam He | 6240eab | 2019-02-25 13:34:45 -0800 | [diff] [blame] | 1123 | /** @hide */ |
| 1124 | @Override |
| 1125 | public final ContentCaptureClient getContentCaptureClient() { |
| 1126 | return this; |
| 1127 | } |
| 1128 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1129 | /** |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 1130 | * Register an {@link Application.ActivityLifecycleCallbacks} instance that receives |
| 1131 | * lifecycle callbacks for only this Activity. |
| 1132 | * <p> |
| 1133 | * In relation to any |
| 1134 | * {@link Application#registerActivityLifecycleCallbacks Application registered callbacks}, |
| 1135 | * the callbacks registered here will always occur nested within those callbacks. This means: |
| 1136 | * <ul> |
| 1137 | * <li>Pre events will first be sent to Application registered callbacks, then to callbacks |
| 1138 | * registered here.</li> |
| 1139 | * <li>{@link Application.ActivityLifecycleCallbacks#onActivityCreated(Activity, Bundle)}, |
| 1140 | * {@link Application.ActivityLifecycleCallbacks#onActivityStarted(Activity)}, and |
| 1141 | * {@link Application.ActivityLifecycleCallbacks#onActivityResumed(Activity)} will |
| 1142 | * be sent first to Application registered callbacks, then to callbacks registered here. |
| 1143 | * For all other events, callbacks registered here will be sent first.</li> |
| 1144 | * <li>Post events will first be sent to callbacks registered here, then to |
| 1145 | * Application registered callbacks.</li> |
| 1146 | * </ul> |
| 1147 | * <p> |
| 1148 | * If multiple callbacks are registered here, they receive events in a first in (up through |
| 1149 | * {@link Application.ActivityLifecycleCallbacks#onActivityPostResumed}, last out |
| 1150 | * ordering. |
| 1151 | * <p> |
| 1152 | * It is strongly recommended to register this in the constructor of your Activity to ensure |
| 1153 | * you get all available callbacks. As this callback is associated with only this Activity, |
| 1154 | * it is not usually necessary to {@link #unregisterActivityLifecycleCallbacks unregister} it |
| 1155 | * unless you specifically do not want to receive further lifecycle callbacks. |
| 1156 | * |
| 1157 | * @param callback The callback instance to register |
| 1158 | */ |
| 1159 | public void registerActivityLifecycleCallbacks( |
| 1160 | @NonNull Application.ActivityLifecycleCallbacks callback) { |
| 1161 | synchronized (mActivityLifecycleCallbacks) { |
| 1162 | mActivityLifecycleCallbacks.add(callback); |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | /** |
| 1167 | * Unregister an {@link Application.ActivityLifecycleCallbacks} previously registered |
| 1168 | * with {@link #registerActivityLifecycleCallbacks}. It will not receive any further |
| 1169 | * callbacks. |
| 1170 | * |
| 1171 | * @param callback The callback instance to unregister |
| 1172 | * @see #registerActivityLifecycleCallbacks |
| 1173 | */ |
| 1174 | public void unregisterActivityLifecycleCallbacks( |
| 1175 | @NonNull Application.ActivityLifecycleCallbacks callback) { |
| 1176 | synchronized (mActivityLifecycleCallbacks) { |
| 1177 | mActivityLifecycleCallbacks.remove(callback); |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | private void dispatchActivityPreCreated(@Nullable Bundle savedInstanceState) { |
| 1182 | getApplication().dispatchActivityPreCreated(this, savedInstanceState); |
| 1183 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1184 | if (callbacks != null) { |
| 1185 | for (int i = 0; i < callbacks.length; i++) { |
| 1186 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPreCreated(this, |
| 1187 | savedInstanceState); |
| 1188 | } |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | private void dispatchActivityCreated(@Nullable Bundle savedInstanceState) { |
| 1193 | getApplication().dispatchActivityCreated(this, savedInstanceState); |
| 1194 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1195 | if (callbacks != null) { |
| 1196 | for (int i = 0; i < callbacks.length; i++) { |
| 1197 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityCreated(this, |
| 1198 | savedInstanceState); |
| 1199 | } |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | private void dispatchActivityPostCreated(@Nullable Bundle savedInstanceState) { |
| 1204 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1205 | if (callbacks != null) { |
| 1206 | for (int i = 0; i < callbacks.length; i++) { |
| 1207 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPostCreated(this, |
| 1208 | savedInstanceState); |
| 1209 | } |
| 1210 | } |
| 1211 | getApplication().dispatchActivityPostCreated(this, savedInstanceState); |
| 1212 | } |
| 1213 | |
| 1214 | private void dispatchActivityPreStarted() { |
| 1215 | getApplication().dispatchActivityPreStarted(this); |
| 1216 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1217 | if (callbacks != null) { |
| 1218 | for (int i = 0; i < callbacks.length; i++) { |
| 1219 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPreStarted(this); |
| 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | private void dispatchActivityStarted() { |
| 1225 | getApplication().dispatchActivityStarted(this); |
| 1226 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1227 | if (callbacks != null) { |
| 1228 | for (int i = 0; i < callbacks.length; i++) { |
| 1229 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityStarted(this); |
| 1230 | } |
| 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | private void dispatchActivityPostStarted() { |
| 1235 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1236 | if (callbacks != null) { |
| 1237 | for (int i = 0; i < callbacks.length; i++) { |
| 1238 | ((Application.ActivityLifecycleCallbacks) callbacks[i]) |
| 1239 | .onActivityPostStarted(this); |
| 1240 | } |
| 1241 | } |
| 1242 | getApplication().dispatchActivityPostStarted(this); |
| 1243 | } |
| 1244 | |
| 1245 | private void dispatchActivityPreResumed() { |
| 1246 | getApplication().dispatchActivityPreResumed(this); |
| 1247 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1248 | if (callbacks != null) { |
| 1249 | for (int i = 0; i < callbacks.length; i++) { |
| 1250 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPreResumed(this); |
| 1251 | } |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | private void dispatchActivityResumed() { |
| 1256 | getApplication().dispatchActivityResumed(this); |
| 1257 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1258 | if (callbacks != null) { |
| 1259 | for (int i = 0; i < callbacks.length; i++) { |
| 1260 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityResumed(this); |
| 1261 | } |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | private void dispatchActivityPostResumed() { |
| 1266 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1267 | if (callbacks != null) { |
| 1268 | for (int i = 0; i < callbacks.length; i++) { |
| 1269 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPostResumed(this); |
| 1270 | } |
| 1271 | } |
| 1272 | getApplication().dispatchActivityPostResumed(this); |
| 1273 | } |
| 1274 | |
| 1275 | private void dispatchActivityPrePaused() { |
| 1276 | getApplication().dispatchActivityPrePaused(this); |
| 1277 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1278 | if (callbacks != null) { |
| 1279 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1280 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPrePaused(this); |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | private void dispatchActivityPaused() { |
| 1286 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1287 | if (callbacks != null) { |
| 1288 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1289 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPaused(this); |
| 1290 | } |
| 1291 | } |
| 1292 | getApplication().dispatchActivityPaused(this); |
| 1293 | } |
| 1294 | |
| 1295 | private void dispatchActivityPostPaused() { |
| 1296 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1297 | if (callbacks != null) { |
| 1298 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1299 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPostPaused(this); |
| 1300 | } |
| 1301 | } |
| 1302 | getApplication().dispatchActivityPostPaused(this); |
| 1303 | } |
| 1304 | |
| 1305 | private void dispatchActivityPreStopped() { |
| 1306 | getApplication().dispatchActivityPreStopped(this); |
| 1307 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1308 | if (callbacks != null) { |
| 1309 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1310 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityPreStopped(this); |
| 1311 | } |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | private void dispatchActivityStopped() { |
| 1316 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1317 | if (callbacks != null) { |
| 1318 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1319 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityStopped(this); |
| 1320 | } |
| 1321 | } |
| 1322 | getApplication().dispatchActivityStopped(this); |
| 1323 | } |
| 1324 | |
| 1325 | private void dispatchActivityPostStopped() { |
| 1326 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1327 | if (callbacks != null) { |
| 1328 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1329 | ((Application.ActivityLifecycleCallbacks) callbacks[i]) |
| 1330 | .onActivityPostStopped(this); |
| 1331 | } |
| 1332 | } |
| 1333 | getApplication().dispatchActivityPostStopped(this); |
| 1334 | } |
| 1335 | |
| 1336 | private void dispatchActivityPreSaveInstanceState(@NonNull Bundle outState) { |
| 1337 | getApplication().dispatchActivityPreSaveInstanceState(this, outState); |
| 1338 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1339 | if (callbacks != null) { |
| 1340 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1341 | ((Application.ActivityLifecycleCallbacks) callbacks[i]) |
| 1342 | .onActivityPreSaveInstanceState(this, outState); |
| 1343 | } |
| 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | private void dispatchActivitySaveInstanceState(@NonNull Bundle outState) { |
| 1348 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1349 | if (callbacks != null) { |
| 1350 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1351 | ((Application.ActivityLifecycleCallbacks) callbacks[i]) |
| 1352 | .onActivitySaveInstanceState(this, outState); |
| 1353 | } |
| 1354 | } |
| 1355 | getApplication().dispatchActivitySaveInstanceState(this, outState); |
| 1356 | } |
| 1357 | |
| 1358 | private void dispatchActivityPostSaveInstanceState(@NonNull Bundle outState) { |
| 1359 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1360 | if (callbacks != null) { |
| 1361 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1362 | ((Application.ActivityLifecycleCallbacks) callbacks[i]) |
| 1363 | .onActivityPostSaveInstanceState(this, outState); |
| 1364 | } |
| 1365 | } |
| 1366 | getApplication().dispatchActivityPostSaveInstanceState(this, outState); |
| 1367 | } |
| 1368 | |
| 1369 | private void dispatchActivityPreDestroyed() { |
| 1370 | getApplication().dispatchActivityPreDestroyed(this); |
| 1371 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1372 | if (callbacks != null) { |
| 1373 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1374 | ((Application.ActivityLifecycleCallbacks) callbacks[i]) |
| 1375 | .onActivityPreDestroyed(this); |
| 1376 | } |
| 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | private void dispatchActivityDestroyed() { |
| 1381 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1382 | if (callbacks != null) { |
| 1383 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1384 | ((Application.ActivityLifecycleCallbacks) callbacks[i]).onActivityDestroyed(this); |
| 1385 | } |
| 1386 | } |
| 1387 | getApplication().dispatchActivityDestroyed(this); |
| 1388 | } |
| 1389 | |
| 1390 | private void dispatchActivityPostDestroyed() { |
| 1391 | Object[] callbacks = collectActivityLifecycleCallbacks(); |
| 1392 | if (callbacks != null) { |
| 1393 | for (int i = callbacks.length - 1; i >= 0; i--) { |
| 1394 | ((Application.ActivityLifecycleCallbacks) callbacks[i]) |
| 1395 | .onActivityPostDestroyed(this); |
| 1396 | } |
| 1397 | } |
| 1398 | getApplication().dispatchActivityPostDestroyed(this); |
| 1399 | } |
| 1400 | |
| 1401 | private Object[] collectActivityLifecycleCallbacks() { |
| 1402 | Object[] callbacks = null; |
| 1403 | synchronized (mActivityLifecycleCallbacks) { |
| 1404 | if (mActivityLifecycleCallbacks.size() > 0) { |
| 1405 | callbacks = mActivityLifecycleCallbacks.toArray(); |
| 1406 | } |
| 1407 | } |
| 1408 | return callbacks; |
| 1409 | } |
| 1410 | |
| 1411 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1412 | * Called when the activity is starting. This is where most initialization |
| 1413 | * should go: calling {@link #setContentView(int)} to inflate the |
| 1414 | * activity's UI, using {@link #findViewById} to programmatically interact |
| 1415 | * with widgets in the UI, calling |
| 1416 | * {@link #managedQuery(android.net.Uri , String[], String, String[], String)} to retrieve |
| 1417 | * cursors for data being displayed, etc. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1418 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1419 | * <p>You can call {@link #finish} from within this function, in |
Bryce Lee | 476edc8 | 2018-03-12 10:06:23 -0700 | [diff] [blame] | 1420 | * which case onDestroy() will be immediately called after {@link #onCreate} without any of the |
| 1421 | * rest of the activity lifecycle ({@link #onStart}, {@link #onResume}, {@link #onPause}, etc) |
| 1422 | * executing. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1423 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1424 | * <p><em>Derived classes must call through to the super class's |
| 1425 | * implementation of this method. If they do not, an exception will be |
| 1426 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1427 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1428 | * @param savedInstanceState If the activity is being re-initialized after |
| 1429 | * previously being shut down then this Bundle contains the data it most |
| 1430 | * 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] | 1431 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | * @see #onStart |
| 1433 | * @see #onSaveInstanceState |
| 1434 | * @see #onRestoreInstanceState |
| 1435 | * @see #onPostCreate |
| 1436 | */ |
Tor Norbye | 83c6896 | 2015-03-10 20:55:31 -0700 | [diff] [blame] | 1437 | @MainThread |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1438 | @CallSuper |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1439 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1440 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState); |
Bryce Lee | 3979159 | 2017-04-26 09:29:12 -0700 | [diff] [blame] | 1441 | |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 1442 | if (mLastNonConfigurationInstances != null) { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 1443 | mFragments.restoreLoaderNonConfig(mLastNonConfigurationInstances.loaders); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 1444 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 1445 | if (mActivityInfo.parentActivityName != null) { |
| 1446 | if (mActionBar == null) { |
| 1447 | mEnableDefaultActionBarUp = true; |
| 1448 | } else { |
| 1449 | mActionBar.setDefaultDisplayHomeAsUpEnabled(true); |
| 1450 | } |
| 1451 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1452 | if (savedInstanceState != null) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1453 | mAutoFillResetNeeded = savedInstanceState.getBoolean(AUTOFILL_RESET_NEEDED, false); |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 1454 | mLastAutofillId = savedInstanceState.getInt(LAST_AUTOFILL_ID, |
| 1455 | View.LAST_APP_AUTOFILL_ID); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1456 | |
| 1457 | if (mAutoFillResetNeeded) { |
| 1458 | getAutofillManager().onCreate(savedInstanceState); |
| 1459 | } |
| 1460 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1461 | Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG); |
| 1462 | mFragments.restoreAllState(p, mLastNonConfigurationInstances != null |
| 1463 | ? mLastNonConfigurationInstances.fragments : null); |
| 1464 | } |
| 1465 | mFragments.dispatchCreate(); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 1466 | dispatchActivityCreated(savedInstanceState); |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 1467 | if (mVoiceInteractor != null) { |
| 1468 | mVoiceInteractor.attachActivity(this); |
| 1469 | } |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 1470 | mRestoredFromBundle = savedInstanceState != null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1471 | mCalled = true; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1472 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1476 | * 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] | 1477 | * the attribute {@link android.R.attr#persistableMode} set to |
| 1478 | * <code>persistAcrossReboots</code>. |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1479 | * |
| 1480 | * @param savedInstanceState if the activity is being re-initialized after |
| 1481 | * previously being shut down then this Bundle contains the data it most |
| 1482 | * recently supplied in {@link #onSaveInstanceState}. |
| 1483 | * <b><i>Note: Otherwise it is null.</i></b> |
| 1484 | * @param persistentState if the activity is being re-initialized after |
| 1485 | * previously being shut down or powered off then this Bundle contains the data it most |
| 1486 | * recently supplied to outPersistentState in {@link #onSaveInstanceState}. |
| 1487 | * <b><i>Note: Otherwise it is null.</i></b> |
| 1488 | * |
| 1489 | * @see #onCreate(android.os.Bundle) |
| 1490 | * @see #onStart |
| 1491 | * @see #onSaveInstanceState |
| 1492 | * @see #onRestoreInstanceState |
| 1493 | * @see #onPostCreate |
| 1494 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1495 | public void onCreate(@Nullable Bundle savedInstanceState, |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1496 | @Nullable PersistableBundle persistentState) { |
| 1497 | onCreate(savedInstanceState); |
| 1498 | } |
| 1499 | |
| 1500 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1501 | * The hook for {@link ActivityThread} to restore the state of this activity. |
| 1502 | * |
| 1503 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} and |
| 1504 | * {@link #restoreManagedDialogs(android.os.Bundle)}. |
| 1505 | * |
| 1506 | * @param savedInstanceState contains the saved state |
| 1507 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 1508 | final void performRestoreInstanceState(@NonNull Bundle savedInstanceState) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1509 | onRestoreInstanceState(savedInstanceState); |
| 1510 | restoreManagedDialogs(savedInstanceState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1514 | * The hook for {@link ActivityThread} to restore the state of this activity. |
| 1515 | * |
| 1516 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} and |
| 1517 | * {@link #restoreManagedDialogs(android.os.Bundle)}. |
| 1518 | * |
| 1519 | * @param savedInstanceState contains the saved state |
| 1520 | * @param persistentState contains the persistable saved state |
| 1521 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 1522 | final void performRestoreInstanceState(@Nullable Bundle savedInstanceState, |
| 1523 | @Nullable PersistableBundle persistentState) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1524 | onRestoreInstanceState(savedInstanceState, persistentState); |
| 1525 | if (savedInstanceState != null) { |
| 1526 | restoreManagedDialogs(savedInstanceState); |
| 1527 | } |
| 1528 | } |
| 1529 | |
| 1530 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1531 | * This method is called after {@link #onStart} when the activity is |
| 1532 | * being re-initialized from a previously saved state, given here in |
Mike LeBeau | 305de9d | 2010-03-11 09:21:08 -0800 | [diff] [blame] | 1533 | * <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] | 1534 | * to restore their state, but it is sometimes convenient to do it here |
| 1535 | * after all of the initialization has been done or to allow subclasses to |
| 1536 | * decide whether to use your default implementation. The default |
| 1537 | * implementation of this method performs a restore of any view state that |
| 1538 | * had previously been frozen by {@link #onSaveInstanceState}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1539 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1540 | * <p>This method is called between {@link #onStart} and |
| 1541 | * {@link #onPostCreate}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1542 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1543 | * @param savedInstanceState the data most recently supplied in {@link #onSaveInstanceState}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1544 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | * @see #onCreate |
| 1546 | * @see #onPostCreate |
| 1547 | * @see #onResume |
| 1548 | * @see #onSaveInstanceState |
| 1549 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 1550 | protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1551 | if (mWindow != null) { |
| 1552 | Bundle windowState = savedInstanceState.getBundle(WINDOW_HIERARCHY_TAG); |
| 1553 | if (windowState != null) { |
| 1554 | mWindow.restoreHierarchyState(windowState); |
| 1555 | } |
| 1556 | } |
| 1557 | } |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1558 | |
| 1559 | /** |
| 1560 | * 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] | 1561 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 1562 | * <code>persistAcrossReboots</code>. The {@link android.os.PersistableBundle} passed |
| 1563 | * came from the restored PersistableBundle first |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1564 | * saved in {@link #onSaveInstanceState(Bundle, PersistableBundle)}. |
| 1565 | * |
| 1566 | * <p>This method is called between {@link #onStart} and |
| 1567 | * {@link #onPostCreate}. |
| 1568 | * |
| 1569 | * <p>If this method is called {@link #onRestoreInstanceState(Bundle)} will not be called. |
| 1570 | * |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 1571 | * <p>At least one of {@code savedInstanceState} or {@code persistentState} will not be null. |
| 1572 | * |
| 1573 | * @param savedInstanceState the data most recently supplied in {@link #onSaveInstanceState} |
| 1574 | * or null. |
| 1575 | * @param persistentState the data most recently supplied in {@link #onSaveInstanceState} |
| 1576 | * or null. |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1577 | * |
| 1578 | * @see #onRestoreInstanceState(Bundle) |
| 1579 | * @see #onCreate |
| 1580 | * @see #onPostCreate |
| 1581 | * @see #onResume |
| 1582 | * @see #onSaveInstanceState |
| 1583 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 1584 | public void onRestoreInstanceState(@Nullable Bundle savedInstanceState, |
| 1585 | @Nullable PersistableBundle persistentState) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1586 | if (savedInstanceState != null) { |
| 1587 | onRestoreInstanceState(savedInstanceState); |
| 1588 | } |
| 1589 | } |
| 1590 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | /** |
| 1592 | * Restore the state of any saved managed dialogs. |
| 1593 | * |
| 1594 | * @param savedInstanceState The bundle to restore from. |
| 1595 | */ |
| 1596 | private void restoreManagedDialogs(Bundle savedInstanceState) { |
| 1597 | final Bundle b = savedInstanceState.getBundle(SAVED_DIALOGS_TAG); |
| 1598 | if (b == null) { |
| 1599 | return; |
| 1600 | } |
| 1601 | |
| 1602 | final int[] ids = b.getIntArray(SAVED_DIALOG_IDS_KEY); |
| 1603 | final int numDialogs = ids.length; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1604 | mManagedDialogs = new SparseArray<ManagedDialog>(numDialogs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1605 | for (int i = 0; i < numDialogs; i++) { |
| 1606 | final Integer dialogId = ids[i]; |
| 1607 | Bundle dialogState = b.getBundle(savedDialogKeyFor(dialogId)); |
| 1608 | if (dialogState != null) { |
Romain Guy | e35c235 | 2009-06-19 13:18:12 -0700 | [diff] [blame] | 1609 | // Calling onRestoreInstanceState() below will invoke dispatchOnCreate |
| 1610 | // so tell createDialog() not to do it, otherwise we get an exception |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1611 | final ManagedDialog md = new ManagedDialog(); |
| 1612 | md.mArgs = b.getBundle(savedDialogArgsKeyFor(dialogId)); |
| 1613 | md.mDialog = createDialog(dialogId, dialogState, md.mArgs); |
| 1614 | if (md.mDialog != null) { |
| 1615 | mManagedDialogs.put(dialogId, md); |
| 1616 | onPrepareDialog(dialogId, md.mDialog, md.mArgs); |
| 1617 | md.mDialog.onRestoreInstanceState(dialogState); |
| 1618 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1619 | } |
| 1620 | } |
| 1621 | } |
| 1622 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1623 | private Dialog createDialog(Integer dialogId, Bundle state, Bundle args) { |
| 1624 | final Dialog dialog = onCreateDialog(dialogId, args); |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1625 | if (dialog == null) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1626 | return null; |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1627 | } |
Romain Guy | 6de4aed | 2009-07-08 10:54:45 -0700 | [diff] [blame] | 1628 | dialog.dispatchOnCreate(state); |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1629 | return dialog; |
| 1630 | } |
| 1631 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1632 | private static String savedDialogKeyFor(int key) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1633 | return SAVED_DIALOG_KEY_PREFIX + key; |
| 1634 | } |
| 1635 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1636 | private static String savedDialogArgsKeyFor(int key) { |
| 1637 | return SAVED_DIALOG_ARGS_KEY_PREFIX + key; |
| 1638 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1639 | |
| 1640 | /** |
| 1641 | * Called when activity start-up is complete (after {@link #onStart} |
| 1642 | * and {@link #onRestoreInstanceState} have been called). Applications will |
| 1643 | * generally not implement this method; it is intended for system |
| 1644 | * classes to do final initialization after application code has run. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1645 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1646 | * <p><em>Derived classes must call through to the super class's |
| 1647 | * implementation of this method. If they do not, an exception will be |
| 1648 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1649 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1650 | * @param savedInstanceState If the activity is being re-initialized after |
| 1651 | * previously being shut down then this Bundle contains the data it most |
| 1652 | * recently supplied in {@link #onSaveInstanceState}. <b><i>Note: Otherwise it is null.</i></b> |
| 1653 | * @see #onCreate |
| 1654 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1655 | @CallSuper |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1656 | protected void onPostCreate(@Nullable Bundle savedInstanceState) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1657 | if (!isChild()) { |
| 1658 | mTitleReady = true; |
| 1659 | onTitleChanged(getTitle(), getTitleColor()); |
| 1660 | } |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 1661 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1662 | mCalled = true; |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 1663 | |
| 1664 | notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_START); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1668 | * 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] | 1669 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 1670 | * <code>persistAcrossReboots</code>. |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1671 | * |
| 1672 | * @param savedInstanceState The data most recently supplied in {@link #onSaveInstanceState} |
| 1673 | * @param persistentState The data caming from the PersistableBundle first |
| 1674 | * saved in {@link #onSaveInstanceState(Bundle, PersistableBundle)}. |
| 1675 | * |
| 1676 | * @see #onCreate |
| 1677 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1678 | public void onPostCreate(@Nullable Bundle savedInstanceState, |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1679 | @Nullable PersistableBundle persistentState) { |
| 1680 | onPostCreate(savedInstanceState); |
| 1681 | } |
| 1682 | |
| 1683 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1684 | * Called after {@link #onCreate} — or after {@link #onRestart} when |
| 1685 | * the activity had been stopped, but is now again being displayed to the |
John Spurlock | 8a985d2 | 2014-02-25 09:40:05 -0500 | [diff] [blame] | 1686 | * user. It will be followed by {@link #onResume}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1687 | * |
| 1688 | * <p><em>Derived classes must call through to the super class's |
| 1689 | * implementation of this method. If they do not, an exception will be |
| 1690 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1691 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1692 | * @see #onCreate |
| 1693 | * @see #onStop |
| 1694 | * @see #onResume |
| 1695 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1696 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1697 | protected void onStart() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1698 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onStart " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1699 | mCalled = true; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1700 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 1701 | mFragments.doLoaderStart(); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1702 | |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 1703 | dispatchActivityStarted(); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1704 | |
| 1705 | if (mAutoFillResetNeeded) { |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 1706 | getAutofillManager().onVisibleForAutofill(); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1707 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | /** |
| 1711 | * Called after {@link #onStop} when the current activity is being |
| 1712 | * re-displayed to the user (the user has navigated back to it). It will |
| 1713 | * be followed by {@link #onStart} and then {@link #onResume}. |
| 1714 | * |
| 1715 | * <p>For activities that are using raw {@link Cursor} objects (instead of |
| 1716 | * creating them through |
| 1717 | * {@link #managedQuery(android.net.Uri , String[], String, String[], String)}, |
| 1718 | * this is usually the place |
| 1719 | * where the cursor should be requeried (because you had deactivated it in |
| 1720 | * {@link #onStop}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1721 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1722 | * <p><em>Derived classes must call through to the super class's |
| 1723 | * implementation of this method. If they do not, an exception will be |
| 1724 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1725 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1726 | * @see #onStop |
| 1727 | * @see #onStart |
| 1728 | * @see #onResume |
| 1729 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1730 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1731 | protected void onRestart() { |
| 1732 | mCalled = true; |
| 1733 | } |
| 1734 | |
| 1735 | /** |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 1736 | * Called when an {@link #onResume} is coming up, prior to other pre-resume callbacks |
| 1737 | * such as {@link #onNewIntent} and {@link #onActivityResult}. This is primarily intended |
| 1738 | * to give the activity a hint that its state is no longer saved -- it will generally |
| 1739 | * be called after {@link #onSaveInstanceState} and prior to the activity being |
| 1740 | * resumed/started again. |
Sergey Vasilinets | 0de0eca | 2018-08-23 19:28:57 -0700 | [diff] [blame] | 1741 | * |
| 1742 | * @deprecated starting with {@link android.os.Build.VERSION_CODES#P} onSaveInstanceState is |
| 1743 | * called after {@link #onStop}, so this hint isn't accurate anymore: you should consider your |
| 1744 | * state not saved in between {@code onStart} and {@code onStop} callbacks inclusively. |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 1745 | */ |
Sergey Vasilinets | 0de0eca | 2018-08-23 19:28:57 -0700 | [diff] [blame] | 1746 | @Deprecated |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 1747 | public void onStateNotSaved() { |
| 1748 | } |
| 1749 | |
| 1750 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1751 | * Called after {@link #onRestoreInstanceState}, {@link #onRestart}, or |
| 1752 | * {@link #onPause}, for your activity to start interacting with the user. |
| 1753 | * This is a good place to begin animations, open exclusive-access devices |
| 1754 | * (such as the camera), etc. |
| 1755 | * |
| 1756 | * <p>Keep in mind that onResume is not the best indicator that your activity |
| 1757 | * is visible to the user; a system window such as the keyguard may be in |
| 1758 | * front. Use {@link #onWindowFocusChanged} to know for certain that your |
| 1759 | * activity is visible to the user (for example, to resume a game). |
| 1760 | * |
| 1761 | * <p><em>Derived classes must call through to the super class's |
| 1762 | * implementation of this method. If they do not, an exception will be |
| 1763 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1764 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1765 | * @see #onRestoreInstanceState |
| 1766 | * @see #onRestart |
| 1767 | * @see #onPostResume |
| 1768 | * @see #onPause |
| 1769 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1770 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1771 | protected void onResume() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1772 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onResume " + this); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 1773 | dispatchActivityResumed(); |
Sunny Goyal | 64643f6 | 2019-01-31 15:15:33 -0800 | [diff] [blame] | 1774 | mActivityTransitionState.onResume(this); |
Felipe Leme | ce40498 | 2018-09-17 09:46:13 -0700 | [diff] [blame] | 1775 | enableAutofillCompatibilityIfNeeded(); |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 1776 | if (mAutoFillResetNeeded) { |
| 1777 | if (!mAutoFillIgnoreFirstResumePause) { |
| 1778 | View focus = getCurrentFocus(); |
Ben Lin | e55cd3e | 2018-12-07 20:26:37 +0000 | [diff] [blame] | 1779 | if (focus != null && focus.canNotifyAutofillEnterExitEvent()) { |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 1780 | // TODO: in Activity killed/recreated case, i.e. SessionLifecycleTest# |
| 1781 | // testDatasetVisibleWhileAutofilledAppIsLifecycled: the View's initial |
| 1782 | // window visibility after recreation is INVISIBLE in onResume() and next frame |
| 1783 | // ViewRootImpl.performTraversals() changes window visibility to VISIBLE. |
| 1784 | // So we cannot call View.notifyEnterOrExited() which will do nothing |
| 1785 | // when View.isVisibleToUser() is false. |
| 1786 | getAutofillManager().notifyViewEntered(focus); |
| 1787 | } |
| 1788 | } |
| 1789 | } |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 1790 | |
| 1791 | notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_RESUME); |
| 1792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1793 | mCalled = true; |
| 1794 | } |
| 1795 | |
| 1796 | /** |
| 1797 | * Called when activity resume is complete (after {@link #onResume} has |
| 1798 | * been called). Applications will generally not implement this method; |
| 1799 | * it is intended for system classes to do final setup after application |
| 1800 | * resume code has run. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1801 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1802 | * <p><em>Derived classes must call through to the super class's |
| 1803 | * implementation of this method. If they do not, an exception will be |
| 1804 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1805 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1806 | * @see #onResume |
| 1807 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1808 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1809 | protected void onPostResume() { |
| 1810 | final Window win = getWindow(); |
| 1811 | if (win != null) win.makeActive(); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 1812 | if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1813 | mCalled = true; |
| 1814 | } |
| 1815 | |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 1816 | /** |
| 1817 | * Called when activity gets or looses the top resumed position in the system. |
| 1818 | * |
| 1819 | * <p>Starting with {@link android.os.Build.VERSION_CODES#Q} multiple activities can be resumed |
| 1820 | * at the same time in multi-window and multi-display modes. This callback should be used |
| 1821 | * instead of {@link #onResume()} as an indication that the activity can try to open |
| 1822 | * exclusive-access devices like camera.</p> |
| 1823 | * |
| 1824 | * <p>It will always be delivered after the activity was resumed and before it is paused. In |
| 1825 | * some cases it might be skipped and activity can go straight from {@link #onResume()} to |
| 1826 | * {@link #onPause()} without receiving the top resumed state.</p> |
| 1827 | * |
| 1828 | * @param isTopResumedActivity {@code true} if it's the topmost resumed activity in the system, |
| 1829 | * {@code false} otherwise. A call with this as {@code true} will |
| 1830 | * always be followed by another one with {@code false}. |
| 1831 | * |
| 1832 | * @see #onResume() |
| 1833 | * @see #onPause() |
| 1834 | * @see #onWindowFocusChanged(boolean) |
| 1835 | */ |
| 1836 | public void onTopResumedActivityChanged(boolean isTopResumedActivity) { |
| 1837 | } |
| 1838 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1839 | void setVoiceInteractor(IVoiceInteractor voiceInteractor) { |
Amith Yamasani | eeed06c | 2016-05-03 15:07:03 -0700 | [diff] [blame] | 1840 | if (mVoiceInteractor != null) { |
| 1841 | for (Request activeRequest: mVoiceInteractor.getActiveRequests()) { |
| 1842 | activeRequest.cancel(); |
| 1843 | activeRequest.clear(); |
| 1844 | } |
| 1845 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1846 | if (voiceInteractor == null) { |
| 1847 | mVoiceInteractor = null; |
| 1848 | } else { |
| 1849 | mVoiceInteractor = new VoiceInteractor(voiceInteractor, this, this, |
| 1850 | Looper.myLooper()); |
| 1851 | } |
| 1852 | } |
| 1853 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1854 | /** |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1855 | * Gets the next autofill ID. |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1856 | * |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1857 | * <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] | 1858 | * will be unique. |
| 1859 | * |
| 1860 | * @return A ID that is unique in the activity |
| 1861 | * |
| 1862 | * {@hide} |
| 1863 | */ |
Felipe Leme | 42b9793 | 2018-02-20 13:04:31 -0800 | [diff] [blame] | 1864 | @Override |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1865 | public int getNextAutofillId() { |
| 1866 | if (mLastAutofillId == Integer.MAX_VALUE - 1) { |
| 1867 | mLastAutofillId = View.LAST_APP_AUTOFILL_ID; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1870 | mLastAutofillId++; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1871 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1872 | return mLastAutofillId; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | /** |
Felipe Leme | 42b9793 | 2018-02-20 13:04:31 -0800 | [diff] [blame] | 1876 | * @hide |
| 1877 | */ |
| 1878 | @Override |
| 1879 | public AutofillId autofillClientGetNextAutofillId() { |
Felipe Leme | 305fd40 | 2018-09-11 18:20:42 +0000 | [diff] [blame] | 1880 | return new AutofillId(getNextAutofillId()); |
Felipe Leme | 42b9793 | 2018-02-20 13:04:31 -0800 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | /** |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1884 | * Check whether this activity is running as part of a voice interaction with the user. |
| 1885 | * If true, it should perform its interaction with the user through the |
| 1886 | * {@link VoiceInteractor} returned by {@link #getVoiceInteractor}. |
| 1887 | */ |
| 1888 | public boolean isVoiceInteraction() { |
| 1889 | return mVoiceInteractor != null; |
| 1890 | } |
| 1891 | |
| 1892 | /** |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 1893 | * Like {@link #isVoiceInteraction}, but only returns true if this is also the root |
| 1894 | * of a voice interaction. That is, returns true if this activity was directly |
| 1895 | * started by the voice interaction service as the initiation of a voice interaction. |
| 1896 | * Otherwise, for example if it was started by another activity while under voice |
| 1897 | * interaction, returns false. |
| 1898 | */ |
| 1899 | public boolean isVoiceInteractionRoot() { |
| 1900 | try { |
| 1901 | return mVoiceInteractor != null |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1902 | && ActivityTaskManager.getService().isRootVoiceInteraction(mToken); |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 1903 | } catch (RemoteException e) { |
| 1904 | } |
| 1905 | return false; |
| 1906 | } |
| 1907 | |
| 1908 | /** |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1909 | * Retrieve the active {@link VoiceInteractor} that the user is going through to |
| 1910 | * interact with this activity. |
| 1911 | */ |
| 1912 | public VoiceInteractor getVoiceInteractor() { |
| 1913 | return mVoiceInteractor; |
| 1914 | } |
| 1915 | |
| 1916 | /** |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1917 | * Queries whether the currently enabled voice interaction service supports returning |
| 1918 | * a voice interactor for use by the activity. This is valid only for the duration of the |
| 1919 | * activity. |
| 1920 | * |
| 1921 | * @return whether the current voice interaction service supports local voice interaction |
| 1922 | */ |
| 1923 | public boolean isLocalVoiceInteractionSupported() { |
| 1924 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1925 | return ActivityTaskManager.getService().supportsLocalVoiceInteraction(); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1926 | } catch (RemoteException re) { |
| 1927 | } |
| 1928 | return false; |
| 1929 | } |
| 1930 | |
| 1931 | /** |
| 1932 | * Starts a local voice interaction session. When ready, |
| 1933 | * {@link #onLocalVoiceInteractionStarted()} is called. You can pass a bundle of private options |
| 1934 | * to the registered voice interaction service. |
| 1935 | * @param privateOptions a Bundle of private arguments to the current voice interaction service |
| 1936 | */ |
| 1937 | public void startLocalVoiceInteraction(Bundle privateOptions) { |
| 1938 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1939 | ActivityTaskManager.getService().startLocalVoiceInteraction(mToken, privateOptions); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1940 | } catch (RemoteException re) { |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | /** |
| 1945 | * Callback to indicate that {@link #startLocalVoiceInteraction(Bundle)} has resulted in a |
| 1946 | * voice interaction session being started. You can now retrieve a voice interactor using |
| 1947 | * {@link #getVoiceInteractor()}. |
| 1948 | */ |
| 1949 | public void onLocalVoiceInteractionStarted() { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | /** |
Amith Yamasani | d8d967e | 2016-04-08 09:57:01 -0700 | [diff] [blame] | 1953 | * Callback to indicate that the local voice interaction has stopped either |
| 1954 | * because it was requested through a call to {@link #stopLocalVoiceInteraction()} |
| 1955 | * or because it was canceled by the user. The previously acquired {@link VoiceInteractor} |
| 1956 | * is no longer valid after this. |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1957 | */ |
| 1958 | public void onLocalVoiceInteractionStopped() { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | /** |
| 1962 | * Request to terminate the current voice interaction that was previously started |
Amith Yamasani | d8d967e | 2016-04-08 09:57:01 -0700 | [diff] [blame] | 1963 | * using {@link #startLocalVoiceInteraction(Bundle)}. When the interaction is |
| 1964 | * terminated, {@link #onLocalVoiceInteractionStopped()} will be called. |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1965 | */ |
| 1966 | public void stopLocalVoiceInteraction() { |
| 1967 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1968 | ActivityTaskManager.getService().stopLocalVoiceInteraction(mToken); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1969 | } catch (RemoteException re) { |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1974 | * This is called for activities that set launchMode to "singleTop" in |
| 1975 | * their package, or if a client used the {@link Intent#FLAG_ACTIVITY_SINGLE_TOP} |
| 1976 | * flag when calling {@link #startActivity}. In either case, when the |
| 1977 | * activity is re-launched while at the top of the activity stack instead |
| 1978 | * of a new instance of the activity being started, onNewIntent() will be |
| 1979 | * called on the existing instance with the Intent that was used to |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1980 | * re-launch it. |
| 1981 | * |
| 1982 | * <p>An activity will always be paused before receiving a new intent, so |
| 1983 | * you can count on {@link #onResume} being called after this method. |
| 1984 | * |
| 1985 | * <p>Note that {@link #getIntent} still returns the original Intent. You |
| 1986 | * can use {@link #setIntent} to update it to this new Intent. |
| 1987 | * |
| 1988 | * @param intent The new intent that was started for the activity. |
| 1989 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1990 | * @see #getIntent |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1991 | * @see #setIntent |
| 1992 | * @see #onResume |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1993 | */ |
| 1994 | protected void onNewIntent(Intent intent) { |
| 1995 | } |
| 1996 | |
| 1997 | /** |
| 1998 | * The hook for {@link ActivityThread} to save the state of this activity. |
| 1999 | * |
| 2000 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} |
| 2001 | * and {@link #saveManagedDialogs(android.os.Bundle)}. |
| 2002 | * |
| 2003 | * @param outState The bundle to save the state to. |
| 2004 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 2005 | final void performSaveInstanceState(@NonNull Bundle outState) { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2006 | dispatchActivityPreSaveInstanceState(outState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2007 | onSaveInstanceState(outState); |
| 2008 | saveManagedDialogs(outState); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 2009 | mActivityTransitionState.saveState(outState); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 2010 | storeHasCurrentPermissionRequest(outState); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2011 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onSaveInstanceState " + this + ": " + outState); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2012 | dispatchActivityPostSaveInstanceState(outState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2016 | * The hook for {@link ActivityThread} to save the state of this activity. |
| 2017 | * |
| 2018 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} |
| 2019 | * and {@link #saveManagedDialogs(android.os.Bundle)}. |
| 2020 | * |
| 2021 | * @param outState The bundle to save the state to. |
| 2022 | * @param outPersistentState The bundle to save persistent state to. |
| 2023 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 2024 | final void performSaveInstanceState(@NonNull Bundle outState, |
| 2025 | @NonNull PersistableBundle outPersistentState) { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2026 | dispatchActivityPreSaveInstanceState(outState); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2027 | onSaveInstanceState(outState, outPersistentState); |
| 2028 | saveManagedDialogs(outState); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 2029 | storeHasCurrentPermissionRequest(outState); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2030 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onSaveInstanceState " + this + ": " + outState + |
| 2031 | ", " + outPersistentState); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2032 | dispatchActivityPostSaveInstanceState(outState); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2036 | * Called to retrieve per-instance state from an activity before being killed |
| 2037 | * so that the state can be restored in {@link #onCreate} or |
| 2038 | * {@link #onRestoreInstanceState} (the {@link Bundle} populated by this method |
| 2039 | * will be passed to both). |
| 2040 | * |
| 2041 | * <p>This method is called before an activity may be killed so that when it |
| 2042 | * comes back some time in the future it can restore its state. For example, |
| 2043 | * if activity B is launched in front of activity A, and at some point activity |
| 2044 | * A is killed to reclaim resources, activity A will have a chance to save the |
| 2045 | * current state of its user interface via this method so that when the user |
| 2046 | * returns to activity A, the state of the user interface can be restored |
| 2047 | * via {@link #onCreate} or {@link #onRestoreInstanceState}. |
| 2048 | * |
| 2049 | * <p>Do not confuse this method with activity lifecycle callbacks such as |
| 2050 | * {@link #onPause}, which is always called when an activity is being placed |
| 2051 | * in the background or on its way to destruction, or {@link #onStop} which |
| 2052 | * is called before destruction. One example of when {@link #onPause} and |
| 2053 | * {@link #onStop} is called and not this method is when a user navigates back |
| 2054 | * from activity B to activity A: there is no need to call {@link #onSaveInstanceState} |
| 2055 | * on B because that particular instance will never be restored, so the |
| 2056 | * system avoids calling it. An example when {@link #onPause} is called and |
| 2057 | * not {@link #onSaveInstanceState} is when activity B is launched in front of activity A: |
| 2058 | * the system may avoid calling {@link #onSaveInstanceState} on activity A if it isn't |
| 2059 | * killed during the lifetime of B since the state of the user interface of |
| 2060 | * A will stay intact. |
| 2061 | * |
| 2062 | * <p>The default implementation takes care of most of the UI per-instance |
| 2063 | * state for you by calling {@link android.view.View#onSaveInstanceState()} on each |
| 2064 | * view in the hierarchy that has an id, and by saving the id of the currently |
| 2065 | * focused view (all of which is restored by the default implementation of |
| 2066 | * {@link #onRestoreInstanceState}). If you override this method to save additional |
| 2067 | * information not captured by each individual view, you will likely want to |
| 2068 | * call through to the default implementation, otherwise be prepared to save |
| 2069 | * all of the state of each view yourself. |
| 2070 | * |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 2071 | * <p>If called, this method will occur after {@link #onStop} for applications |
| 2072 | * targeting platforms starting with {@link android.os.Build.VERSION_CODES#P}. |
| 2073 | * For applications targeting earlier platform versions this method will occur |
| 2074 | * before {@link #onStop} and there are no guarantees about whether it will |
| 2075 | * occur before or after {@link #onPause}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2076 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2077 | * @param outState Bundle in which to place your saved state. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2078 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2079 | * @see #onCreate |
| 2080 | * @see #onRestoreInstanceState |
| 2081 | * @see #onPause |
| 2082 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 2083 | protected void onSaveInstanceState(@NonNull Bundle outState) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2084 | outState.putBundle(WINDOW_HIERARCHY_TAG, mWindow.saveHierarchyState()); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 2085 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 2086 | outState.putInt(LAST_AUTOFILL_ID, mLastAutofillId); |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2087 | Parcelable p = mFragments.saveAllState(); |
| 2088 | if (p != null) { |
| 2089 | outState.putParcelable(FRAGMENTS_TAG, p); |
| 2090 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 2091 | if (mAutoFillResetNeeded) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 2092 | outState.putBoolean(AUTOFILL_RESET_NEEDED, true); |
| 2093 | getAutofillManager().onSaveInstanceState(outState); |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 2094 | } |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2095 | dispatchActivitySaveInstanceState(outState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2099 | * This is the same as {@link #onSaveInstanceState} but is called for activities |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 2100 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 2101 | * <code>persistAcrossReboots</code>. The {@link android.os.PersistableBundle} passed |
| 2102 | * in will be saved and presented in {@link #onCreate(Bundle, PersistableBundle)} |
| 2103 | * 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] | 2104 | * |
| 2105 | * @param outState Bundle in which to place your saved state. |
| 2106 | * @param outPersistentState State which will be saved across reboots. |
| 2107 | * |
| 2108 | * @see #onSaveInstanceState(Bundle) |
| 2109 | * @see #onCreate |
| 2110 | * @see #onRestoreInstanceState(Bundle, PersistableBundle) |
| 2111 | * @see #onPause |
| 2112 | */ |
Jake Wharton | 63f4d89 | 2018-07-10 12:27:59 -0400 | [diff] [blame] | 2113 | public void onSaveInstanceState(@NonNull Bundle outState, |
| 2114 | @NonNull PersistableBundle outPersistentState) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2115 | onSaveInstanceState(outState); |
| 2116 | } |
| 2117 | |
| 2118 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2119 | * Save the state of any managed dialogs. |
| 2120 | * |
| 2121 | * @param outState place to store the saved state. |
| 2122 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2123 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2124 | private void saveManagedDialogs(Bundle outState) { |
| 2125 | if (mManagedDialogs == null) { |
| 2126 | return; |
| 2127 | } |
| 2128 | |
| 2129 | final int numDialogs = mManagedDialogs.size(); |
| 2130 | if (numDialogs == 0) { |
| 2131 | return; |
| 2132 | } |
| 2133 | |
| 2134 | Bundle dialogState = new Bundle(); |
| 2135 | |
| 2136 | int[] ids = new int[mManagedDialogs.size()]; |
| 2137 | |
| 2138 | // save each dialog's bundle, gather the ids |
| 2139 | for (int i = 0; i < numDialogs; i++) { |
| 2140 | final int key = mManagedDialogs.keyAt(i); |
| 2141 | ids[i] = key; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2142 | final ManagedDialog md = mManagedDialogs.valueAt(i); |
| 2143 | dialogState.putBundle(savedDialogKeyFor(key), md.mDialog.onSaveInstanceState()); |
| 2144 | if (md.mArgs != null) { |
| 2145 | dialogState.putBundle(savedDialogArgsKeyFor(key), md.mArgs); |
| 2146 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | dialogState.putIntArray(SAVED_DIALOG_IDS_KEY, ids); |
| 2150 | outState.putBundle(SAVED_DIALOGS_TAG, dialogState); |
| 2151 | } |
| 2152 | |
| 2153 | |
| 2154 | /** |
| 2155 | * Called as part of the activity lifecycle when an activity is going into |
| 2156 | * the background, but has not (yet) been killed. The counterpart to |
| 2157 | * {@link #onResume}. |
| 2158 | * |
| 2159 | * <p>When activity B is launched in front of activity A, this callback will |
| 2160 | * be invoked on A. B will not be created until A's {@link #onPause} returns, |
| 2161 | * so be sure to not do anything lengthy here. |
| 2162 | * |
| 2163 | * <p>This callback is mostly used for saving any persistent state the |
| 2164 | * activity is editing, to present a "edit in place" model to the user and |
| 2165 | * making sure nothing is lost if there are not enough resources to start |
| 2166 | * the new activity without first killing this one. This is also a good |
| 2167 | * place to do things like stop animations and other things that consume a |
Pin Ting | 14a9310 | 2012-04-25 11:27:03 +0800 | [diff] [blame] | 2168 | * noticeable amount of CPU in order to make the switch to the next activity |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2169 | * as fast as possible, or to close resources that are exclusive access |
| 2170 | * such as the camera. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2171 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2172 | * <p>In situations where the system needs more memory it may kill paused |
| 2173 | * processes to reclaim resources. Because of this, you should be sure |
| 2174 | * that all of your state is saved by the time you return from |
| 2175 | * this function. In general {@link #onSaveInstanceState} is used to save |
| 2176 | * per-instance state in the activity and this method is used to store |
| 2177 | * global persistent data (in content providers, files, etc.) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2178 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2179 | * <p>After receiving this call you will usually receive a following call |
| 2180 | * to {@link #onStop} (after the next activity has been resumed and |
| 2181 | * displayed), however in some cases there will be a direct call back to |
| 2182 | * {@link #onResume} without going through the stopped state. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2183 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2184 | * <p><em>Derived classes must call through to the super class's |
| 2185 | * implementation of this method. If they do not, an exception will be |
| 2186 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2187 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2188 | * @see #onResume |
| 2189 | * @see #onSaveInstanceState |
| 2190 | * @see #onStop |
| 2191 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 2192 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2193 | protected void onPause() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2194 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onPause " + this); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2195 | dispatchActivityPaused(); |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 2196 | if (mAutoFillResetNeeded) { |
| 2197 | if (!mAutoFillIgnoreFirstResumePause) { |
| 2198 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "autofill notifyViewExited " + this); |
| 2199 | View focus = getCurrentFocus(); |
| 2200 | if (focus != null && focus.canNotifyAutofillEnterExitEvent()) { |
| 2201 | getAutofillManager().notifyViewExited(focus); |
| 2202 | } |
| 2203 | } else { |
| 2204 | // reset after first pause() |
| 2205 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "autofill got first pause " + this); |
| 2206 | mAutoFillIgnoreFirstResumePause = false; |
| 2207 | } |
| 2208 | } |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 2209 | |
| 2210 | notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_PAUSE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2211 | mCalled = true; |
| 2212 | } |
| 2213 | |
| 2214 | /** |
| 2215 | * Called as part of the activity lifecycle when an activity is about to go |
| 2216 | * into the background as the result of user choice. For example, when the |
| 2217 | * user presses the Home key, {@link #onUserLeaveHint} will be called, but |
| 2218 | * when an incoming phone call causes the in-call Activity to be automatically |
| 2219 | * brought to the foreground, {@link #onUserLeaveHint} will not be called on |
| 2220 | * the activity being interrupted. In cases when it is invoked, this method |
| 2221 | * is called right before the activity's {@link #onPause} callback. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2222 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2223 | * <p>This callback and {@link #onUserInteraction} are intended to help |
| 2224 | * activities manage status bar notifications intelligently; specifically, |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 2225 | * for helping activities determine the proper time to cancel a notification. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2226 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2227 | * @see #onUserInteraction() |
Louis Chang | c2e193a | 2019-01-09 15:33:57 +0800 | [diff] [blame] | 2228 | * @see android.content.Intent#FLAG_ACTIVITY_NO_USER_ACTION |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2229 | */ |
| 2230 | protected void onUserLeaveHint() { |
| 2231 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2233 | /** |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 2234 | * @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] | 2235 | */ |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 2236 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2237 | public boolean onCreateThumbnail(Bitmap outBitmap, Canvas canvas) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 2238 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | /** |
| 2242 | * Generate a new description for this activity. This method is called |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 2243 | * 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] | 2244 | * description of its current state to be displayed to the user. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2245 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2246 | * <p>The default implementation returns null, which will cause you to |
| 2247 | * inherit the description from the previous activity. If all activities |
| 2248 | * return null, generally the label of the top activity will be used as the |
| 2249 | * description. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2250 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2251 | * @return A description of what the user is doing. It should be short and |
| 2252 | * sweet (only a few words). |
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 #onSaveInstanceState |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 2255 | * @see #onStop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2256 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2257 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2258 | public CharSequence onCreateDescription() { |
| 2259 | return null; |
| 2260 | } |
| 2261 | |
| 2262 | /** |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2263 | * This is called when the user is requesting an assist, to build a full |
| 2264 | * {@link Intent#ACTION_ASSIST} Intent with all of the context of the current |
| 2265 | * application. You can override this method to place into the bundle anything |
| 2266 | * 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] | 2267 | * of the assist Intent. |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2268 | * |
| 2269 | * <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] | 2270 | * been registered with {@link Application#registerOnProvideAssistDataListener |
| 2271 | * Application.registerOnProvideAssistDataListener}. |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2272 | */ |
| 2273 | public void onProvideAssistData(Bundle data) { |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | /** |
| 2277 | * This is called when the user is requesting an assist, to provide references |
| 2278 | * to content related to the current activity. Before being called, the |
| 2279 | * {@code outContent} Intent is filled with the base Intent of the activity (the Intent |
| 2280 | * returned by {@link #getIntent()}). The Intent's extras are stripped of any types |
| 2281 | * that are not valid for {@link PersistableBundle} or non-framework Parcelables, and |
| 2282 | * the flags {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION} and |
| 2283 | * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION} are cleared from the Intent. |
| 2284 | * |
| 2285 | * <p>Custom implementation may adjust the content intent to better reflect the top-level |
| 2286 | * context of the activity, and fill in its ClipData with additional content of |
| 2287 | * interest that the user is currently viewing. For example, an image gallery application |
| 2288 | * that has launched in to an activity allowing the user to swipe through pictures should |
| 2289 | * modify the intent to reference the current image they are looking it; such an |
| 2290 | * application when showing a list of pictures should add a ClipData that has |
| 2291 | * references to all of the pictures currently visible on screen.</p> |
| 2292 | * |
| 2293 | * @param outContent The assist content to return. |
| 2294 | */ |
| 2295 | public void onProvideAssistContent(AssistContent outContent) { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2296 | } |
| 2297 | |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 2298 | /** |
Clara Bayarri | ab591ba | 2016-05-16 17:48:16 +0100 | [diff] [blame] | 2299 | * Request the Keyboard Shortcuts screen to show up. This will trigger |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 2300 | * {@link #onProvideKeyboardShortcuts} to retrieve the shortcuts for the foreground activity. |
| 2301 | */ |
Clara Bayarri | ac6f034 | 2016-05-16 14:15:14 +0100 | [diff] [blame] | 2302 | public final void requestShowKeyboardShortcuts() { |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 2303 | Intent intent = new Intent(Intent.ACTION_SHOW_KEYBOARD_SHORTCUTS); |
Andrei Stingaceanu | a3d2693 | 2016-07-15 11:12:20 +0100 | [diff] [blame] | 2304 | intent.setPackage(KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME); |
Nicholas Sauer | 28348ed74 | 2019-02-15 11:58:32 -0800 | [diff] [blame] | 2305 | sendBroadcastAsUser(intent, Process.myUserHandle()); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | /** |
| 2309 | * Dismiss the Keyboard Shortcuts screen. |
| 2310 | */ |
| 2311 | public final void dismissKeyboardShortcutsHelper() { |
| 2312 | Intent intent = new Intent(Intent.ACTION_DISMISS_KEYBOARD_SHORTCUTS); |
Andrei Stingaceanu | a3d2693 | 2016-07-15 11:12:20 +0100 | [diff] [blame] | 2313 | intent.setPackage(KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME); |
Nicholas Sauer | 28348ed74 | 2019-02-15 11:58:32 -0800 | [diff] [blame] | 2314 | sendBroadcastAsUser(intent, Process.myUserHandle()); |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 2315 | } |
| 2316 | |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 2317 | @Override |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 2318 | public void onProvideKeyboardShortcuts( |
| 2319 | List<KeyboardShortcutGroup> data, Menu menu, int deviceId) { |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 2320 | if (menu == null) { |
| 2321 | return; |
| 2322 | } |
| 2323 | KeyboardShortcutGroup group = null; |
| 2324 | int menuSize = menu.size(); |
| 2325 | for (int i = 0; i < menuSize; ++i) { |
| 2326 | final MenuItem item = menu.getItem(i); |
| 2327 | final CharSequence title = item.getTitle(); |
| 2328 | final char alphaShortcut = item.getAlphabeticShortcut(); |
Peeyush Agarwal | e631e32 | 2016-10-19 11:41:42 +0100 | [diff] [blame] | 2329 | final int alphaModifiers = item.getAlphabeticModifiers(); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 2330 | if (title != null && alphaShortcut != MIN_VALUE) { |
| 2331 | if (group == null) { |
Clara Bayarri | ada88b3 | 2016-02-02 18:08:01 +0000 | [diff] [blame] | 2332 | final int resource = mApplication.getApplicationInfo().labelRes; |
| 2333 | group = new KeyboardShortcutGroup(resource != 0 ? getString(resource) : null); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 2334 | } |
| 2335 | group.addItem(new KeyboardShortcutInfo( |
Peeyush Agarwal | e631e32 | 2016-10-19 11:41:42 +0100 | [diff] [blame] | 2336 | title, alphaShortcut, alphaModifiers)); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 2337 | } |
| 2338 | } |
| 2339 | if (group != null) { |
| 2340 | data.add(group); |
| 2341 | } |
| 2342 | } |
| 2343 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2344 | /** |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 2345 | * Ask to have the current assistant shown to the user. This only works if the calling |
| 2346 | * activity is the current foreground activity. It is the same as calling |
| 2347 | * {@link android.service.voice.VoiceInteractionService#showSession |
| 2348 | * VoiceInteractionService.showSession} and requesting all of the possible context. |
| 2349 | * The receiver will always see |
| 2350 | * {@link android.service.voice.VoiceInteractionSession#SHOW_SOURCE_APPLICATION} set. |
| 2351 | * @return Returns true if the assistant was successfully invoked, else false. For example |
| 2352 | * false will be returned if the caller is not the current top activity. |
| 2353 | */ |
| 2354 | public boolean showAssist(Bundle args) { |
| 2355 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2356 | return ActivityTaskManager.getService().showAssistFromActivity(mToken, args); |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 2357 | } catch (RemoteException e) { |
| 2358 | } |
| 2359 | return false; |
| 2360 | } |
| 2361 | |
| 2362 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2363 | * Called when you are no longer visible to the user. You will next |
| 2364 | * receive either {@link #onRestart}, {@link #onDestroy}, or nothing, |
| 2365 | * depending on later user activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2366 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2367 | * <p><em>Derived classes must call through to the super class's |
| 2368 | * implementation of this method. If they do not, an exception will be |
| 2369 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2370 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2371 | * @see #onRestart |
| 2372 | * @see #onResume |
| 2373 | * @see #onSaveInstanceState |
| 2374 | * @see #onDestroy |
| 2375 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 2376 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2377 | protected void onStop() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2378 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onStop " + this); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 2379 | if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(false); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 2380 | mActivityTransitionState.onStop(); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2381 | dispatchActivityStopped(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2382 | mTranslucentCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2383 | mCalled = true; |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 2384 | |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 2385 | if (mAutoFillResetNeeded) { |
| 2386 | getAutofillManager().onInvisibleForAutofill(); |
| 2387 | } |
| 2388 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 2389 | if (isFinishing()) { |
| 2390 | if (mAutoFillResetNeeded) { |
Felipe Leme | 5b32ebe | 2018-02-15 12:52:19 -0800 | [diff] [blame] | 2391 | getAutofillManager().onActivityFinishing(); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 2392 | } else if (mIntent != null |
| 2393 | && mIntent.hasExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN)) { |
| 2394 | // Activity was launched when user tapped a link in the Autofill Save UI - since |
| 2395 | // user launched another activity, the Save UI should not be restored when this |
| 2396 | // activity is finished. |
| 2397 | getAutofillManager().onPendingSaveUi(AutofillManager.PENDING_UI_OPERATION_CANCEL, |
| 2398 | mIntent.getIBinderExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN)); |
| 2399 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 2400 | } |
chaviw | feb2e1e | 2018-12-19 17:24:11 -0800 | [diff] [blame] | 2401 | mEnterAnimationComplete = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | /** |
| 2405 | * Perform any final cleanup before an activity is destroyed. This can |
| 2406 | * happen either because the activity is finishing (someone called |
kopriva | fdb0bff | 2018-09-29 15:22:41 -0700 | [diff] [blame] | 2407 | * {@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] | 2408 | * this instance of the activity to save space. You can distinguish |
| 2409 | * between these two scenarios with the {@link #isFinishing} method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2410 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2411 | * <p><em>Note: do not count on this method being called as a place for |
| 2412 | * saving data! For example, if an activity is editing data in a content |
| 2413 | * provider, those edits should be committed in either {@link #onPause} or |
| 2414 | * {@link #onSaveInstanceState}, not here.</em> This method is usually implemented to |
| 2415 | * free resources like threads that are associated with an activity, so |
| 2416 | * that a destroyed activity does not leave such things around while the |
| 2417 | * rest of its application is still running. There are situations where |
| 2418 | * the system will simply kill the activity's hosting process without |
| 2419 | * calling this method (or any others) in it, so it should not be used to |
| 2420 | * do things that are intended to remain around after the process goes |
| 2421 | * away. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2422 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2423 | * <p><em>Derived classes must call through to the super class's |
| 2424 | * implementation of this method. If they do not, an exception will be |
| 2425 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2426 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2427 | * @see #onPause |
| 2428 | * @see #onStop |
| 2429 | * @see #finish |
| 2430 | * @see #isFinishing |
| 2431 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 2432 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2433 | protected void onDestroy() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2434 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onDestroy " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2435 | mCalled = true; |
| 2436 | |
| 2437 | // dismiss any dialogs we are managing. |
| 2438 | if (mManagedDialogs != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2439 | final int numDialogs = mManagedDialogs.size(); |
| 2440 | for (int i = 0; i < numDialogs; i++) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2441 | final ManagedDialog md = mManagedDialogs.valueAt(i); |
| 2442 | if (md.mDialog.isShowing()) { |
| 2443 | md.mDialog.dismiss(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2444 | } |
| 2445 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2446 | mManagedDialogs = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2447 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2448 | |
| 2449 | // close any cursors we are managing. |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 2450 | synchronized (mManagedCursors) { |
| 2451 | int numCursors = mManagedCursors.size(); |
| 2452 | for (int i = 0; i < numCursors; i++) { |
| 2453 | ManagedCursor c = mManagedCursors.get(i); |
| 2454 | if (c != null) { |
| 2455 | c.mCursor.close(); |
| 2456 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2457 | } |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 2458 | mManagedCursors.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2459 | } |
Amith Yamasani | 4986044 | 2010-03-17 20:54:10 -0700 | [diff] [blame] | 2460 | |
| 2461 | // Close any open search dialog |
| 2462 | if (mSearchManager != null) { |
| 2463 | mSearchManager.stopSearch(); |
| 2464 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 2465 | |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 2466 | if (mActionBar != null) { |
| 2467 | mActionBar.onDestroy(); |
| 2468 | } |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 2469 | |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 2470 | dispatchActivityDestroyed(); |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 2471 | |
| 2472 | notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_STOP); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | /** |
Dianne Hackborn | ebc15ef | 2013-10-09 17:36:57 -0700 | [diff] [blame] | 2476 | * Report to the system that your app is now fully drawn, purely for diagnostic |
| 2477 | * purposes (calling it does not impact the visible behavior of the activity). |
| 2478 | * This is only used to help instrument application launch times, so that the |
| 2479 | * app can report when it is fully in a usable state; without this, the only thing |
| 2480 | * the system itself can determine is the point at which the activity's window |
| 2481 | * 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] | 2482 | * measurement, you should always call this method after first launch (when |
Dianne Hackborn | ebc15ef | 2013-10-09 17:36:57 -0700 | [diff] [blame] | 2483 | * {@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] | 2484 | * entirely drawn your UI and populated with all of the significant data. You |
| 2485 | * can safely call this method any time after first launch as well, in which case |
| 2486 | * it will simply be ignored. |
| 2487 | */ |
| 2488 | public void reportFullyDrawn() { |
| 2489 | if (mDoReportFullyDrawn) { |
| 2490 | mDoReportFullyDrawn = false; |
| 2491 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2492 | ActivityTaskManager.getService().reportActivityFullyDrawn( |
| 2493 | mToken, mRestoredFromBundle); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 2494 | } catch (RemoteException e) { |
| 2495 | } |
| 2496 | } |
| 2497 | } |
| 2498 | |
| 2499 | /** |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2500 | * 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] | 2501 | * visa-versa. This method provides the same configuration that will be sent in the following |
| 2502 | * {@link #onConfigurationChanged(Configuration)} call after the activity enters this mode. |
| 2503 | * |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2504 | * @see android.R.attr#resizeableActivity |
| 2505 | * |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2506 | * @param isInMultiWindowMode True if the activity is in multi-window mode. |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2507 | * @param newConfig The new configuration of the activity with the state |
| 2508 | * {@param isInMultiWindowMode}. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2509 | */ |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2510 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) { |
| 2511 | // Left deliberately empty. There should be no side effects if a direct |
| 2512 | // subclass of Activity does not call super. |
| 2513 | onMultiWindowModeChanged(isInMultiWindowMode); |
| 2514 | } |
| 2515 | |
| 2516 | /** |
| 2517 | * Called by the system when the activity changes from fullscreen mode to multi-window mode and |
| 2518 | * visa-versa. |
| 2519 | * |
| 2520 | * @see android.R.attr#resizeableActivity |
| 2521 | * |
| 2522 | * @param isInMultiWindowMode True if the activity is in multi-window mode. |
| 2523 | * |
| 2524 | * @deprecated Use {@link #onMultiWindowModeChanged(boolean, Configuration)} instead. |
| 2525 | */ |
| 2526 | @Deprecated |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2527 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 2528 | // Left deliberately empty. There should be no side effects if a direct |
| 2529 | // subclass of Activity does not call super. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | /** |
| 2533 | * Returns true if the activity is currently in multi-window mode. |
| 2534 | * @see android.R.attr#resizeableActivity |
| 2535 | * |
| 2536 | * @return True if the activity is in multi-window mode. |
| 2537 | */ |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2538 | public boolean isInMultiWindowMode() { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2539 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2540 | return ActivityTaskManager.getService().isInMultiWindowMode(mToken); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2541 | } catch (RemoteException e) { |
| 2542 | } |
| 2543 | return false; |
| 2544 | } |
| 2545 | |
| 2546 | /** |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2547 | * Called by the system when the activity changes to and from picture-in-picture mode. This |
| 2548 | * method provides the same configuration that will be sent in the following |
| 2549 | * {@link #onConfigurationChanged(Configuration)} call after the activity enters this mode. |
| 2550 | * |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2551 | * @see android.R.attr#supportsPictureInPicture |
| 2552 | * |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2553 | * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode. |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2554 | * @param newConfig The new configuration of the activity with the state |
| 2555 | * {@param isInPictureInPictureMode}. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2556 | */ |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2557 | public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, |
| 2558 | Configuration newConfig) { |
| 2559 | // Left deliberately empty. There should be no side effects if a direct |
| 2560 | // subclass of Activity does not call super. |
| 2561 | onPictureInPictureModeChanged(isInPictureInPictureMode); |
| 2562 | } |
| 2563 | |
| 2564 | /** |
| 2565 | * Called by the system when the activity changes to and from picture-in-picture mode. |
| 2566 | * |
| 2567 | * @see android.R.attr#supportsPictureInPicture |
| 2568 | * |
| 2569 | * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode. |
| 2570 | * |
| 2571 | * @deprecated Use {@link #onPictureInPictureModeChanged(boolean, Configuration)} instead. |
| 2572 | */ |
| 2573 | @Deprecated |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2574 | public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 2575 | // Left deliberately empty. There should be no side effects if a direct |
| 2576 | // subclass of Activity does not call super. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | /** |
| 2580 | * Returns true if the activity is currently in picture-in-picture mode. |
| 2581 | * @see android.R.attr#supportsPictureInPicture |
| 2582 | * |
| 2583 | * @return True if the activity is in picture-in-picture mode. |
| 2584 | */ |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2585 | public boolean isInPictureInPictureMode() { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2586 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2587 | return ActivityTaskManager.getService().isInPictureInPictureMode(mToken); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2588 | } catch (RemoteException e) { |
| 2589 | } |
| 2590 | return false; |
| 2591 | } |
| 2592 | |
| 2593 | /** |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2594 | * 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] | 2595 | * prior calls to {@link #setPictureInPictureParams(PictureInPictureParams)} will still apply |
| 2596 | * when entering picture-in-picture through this call. |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2597 | * |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2598 | * @see #enterPictureInPictureMode(PictureInPictureParams) |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 2599 | * @see android.R.attr#supportsPictureInPicture |
| 2600 | */ |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2601 | @Deprecated |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2602 | public void enterPictureInPictureMode() { |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2603 | enterPictureInPictureMode(new PictureInPictureParams.Builder().build()); |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 2604 | } |
| 2605 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2606 | /** @removed */ |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2607 | @Deprecated |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2608 | public boolean enterPictureInPictureMode(@NonNull PictureInPictureArgs args) { |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2609 | return enterPictureInPictureMode(PictureInPictureArgs.convert(args)); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | /** |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2613 | * Puts the activity in picture-in-picture mode if possible in the current system state. The |
| 2614 | * set parameters in {@param params} will be combined with the parameters from prior calls to |
| 2615 | * {@link #setPictureInPictureParams(PictureInPictureParams)}. |
| 2616 | * |
| 2617 | * The system may disallow entering picture-in-picture in various cases, including when the |
| 2618 | * activity is not visible, if the screen is locked or if the user has an activity pinned. |
| 2619 | * |
| 2620 | * @see android.R.attr#supportsPictureInPicture |
| 2621 | * @see PictureInPictureParams |
| 2622 | * |
| 2623 | * @param params non-null parameters to be combined with previously set parameters when entering |
| 2624 | * picture-in-picture. |
| 2625 | * |
Winson Chung | 80fa2d8 | 2018-01-25 13:58:20 -0800 | [diff] [blame] | 2626 | * @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] | 2627 | * already in picture-in-picture mode (see {@link #isInPictureInPictureMode()}). If the device |
Winson Chung | 80fa2d8 | 2018-01-25 13:58:20 -0800 | [diff] [blame] | 2628 | * does not support picture-in-picture, return false. |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2629 | */ |
| 2630 | public boolean enterPictureInPictureMode(@NonNull PictureInPictureParams params) { |
| 2631 | try { |
Winson Chung | 80fa2d8 | 2018-01-25 13:58:20 -0800 | [diff] [blame] | 2632 | if (!deviceSupportsPictureInPictureMode()) { |
| 2633 | return false; |
| 2634 | } |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2635 | if (params == null) { |
| 2636 | throw new IllegalArgumentException("Expected non-null picture-in-picture params"); |
| 2637 | } |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 2638 | if (!mCanEnterPictureInPicture) { |
| 2639 | throw new IllegalStateException("Activity must be resumed to enter" |
| 2640 | + " picture-in-picture"); |
| 2641 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2642 | return ActivityTaskManager.getService().enterPictureInPictureMode(mToken, params); |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2643 | } catch (RemoteException e) { |
| 2644 | return false; |
| 2645 | } |
| 2646 | } |
| 2647 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2648 | /** @removed */ |
| 2649 | @Deprecated |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2650 | public void setPictureInPictureArgs(@NonNull PictureInPictureArgs args) { |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2651 | setPictureInPictureParams(PictureInPictureArgs.convert(args)); |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | /** |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2655 | * Updates the properties of the picture-in-picture activity, or sets it to be used later when |
| 2656 | * {@link #enterPictureInPictureMode()} is called. |
| 2657 | * |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2658 | * @param params the new parameters for the picture-in-picture. |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2659 | */ |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2660 | public void setPictureInPictureParams(@NonNull PictureInPictureParams params) { |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2661 | try { |
Winson Chung | 80fa2d8 | 2018-01-25 13:58:20 -0800 | [diff] [blame] | 2662 | if (!deviceSupportsPictureInPictureMode()) { |
| 2663 | return; |
| 2664 | } |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2665 | if (params == null) { |
| 2666 | throw new IllegalArgumentException("Expected non-null picture-in-picture params"); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2667 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2668 | ActivityTaskManager.getService().setPictureInPictureParams(mToken, params); |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2669 | } catch (RemoteException e) { |
| 2670 | } |
| 2671 | } |
| 2672 | |
Winson Chung | 8802eac | 2017-04-17 14:21:44 -0700 | [diff] [blame] | 2673 | /** |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2674 | * Return the number of actions that will be displayed in the picture-in-picture UI when the |
| 2675 | * user interacts with the activity currently in picture-in-picture mode. This number may change |
| 2676 | * if the global configuration changes (ie. if the device is plugged into an external display), |
| 2677 | * but will always be larger than three. |
| 2678 | */ |
| 2679 | public int getMaxNumPictureInPictureActions() { |
| 2680 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2681 | return ActivityTaskManager.getService().getMaxNumPictureInPictureActions(mToken); |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2682 | } catch (RemoteException e) { |
| 2683 | return 0; |
| 2684 | } |
| 2685 | } |
| 2686 | |
Winson Chung | 80fa2d8 | 2018-01-25 13:58:20 -0800 | [diff] [blame] | 2687 | /** |
| 2688 | * @return Whether this device supports picture-in-picture. |
| 2689 | */ |
| 2690 | private boolean deviceSupportsPictureInPictureMode() { |
| 2691 | return getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE); |
| 2692 | } |
| 2693 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2694 | void dispatchMovedToDisplay(int displayId, Configuration config) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2695 | updateDisplay(displayId); |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2696 | onMovedToDisplay(displayId, config); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | /** |
| 2700 | * Called by the system when the activity is moved from one display to another without |
| 2701 | * recreation. This means that this activity is declared to handle all changes to configuration |
| 2702 | * 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] | 2703 | * again. |
| 2704 | * |
| 2705 | * <p>This call will be followed by {@link #onConfigurationChanged(Configuration)} if the |
| 2706 | * applied configuration actually changed. It is up to app developer to choose whether to handle |
| 2707 | * the change in this method or in the following {@link #onConfigurationChanged(Configuration)} |
| 2708 | * call. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2709 | * |
| 2710 | * <p>Use this callback to track changes to the displays if some activity functionality relies |
| 2711 | * on an association with some display properties. |
| 2712 | * |
| 2713 | * @param displayId The id of the display to which activity was moved. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2714 | * @param config Configuration of the activity resources on new display after move. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2715 | * |
| 2716 | * @see #onConfigurationChanged(Configuration) |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2717 | * @see View#onMovedToDisplay(int, Configuration) |
Andrii Kulian | cadacce | 2017-04-26 18:09:54 -0700 | [diff] [blame] | 2718 | * @hide |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2719 | */ |
Tiger Huang | fc21845 | 2018-09-27 00:38:50 +0800 | [diff] [blame] | 2720 | @TestApi |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2721 | public void onMovedToDisplay(int displayId, Configuration config) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2722 | } |
| 2723 | |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2724 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2725 | * Called by the system when the device configuration changes while your |
| 2726 | * activity is running. Note that this will <em>only</em> be called if |
| 2727 | * you have selected configurations you would like to handle with the |
| 2728 | * {@link android.R.attr#configChanges} attribute in your manifest. If |
| 2729 | * any configuration change occurs that is not selected to be reported |
| 2730 | * by that attribute, then instead of reporting it the system will stop |
| 2731 | * and restart the activity (to have it launched with the new |
| 2732 | * configuration). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2733 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2734 | * <p>At the time that this function has been called, your Resources |
| 2735 | * object will have been updated to return resource values matching the |
| 2736 | * new configuration. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2737 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | * @param newConfig The new device configuration. |
| 2739 | */ |
Ian Lake | 666a965 | 2018-09-12 15:13:19 -0700 | [diff] [blame] | 2740 | public void onConfigurationChanged(@NonNull Configuration newConfig) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2741 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onConfigurationChanged " + this + ": " + newConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2742 | mCalled = true; |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 2743 | |
Dianne Hackborn | 9d07180 | 2010-12-08 14:49:15 -0800 | [diff] [blame] | 2744 | mFragments.dispatchConfigurationChanged(newConfig); |
| 2745 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2746 | if (mWindow != null) { |
| 2747 | // Pass the configuration changed event to the window |
| 2748 | mWindow.onConfigurationChanged(newConfig); |
| 2749 | } |
Adam Powell | 45c0b19 | 2011-07-28 15:11:57 -0700 | [diff] [blame] | 2750 | |
| 2751 | if (mActionBar != null) { |
| 2752 | // Do this last; the action bar will need to access |
| 2753 | // view changes from above. |
| 2754 | mActionBar.onConfigurationChanged(newConfig); |
| 2755 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2756 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2758 | /** |
| 2759 | * If this activity is being destroyed because it can not handle a |
| 2760 | * configuration parameter being changed (and thus its |
| 2761 | * {@link #onConfigurationChanged(Configuration)} method is |
| 2762 | * <em>not</em> being called), then you can use this method to discover |
| 2763 | * the set of changes that have occurred while in the process of being |
| 2764 | * destroyed. Note that there is no guarantee that these will be |
| 2765 | * accurate (other changes could have happened at any time), so you should |
| 2766 | * only use this as an optimization hint. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2767 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2768 | * @return Returns a bit field of the configuration parameters that are |
| 2769 | * changing, as defined by the {@link android.content.res.Configuration} |
| 2770 | * class. |
| 2771 | */ |
| 2772 | public int getChangingConfigurations() { |
| 2773 | return mConfigChangeFlags; |
| 2774 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2775 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2776 | /** |
| 2777 | * Retrieve the non-configuration instance data that was previously |
| 2778 | * returned by {@link #onRetainNonConfigurationInstance()}. This will |
| 2779 | * be available from the initial {@link #onCreate} and |
| 2780 | * {@link #onStart} calls to the new instance, allowing you to extract |
| 2781 | * any useful dynamic state from the previous instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2782 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2783 | * <p>Note that the data you retrieve here should <em>only</em> be used |
| 2784 | * as an optimization for handling configuration changes. You should always |
| 2785 | * be able to handle getting a null pointer back, and an activity must |
| 2786 | * still be able to restore itself to its previous state (through the |
| 2787 | * normal {@link #onSaveInstanceState(Bundle)} mechanism) even if this |
| 2788 | * function returns null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2789 | * |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2790 | * <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] | 2791 | * {@link Fragment#setRetainInstance(boolean)} instead; this is also |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2792 | * available on older platforms through the Android support libraries. |
| 2793 | * |
| 2794 | * @return the object previously returned by {@link #onRetainNonConfigurationInstance()} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2795 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2796 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2797 | public Object getLastNonConfigurationInstance() { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2798 | return mLastNonConfigurationInstances != null |
| 2799 | ? mLastNonConfigurationInstances.activity : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2800 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2802 | /** |
| 2803 | * Called by the system, as part of destroying an |
| 2804 | * activity due to a configuration change, when it is known that a new |
| 2805 | * instance will immediately be created for the new configuration. You |
| 2806 | * can return any object you like here, including the activity instance |
| 2807 | * itself, which can later be retrieved by calling |
| 2808 | * {@link #getLastNonConfigurationInstance()} in the new activity |
| 2809 | * instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2810 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2811 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 2812 | * or later, consider instead using a {@link Fragment} with |
| 2813 | * {@link Fragment#setRetainInstance(boolean) |
| 2814 | * Fragment.setRetainInstance(boolean}.</em> |
| 2815 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2816 | * <p>This function is called purely as an optimization, and you must |
| 2817 | * not rely on it being called. When it is called, a number of guarantees |
| 2818 | * will be made to help optimize configuration switching: |
| 2819 | * <ul> |
| 2820 | * <li> The function will be called between {@link #onStop} and |
| 2821 | * {@link #onDestroy}. |
| 2822 | * <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] | 2823 | * created after this one's {@link #onDestroy()} is called. In particular, |
| 2824 | * <em>no</em> messages will be dispatched during this time (when the returned |
| 2825 | * 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] | 2826 | * <li> The object you return here will <em>always</em> be available from |
| 2827 | * the {@link #getLastNonConfigurationInstance()} method of the following |
| 2828 | * activity instance as described there. |
| 2829 | * </ul> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2830 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2831 | * <p>These guarantees are designed so that an activity can use this API |
| 2832 | * to propagate extensive state from the old to new activity instance, from |
| 2833 | * loaded bitmaps, to network connections, to evenly actively running |
| 2834 | * threads. Note that you should <em>not</em> propagate any data that |
| 2835 | * may change based on the configuration, including any data loaded from |
| 2836 | * resources such as strings, layouts, or drawables. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2837 | * |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 2838 | * <p>The guarantee of no message handling during the switch to the next |
| 2839 | * activity simplifies use with active objects. For example if your retained |
| 2840 | * state is an {@link android.os.AsyncTask} you are guaranteed that its |
| 2841 | * call back functions (like {@link android.os.AsyncTask#onPostExecute}) will |
| 2842 | * not be called from the call here until you execute the next instance's |
| 2843 | * {@link #onCreate(Bundle)}. (Note however that there is of course no such |
| 2844 | * guarantee for {@link android.os.AsyncTask#doInBackground} since that is |
| 2845 | * running in a separate thread.) |
| 2846 | * |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2847 | * <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] | 2848 | * {@link Fragment#setRetainInstance(boolean)} instead; this is also |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2849 | * available on older platforms through the Android support libraries. |
| 2850 | * |
| 2851 | * @return any Object holding the desired state to propagate to the |
| 2852 | * next activity instance |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | */ |
| 2854 | public Object onRetainNonConfigurationInstance() { |
| 2855 | return null; |
| 2856 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2857 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2858 | /** |
| 2859 | * Retrieve the non-configuration instance data that was previously |
| 2860 | * returned by {@link #onRetainNonConfigurationChildInstances()}. This will |
| 2861 | * be available from the initial {@link #onCreate} and |
| 2862 | * {@link #onStart} calls to the new instance, allowing you to extract |
| 2863 | * any useful dynamic state from the previous instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2864 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2865 | * <p>Note that the data you retrieve here should <em>only</em> be used |
| 2866 | * as an optimization for handling configuration changes. You should always |
| 2867 | * be able to handle getting a null pointer back, and an activity must |
| 2868 | * still be able to restore itself to its previous state (through the |
| 2869 | * normal {@link #onSaveInstanceState(Bundle)} mechanism) even if this |
| 2870 | * function returns null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2871 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2872 | * @return Returns the object previously returned by |
| 2873 | * {@link #onRetainNonConfigurationChildInstances()} |
| 2874 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2875 | @Nullable |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2876 | HashMap<String, Object> getLastNonConfigurationChildInstances() { |
| 2877 | return mLastNonConfigurationInstances != null |
| 2878 | ? mLastNonConfigurationInstances.children : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2879 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2880 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2881 | /** |
| 2882 | * This method is similar to {@link #onRetainNonConfigurationInstance()} except that |
| 2883 | * it should return either a mapping from child activity id strings to arbitrary objects, |
| 2884 | * or null. This method is intended to be used by Activity framework subclasses that control a |
| 2885 | * set of child activities, such as ActivityGroup. The same guarantees and restrictions apply |
| 2886 | * as for {@link #onRetainNonConfigurationInstance()}. The default implementation returns null. |
| 2887 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2888 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2889 | HashMap<String,Object> onRetainNonConfigurationChildInstances() { |
| 2890 | return null; |
| 2891 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2892 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2893 | NonConfigurationInstances retainNonConfigurationInstances() { |
| 2894 | Object activity = onRetainNonConfigurationInstance(); |
| 2895 | HashMap<String, Object> children = onRetainNonConfigurationChildInstances(); |
Adam Powell | 44ba79e | 2016-02-04 16:20:37 -0800 | [diff] [blame] | 2896 | FragmentManagerNonConfig fragments = mFragments.retainNestedNonConfig(); |
Adam Powell | cbade7f | 2016-04-15 11:14:37 -0700 | [diff] [blame] | 2897 | |
| 2898 | // We're already stopped but we've been asked to retain. |
| 2899 | // Our fragments are taken care of but we need to mark the loaders for retention. |
| 2900 | // In order to do this correctly we need to restart the loaders first before |
| 2901 | // handing them off to the next activity. |
| 2902 | mFragments.doLoaderStart(); |
| 2903 | mFragments.doLoaderStop(true); |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2904 | ArrayMap<String, LoaderManager> loaders = mFragments.retainLoaderNonConfig(); |
Adam Powell | cbade7f | 2016-04-15 11:14:37 -0700 | [diff] [blame] | 2905 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2906 | if (activity == null && children == null && fragments == null && loaders == null |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 2907 | && mVoiceInteractor == null) { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2908 | return null; |
| 2909 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2910 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2911 | NonConfigurationInstances nci = new NonConfigurationInstances(); |
| 2912 | nci.activity = activity; |
| 2913 | nci.children = children; |
| 2914 | nci.fragments = fragments; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2915 | nci.loaders = loaders; |
Dianne Hackborn | 57dd737 | 2015-07-27 18:11:14 -0700 | [diff] [blame] | 2916 | if (mVoiceInteractor != null) { |
| 2917 | mVoiceInteractor.retainInstance(); |
| 2918 | nci.voiceInteractor = mVoiceInteractor; |
| 2919 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2920 | return nci; |
| 2921 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 2922 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2923 | public void onLowMemory() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2924 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onLowMemory " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2925 | mCalled = true; |
Dianne Hackborn | 9d07180 | 2010-12-08 14:49:15 -0800 | [diff] [blame] | 2926 | mFragments.dispatchLowMemory(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2927 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 2928 | |
| 2929 | public void onTrimMemory(int level) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2930 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onTrimMemory " + this + ": " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 2931 | mCalled = true; |
| 2932 | mFragments.dispatchTrimMemory(level); |
| 2933 | } |
| 2934 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2935 | /** |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 2936 | * Return the FragmentManager for interacting with fragments associated |
| 2937 | * with this activity. |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 2938 | * |
| 2939 | * @deprecated Use {@link android.support.v4.app.FragmentActivity#getSupportFragmentManager()} |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 2940 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 2941 | @Deprecated |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 2942 | public FragmentManager getFragmentManager() { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2943 | return mFragments.getFragmentManager(); |
Dianne Hackborn | 9e14e9f3 | 2010-07-14 11:07:38 -0700 | [diff] [blame] | 2944 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2945 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 2946 | /** |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 2947 | * Called when a Fragment is being attached to this activity, immediately |
| 2948 | * after the call to its {@link Fragment#onAttach Fragment.onAttach()} |
| 2949 | * method and before {@link Fragment#onCreate Fragment.onCreate()}. |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 2950 | * |
| 2951 | * @deprecated Use {@link |
| 2952 | * android.support.v4.app.FragmentActivity#onAttachFragment(android.support.v4.app.Fragment)} |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 2953 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 2954 | @Deprecated |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 2955 | public void onAttachFragment(Fragment fragment) { |
| 2956 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2957 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 2958 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2959 | * Wrapper around |
| 2960 | * {@link ContentResolver#query(android.net.Uri , String[], String, String[], String)} |
| 2961 | * that gives the resulting {@link Cursor} to call |
| 2962 | * {@link #startManagingCursor} so that the activity will manage its |
| 2963 | * lifecycle for you. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2964 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2965 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 2966 | * or later, consider instead using {@link LoaderManager} instead, available |
| 2967 | * via {@link #getLoaderManager()}.</em> |
| 2968 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 2969 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on a cursor obtained using |
| 2970 | * this method, because the activity will do that for you at the appropriate time. However, if |
| 2971 | * you call {@link #stopManagingCursor} on a cursor from a managed query, the system <em>will |
| 2972 | * not</em> automatically close the cursor and, in that case, you must call |
| 2973 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2974 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | * @param uri The URI of the content provider to query. |
| 2976 | * @param projection List of columns to return. |
| 2977 | * @param selection SQL WHERE clause. |
| 2978 | * @param sortOrder SQL ORDER BY clause. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2979 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2980 | * @return The Cursor that was returned by query(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2981 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2982 | * @see ContentResolver#query(android.net.Uri , String[], String, String[], String) |
| 2983 | * @see #startManagingCursor |
| 2984 | * @hide |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2985 | * |
| 2986 | * @deprecated Use {@link CursorLoader} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2987 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2988 | @Deprecated |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2989 | @UnsupportedAppUsage |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2990 | public final Cursor managedQuery(Uri uri, String[] projection, String selection, |
| 2991 | String sortOrder) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2992 | Cursor c = getContentResolver().query(uri, projection, selection, null, sortOrder); |
| 2993 | if (c != null) { |
| 2994 | startManagingCursor(c); |
| 2995 | } |
| 2996 | return c; |
| 2997 | } |
| 2998 | |
| 2999 | /** |
| 3000 | * Wrapper around |
| 3001 | * {@link ContentResolver#query(android.net.Uri , String[], String, String[], String)} |
| 3002 | * that gives the resulting {@link Cursor} to call |
| 3003 | * {@link #startManagingCursor} so that the activity will manage its |
| 3004 | * lifecycle for you. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3005 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 3006 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 3007 | * or later, consider instead using {@link LoaderManager} instead, available |
| 3008 | * via {@link #getLoaderManager()}.</em> |
| 3009 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 3010 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on a cursor obtained using |
| 3011 | * this method, because the activity will do that for you at the appropriate time. However, if |
| 3012 | * you call {@link #stopManagingCursor} on a cursor from a managed query, the system <em>will |
| 3013 | * not</em> automatically close the cursor and, in that case, you must call |
| 3014 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3015 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3016 | * @param uri The URI of the content provider to query. |
| 3017 | * @param projection List of columns to return. |
| 3018 | * @param selection SQL WHERE clause. |
| 3019 | * @param selectionArgs The arguments to selection, if any ?s are pesent |
| 3020 | * @param sortOrder SQL ORDER BY clause. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3021 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3022 | * @return The Cursor that was returned by query(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3023 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3024 | * @see ContentResolver#query(android.net.Uri , String[], String, String[], String) |
| 3025 | * @see #startManagingCursor |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 3026 | * |
| 3027 | * @deprecated Use {@link CursorLoader} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3028 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 3029 | @Deprecated |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 3030 | public final Cursor managedQuery(Uri uri, String[] projection, String selection, |
| 3031 | String[] selectionArgs, String sortOrder) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3032 | Cursor c = getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder); |
| 3033 | if (c != null) { |
| 3034 | startManagingCursor(c); |
| 3035 | } |
| 3036 | return c; |
| 3037 | } |
| 3038 | |
| 3039 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3040 | * This method allows the activity to take care of managing the given |
| 3041 | * {@link Cursor}'s lifecycle for you based on the activity's lifecycle. |
| 3042 | * That is, when the activity is stopped it will automatically call |
| 3043 | * {@link Cursor#deactivate} on the given Cursor, and when it is later restarted |
| 3044 | * it will call {@link Cursor#requery} for you. When the activity is |
| 3045 | * destroyed, all managed Cursors will be closed automatically. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3046 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 3047 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 3048 | * or later, consider instead using {@link LoaderManager} instead, available |
| 3049 | * via {@link #getLoaderManager()}.</em> |
| 3050 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 3051 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on cursor obtained from |
| 3052 | * {@link #managedQuery}, because the activity will do that for you at the appropriate time. |
| 3053 | * However, if you call {@link #stopManagingCursor} on a cursor from a managed query, the system |
| 3054 | * <em>will not</em> automatically close the cursor and, in that case, you must call |
| 3055 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3056 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3057 | * @param c The Cursor to be managed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3058 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3059 | * @see #managedQuery(android.net.Uri , String[], String, String[], String) |
| 3060 | * @see #stopManagingCursor |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3061 | * |
| 3062 | * @deprecated Use the new {@link android.content.CursorLoader} class with |
| 3063 | * {@link LoaderManager} instead; this is also |
| 3064 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3065 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 3066 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3067 | public void startManagingCursor(Cursor c) { |
| 3068 | synchronized (mManagedCursors) { |
| 3069 | mManagedCursors.add(new ManagedCursor(c)); |
| 3070 | } |
| 3071 | } |
| 3072 | |
| 3073 | /** |
| 3074 | * Given a Cursor that was previously given to |
| 3075 | * {@link #startManagingCursor}, stop the activity's management of that |
| 3076 | * cursor. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3077 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 3078 | * <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] | 3079 | * 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] | 3080 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3081 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3082 | * @param c The Cursor that was being managed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3083 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3084 | * @see #startManagingCursor |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3085 | * |
| 3086 | * @deprecated Use the new {@link android.content.CursorLoader} class with |
| 3087 | * {@link LoaderManager} instead; this is also |
| 3088 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3089 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 3090 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3091 | public void stopManagingCursor(Cursor c) { |
| 3092 | synchronized (mManagedCursors) { |
| 3093 | final int N = mManagedCursors.size(); |
| 3094 | for (int i=0; i<N; i++) { |
| 3095 | ManagedCursor mc = mManagedCursors.get(i); |
| 3096 | if (mc.mCursor == c) { |
| 3097 | mManagedCursors.remove(i); |
| 3098 | break; |
| 3099 | } |
| 3100 | } |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | /** |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3105 | * @deprecated As of {@link android.os.Build.VERSION_CODES#GINGERBREAD} |
| 3106 | * this is a no-op. |
Dianne Hackborn | 4f3867e | 2010-12-14 22:09:51 -0800 | [diff] [blame] | 3107 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3108 | */ |
Dianne Hackborn | d3efa39 | 2010-09-01 17:34:12 -0700 | [diff] [blame] | 3109 | @Deprecated |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3110 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3111 | public void setPersistent(boolean isPersistent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | /** |
Alan Viverette | db7423c | 2017-03-31 13:13:58 -0400 | [diff] [blame] | 3115 | * Finds a view that was identified by the {@code android:id} XML attribute |
| 3116 | * that was processed in {@link #onCreate}. |
| 3117 | * <p> |
| 3118 | * <strong>Note:</strong> In most cases -- depending on compiler support -- |
| 3119 | * the resulting view is automatically cast to the target class type. If |
| 3120 | * the target class type is unconstrained, an explicit cast may be |
| 3121 | * necessary. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3122 | * |
Alan Viverette | db7423c | 2017-03-31 13:13:58 -0400 | [diff] [blame] | 3123 | * @param id the ID to search for |
| 3124 | * @return a view with given ID if found, or {@code null} otherwise |
| 3125 | * @see View#findViewById(int) |
Chris Craik | 6faa9e5 | 2018-01-11 10:46:10 -0800 | [diff] [blame] | 3126 | * @see Activity#requireViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3127 | */ |
Scott Kennedy | c051955 | 2015-02-11 15:33:10 -0800 | [diff] [blame] | 3128 | @Nullable |
Alan Viverette | db7423c | 2017-03-31 13:13:58 -0400 | [diff] [blame] | 3129 | public <T extends View> T findViewById(@IdRes int id) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3130 | return getWindow().findViewById(id); |
| 3131 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3132 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3133 | /** |
Chris Craik | 6faa9e5 | 2018-01-11 10:46:10 -0800 | [diff] [blame] | 3134 | * Finds a view that was identified by the {@code android:id} XML attribute that was processed |
| 3135 | * in {@link #onCreate}, or throws an IllegalArgumentException if the ID is invalid, or there is |
| 3136 | * no matching view in the hierarchy. |
| 3137 | * <p> |
| 3138 | * <strong>Note:</strong> In most cases -- depending on compiler support -- |
| 3139 | * the resulting view is automatically cast to the target class type. If |
| 3140 | * the target class type is unconstrained, an explicit cast may be |
| 3141 | * necessary. |
| 3142 | * |
| 3143 | * @param id the ID to search for |
| 3144 | * @return a view with given ID |
| 3145 | * @see View#requireViewById(int) |
| 3146 | * @see Activity#findViewById(int) |
| 3147 | */ |
| 3148 | @NonNull |
| 3149 | public final <T extends View> T requireViewById(@IdRes int id) { |
| 3150 | T view = findViewById(id); |
| 3151 | if (view == null) { |
| 3152 | throw new IllegalArgumentException("ID does not reference a View inside this Activity"); |
| 3153 | } |
| 3154 | return view; |
| 3155 | } |
| 3156 | |
| 3157 | /** |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3158 | * Retrieve a reference to this activity's ActionBar. |
Adam Powell | 42c0fe8 | 2010-08-10 16:36:56 -0700 | [diff] [blame] | 3159 | * |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3160 | * @return The Activity's ActionBar, or null if it does not have one. |
| 3161 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3162 | @Nullable |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3163 | public ActionBar getActionBar() { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3164 | initWindowDecorActionBar(); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3165 | return mActionBar; |
| 3166 | } |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3167 | |
| 3168 | /** |
| 3169 | * Set a {@link android.widget.Toolbar Toolbar} to act as the {@link ActionBar} for this |
| 3170 | * Activity window. |
| 3171 | * |
| 3172 | * <p>When set to a non-null value the {@link #getActionBar()} method will return |
| 3173 | * an {@link ActionBar} object that can be used to control the given toolbar as if it were |
| 3174 | * a traditional window decor action bar. The toolbar's menu will be populated with the |
| 3175 | * Activity's options menu and the navigation button will be wired through the standard |
| 3176 | * {@link android.R.id#home home} menu select action.</p> |
| 3177 | * |
| 3178 | * <p>In order to use a Toolbar within the Activity's window content the application |
| 3179 | * must not request the window feature {@link Window#FEATURE_ACTION_BAR FEATURE_ACTION_BAR}.</p> |
| 3180 | * |
Chris Banes | c7d6c32 | 2016-01-27 14:09:16 +0000 | [diff] [blame] | 3181 | * @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] | 3182 | */ |
Adam Powell | 3778014 | 2014-06-01 13:31:00 -0700 | [diff] [blame] | 3183 | public void setActionBar(@Nullable Toolbar toolbar) { |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 3184 | final ActionBar ab = getActionBar(); |
| 3185 | if (ab instanceof WindowDecorActionBar) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3186 | throw new IllegalStateException("This Activity already has an action bar supplied " + |
| 3187 | "by the window decor. Do not request Window.FEATURE_ACTION_BAR and set " + |
| 3188 | "android:windowActionBar to false in your theme to use a Toolbar instead."); |
| 3189 | } |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 3190 | |
| 3191 | // If we reach here then we're setting a new action bar |
| 3192 | // 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] | 3193 | mMenuInflater = null; |
| 3194 | |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 3195 | // If we have an action bar currently, destroy it |
| 3196 | if (ab != null) { |
| 3197 | ab.onDestroy(); |
| 3198 | } |
| 3199 | |
Chris Banes | c7d6c32 | 2016-01-27 14:09:16 +0000 | [diff] [blame] | 3200 | if (toolbar != null) { |
| 3201 | final ToolbarActionBar tbab = new ToolbarActionBar(toolbar, getTitle(), this); |
| 3202 | mActionBar = tbab; |
| 3203 | mWindow.setCallback(tbab.getWrappedWindowCallback()); |
| 3204 | } else { |
| 3205 | mActionBar = null; |
| 3206 | // Re-set the original window callback since we may have already set a Toolbar wrapper |
| 3207 | mWindow.setCallback(this); |
| 3208 | } |
| 3209 | |
| 3210 | invalidateOptionsMenu(); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3211 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3213 | /** |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3214 | * Creates a new ActionBar, locates the inflated ActionBarView, |
| 3215 | * initializes the ActionBar with the view, and sets mActionBar. |
| 3216 | */ |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3217 | private void initWindowDecorActionBar() { |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 3218 | Window window = getWindow(); |
Adam Powell | a593d98 | 2011-05-13 14:09:54 -0700 | [diff] [blame] | 3219 | |
| 3220 | // Initializing the window decor can change window feature flags. |
| 3221 | // Make sure that we have the correct set before performing the test below. |
| 3222 | window.getDecorView(); |
| 3223 | |
Adam Powell | 9b4c804 | 2010-08-10 15:36:44 -0700 | [diff] [blame] | 3224 | if (isChild() || !window.hasFeature(Window.FEATURE_ACTION_BAR) || mActionBar != null) { |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3225 | return; |
| 3226 | } |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 3227 | |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3228 | mActionBar = new WindowDecorActionBar(this); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3229 | mActionBar.setDefaultDisplayHomeAsUpEnabled(mEnableDefaultActionBarUp); |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 3230 | |
| 3231 | mWindow.setDefaultIcon(mActivityInfo.getIconResource()); |
| 3232 | mWindow.setDefaultLogo(mActivityInfo.getLogoResource()); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3233 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3234 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 3235 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | * Set the activity content from a layout resource. The resource will be |
| 3237 | * inflated, adding all top-level views to the activity. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 3238 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3239 | * @param layoutResID Resource ID to be inflated. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3240 | * |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 3241 | * @see #setContentView(android.view.View) |
| 3242 | * @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3243 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3244 | public void setContentView(@LayoutRes int layoutResID) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | getWindow().setContentView(layoutResID); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3246 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3247 | } |
| 3248 | |
| 3249 | /** |
| 3250 | * Set the activity content to an explicit view. This view is placed |
| 3251 | * 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] | 3252 | * view hierarchy. When calling this method, the layout parameters of the |
| 3253 | * specified view are ignored. Both the width and the height of the view are |
| 3254 | * set by default to {@link ViewGroup.LayoutParams#MATCH_PARENT}. To use |
| 3255 | * your own layout parameters, invoke |
| 3256 | * {@link #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)} |
| 3257 | * instead. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3258 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3259 | * @param view The desired content to display. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 3260 | * |
| 3261 | * @see #setContentView(int) |
| 3262 | * @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3263 | */ |
| 3264 | public void setContentView(View view) { |
| 3265 | getWindow().setContentView(view); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3266 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3267 | } |
| 3268 | |
| 3269 | /** |
| 3270 | * Set the activity content to an explicit view. This view is placed |
| 3271 | * 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] | 3272 | * view hierarchy. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3273 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3274 | * @param view The desired content to display. |
| 3275 | * @param params Layout parameters for the view. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 3276 | * |
| 3277 | * @see #setContentView(android.view.View) |
| 3278 | * @see #setContentView(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3279 | */ |
| 3280 | public void setContentView(View view, ViewGroup.LayoutParams params) { |
| 3281 | getWindow().setContentView(view, params); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3282 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3283 | } |
| 3284 | |
| 3285 | /** |
| 3286 | * Add an additional content view to the activity. Added after any existing |
| 3287 | * ones in the activity -- existing views are NOT removed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3288 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3289 | * @param view The desired content to display. |
| 3290 | * @param params Layout parameters for the view. |
| 3291 | */ |
| 3292 | public void addContentView(View view, ViewGroup.LayoutParams params) { |
| 3293 | getWindow().addContentView(view, params); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3294 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3295 | } |
| 3296 | |
| 3297 | /** |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3298 | * Retrieve the {@link TransitionManager} responsible for default transitions in this window. |
| 3299 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 3300 | * |
| 3301 | * <p>This method will return non-null after content has been initialized (e.g. by using |
| 3302 | * {@link #setContentView}) if {@link Window#FEATURE_CONTENT_TRANSITIONS} has been granted.</p> |
| 3303 | * |
| 3304 | * @return This window's content TransitionManager or null if none is set. |
| 3305 | */ |
| 3306 | public TransitionManager getContentTransitionManager() { |
| 3307 | return getWindow().getTransitionManager(); |
| 3308 | } |
| 3309 | |
| 3310 | /** |
| 3311 | * Set the {@link TransitionManager} to use for default transitions in this window. |
| 3312 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 3313 | * |
| 3314 | * @param tm The TransitionManager to use for scene changes. |
| 3315 | */ |
| 3316 | public void setContentTransitionManager(TransitionManager tm) { |
| 3317 | getWindow().setTransitionManager(tm); |
| 3318 | } |
| 3319 | |
| 3320 | /** |
| 3321 | * Retrieve the {@link Scene} representing this window's current content. |
| 3322 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 3323 | * |
| 3324 | * <p>This method will return null if the current content is not represented by a Scene.</p> |
| 3325 | * |
| 3326 | * @return Current Scene being shown or null |
| 3327 | */ |
| 3328 | public Scene getContentScene() { |
| 3329 | return getWindow().getContentScene(); |
| 3330 | } |
| 3331 | |
| 3332 | /** |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 3333 | * Sets whether this activity is finished when touched outside its window's |
| 3334 | * bounds. |
| 3335 | */ |
| 3336 | public void setFinishOnTouchOutside(boolean finish) { |
| 3337 | mWindow.setCloseOnTouchOutside(finish); |
| 3338 | } |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3339 | |
| 3340 | /** @hide */ |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 3341 | @IntDef(prefix = { "DEFAULT_KEYS_" }, value = { |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3342 | DEFAULT_KEYS_DISABLE, |
| 3343 | DEFAULT_KEYS_DIALER, |
| 3344 | DEFAULT_KEYS_SHORTCUT, |
| 3345 | DEFAULT_KEYS_SEARCH_LOCAL, |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 3346 | DEFAULT_KEYS_SEARCH_GLOBAL |
| 3347 | }) |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3348 | @Retention(RetentionPolicy.SOURCE) |
| 3349 | @interface DefaultKeyMode {} |
| 3350 | |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 3351 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3352 | * Use with {@link #setDefaultKeyMode} to turn off default handling of |
| 3353 | * keys. |
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 | * @see #setDefaultKeyMode |
| 3356 | */ |
| 3357 | static public final int DEFAULT_KEYS_DISABLE = 0; |
| 3358 | /** |
| 3359 | * Use with {@link #setDefaultKeyMode} to launch the dialer during default |
| 3360 | * key handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3361 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3362 | * @see #setDefaultKeyMode |
| 3363 | */ |
| 3364 | static public final int DEFAULT_KEYS_DIALER = 1; |
| 3365 | /** |
| 3366 | * Use with {@link #setDefaultKeyMode} to execute a menu shortcut in |
| 3367 | * default key handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3368 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | * <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] | 3370 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3371 | * @see #setDefaultKeyMode |
| 3372 | */ |
| 3373 | static public final int DEFAULT_KEYS_SHORTCUT = 2; |
| 3374 | /** |
| 3375 | * Use with {@link #setDefaultKeyMode} to specify that unhandled keystrokes |
| 3376 | * will start an application-defined search. (If the application or activity does not |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 3377 | * actually define a search, the keys will be ignored.) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3378 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3379 | * <p>See {@link android.app.SearchManager android.app.SearchManager} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3380 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3381 | * @see #setDefaultKeyMode |
| 3382 | */ |
| 3383 | static public final int DEFAULT_KEYS_SEARCH_LOCAL = 3; |
| 3384 | |
| 3385 | /** |
| 3386 | * Use with {@link #setDefaultKeyMode} to specify that unhandled keystrokes |
| 3387 | * will start a global search (typically web search, but some platforms may define alternate |
| 3388 | * methods for global search) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3389 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3390 | * <p>See {@link android.app.SearchManager android.app.SearchManager} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3391 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3392 | * @see #setDefaultKeyMode |
| 3393 | */ |
| 3394 | static public final int DEFAULT_KEYS_SEARCH_GLOBAL = 4; |
| 3395 | |
| 3396 | /** |
| 3397 | * Select the default key handling for this activity. This controls what |
| 3398 | * will happen to key events that are not otherwise handled. The default |
| 3399 | * mode ({@link #DEFAULT_KEYS_DISABLE}) will simply drop them on the |
| 3400 | * floor. Other modes allow you to launch the dialer |
| 3401 | * ({@link #DEFAULT_KEYS_DIALER}), execute a shortcut in your options |
| 3402 | * menu without requiring the menu key be held down |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3403 | * ({@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] | 3404 | * and {@link #DEFAULT_KEYS_SEARCH_GLOBAL}). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3405 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3406 | * <p>Note that the mode selected here does not impact the default |
| 3407 | * handling of system keys, such as the "back" and "menu" keys, and your |
| 3408 | * activity and its views always get a first chance to receive and handle |
| 3409 | * all application keys. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3410 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3411 | * @param mode The desired default key mode constant. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3412 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3413 | * @see #onKeyDown |
| 3414 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3415 | public final void setDefaultKeyMode(@DefaultKeyMode int mode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3416 | mDefaultKeyMode = mode; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3418 | // Some modes use a SpannableStringBuilder to track & dispatch input events |
| 3419 | // This list must remain in sync with the switch in onKeyDown() |
| 3420 | switch (mode) { |
| 3421 | case DEFAULT_KEYS_DISABLE: |
| 3422 | case DEFAULT_KEYS_SHORTCUT: |
| 3423 | mDefaultKeySsb = null; // not used in these modes |
| 3424 | break; |
| 3425 | case DEFAULT_KEYS_DIALER: |
| 3426 | case DEFAULT_KEYS_SEARCH_LOCAL: |
| 3427 | case DEFAULT_KEYS_SEARCH_GLOBAL: |
| 3428 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 3429 | Selection.setSelection(mDefaultKeySsb,0); |
| 3430 | break; |
| 3431 | default: |
| 3432 | throw new IllegalArgumentException(); |
| 3433 | } |
| 3434 | } |
| 3435 | |
| 3436 | /** |
| 3437 | * 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] | 3438 | * 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] | 3439 | * is inside a TextView will not trigger the event (unless it is a navigation |
| 3440 | * to another object) because TextView handles its own key presses. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3441 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3442 | * <p>If the focused view didn't want this event, this method is called. |
| 3443 | * |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3444 | * <p>The default implementation takes care of {@link KeyEvent#KEYCODE_BACK} |
| 3445 | * by calling {@link #onBackPressed()}, though the behavior varies based |
| 3446 | * on the application compatibility mode: for |
| 3447 | * {@link android.os.Build.VERSION_CODES#ECLAIR} or later applications, |
| 3448 | * it will set up the dispatch to call {@link #onKeyUp} where the action |
| 3449 | * will be performed; for earlier applications, it will perform the |
| 3450 | * action immediately in on-down, as those versions of the platform |
| 3451 | * behaved. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3452 | * |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3453 | * <p>Other additional default key handling may be performed |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3454 | * if configured with {@link #setDefaultKeyMode}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3455 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3456 | * @return Return <code>true</code> to prevent this event from being propagated |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3457 | * 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] | 3458 | * this event and it should continue to be propagated. |
| 3459 | * @see #onKeyUp |
| 3460 | * @see android.view.KeyEvent |
| 3461 | */ |
| 3462 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3463 | if (keyCode == KeyEvent.KEYCODE_BACK) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3464 | if (getApplicationInfo().targetSdkVersion |
| 3465 | >= Build.VERSION_CODES.ECLAIR) { |
| 3466 | event.startTracking(); |
| 3467 | } else { |
| 3468 | onBackPressed(); |
| 3469 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3470 | return true; |
| 3471 | } |
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 | if (mDefaultKeyMode == DEFAULT_KEYS_DISABLE) { |
| 3474 | return false; |
| 3475 | } else if (mDefaultKeyMode == DEFAULT_KEYS_SHORTCUT) { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 3476 | Window w = getWindow(); |
| 3477 | if (w.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 3478 | w.performPanelShortcut(Window.FEATURE_OPTIONS_PANEL, keyCode, event, |
| 3479 | Menu.FLAG_ALWAYS_PERFORM_CLOSE)) { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3480 | return true; |
| 3481 | } |
| 3482 | return false; |
Evan Rosky | c4620378 | 2017-02-17 13:11:53 -0800 | [diff] [blame] | 3483 | } else if (keyCode == KeyEvent.KEYCODE_TAB) { |
| 3484 | // Don't consume TAB here since it's used for navigation. Arrow keys |
| 3485 | // aren't considered "typing keys" so they already won't get consumed. |
| 3486 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | } else { |
| 3488 | // Common code for DEFAULT_KEYS_DIALER & DEFAULT_KEYS_SEARCH_* |
| 3489 | boolean clearSpannable = false; |
| 3490 | boolean handled; |
| 3491 | if ((event.getRepeatCount() != 0) || event.isSystem()) { |
| 3492 | clearSpannable = true; |
| 3493 | handled = false; |
| 3494 | } else { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3495 | handled = TextKeyListener.getInstance().onKeyDown( |
| 3496 | null, mDefaultKeySsb, keyCode, event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3497 | if (handled && mDefaultKeySsb.length() > 0) { |
| 3498 | // something useable has been typed - dispatch it now. |
| 3499 | |
| 3500 | final String str = mDefaultKeySsb.toString(); |
| 3501 | clearSpannable = true; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3503 | switch (mDefaultKeyMode) { |
| 3504 | case DEFAULT_KEYS_DIALER: |
| 3505 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + str)); |
| 3506 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3507 | startActivity(intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3508 | break; |
| 3509 | case DEFAULT_KEYS_SEARCH_LOCAL: |
| 3510 | startSearch(str, false, null, false); |
| 3511 | break; |
| 3512 | case DEFAULT_KEYS_SEARCH_GLOBAL: |
| 3513 | startSearch(str, false, null, true); |
| 3514 | break; |
| 3515 | } |
| 3516 | } |
| 3517 | } |
| 3518 | if (clearSpannable) { |
| 3519 | mDefaultKeySsb.clear(); |
| 3520 | mDefaultKeySsb.clearSpans(); |
| 3521 | Selection.setSelection(mDefaultKeySsb,0); |
| 3522 | } |
| 3523 | return handled; |
| 3524 | } |
| 3525 | } |
| 3526 | |
| 3527 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3528 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 3529 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 3530 | * the event). |
Siarhei Vishniakou | ccf973f | 2018-10-30 14:04:57 -0700 | [diff] [blame] | 3531 | * |
| 3532 | * To receive this callback, you must return true from onKeyDown for the current |
| 3533 | * event stream. |
| 3534 | * |
| 3535 | * @see KeyEvent.Callback#onKeyLongPress() |
| 3536 | * @see KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3537 | */ |
| 3538 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 3539 | return false; |
| 3540 | } |
| 3541 | |
| 3542 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3543 | * 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] | 3544 | * 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] | 3545 | * is inside a TextView will not trigger the event (unless it is a navigation |
| 3546 | * to another object) because TextView handles its own key presses. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3547 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3548 | * <p>The default implementation handles KEYCODE_BACK to stop the activity |
| 3549 | * and go back. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3550 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3551 | * @return Return <code>true</code> to prevent this event from being propagated |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3552 | * further, or <code>false</code> to indicate that you have not handled |
| 3553 | * this event and it should continue to be propagated. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3554 | * @see #onKeyDown |
| 3555 | * @see KeyEvent |
| 3556 | */ |
| 3557 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3558 | if (getApplicationInfo().targetSdkVersion |
| 3559 | >= Build.VERSION_CODES.ECLAIR) { |
| 3560 | if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() |
| 3561 | && !event.isCanceled()) { |
| 3562 | onBackPressed(); |
| 3563 | return true; |
| 3564 | } |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3565 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3566 | return false; |
| 3567 | } |
| 3568 | |
| 3569 | /** |
| 3570 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 3571 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 3572 | * the event). |
| 3573 | */ |
| 3574 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 3575 | return false; |
| 3576 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3577 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3578 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3579 | * Called when the activity has detected the user's press of the back |
| 3580 | * key. The default implementation simply finishes the current activity, |
| 3581 | * but you can override this to do whatever you want. |
| 3582 | */ |
| 3583 | public void onBackPressed() { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3584 | if (mActionBar != null && mActionBar.collapseActionView()) { |
| 3585 | return; |
| 3586 | } |
| 3587 | |
George Mount | 27b0dc0 | 2017-02-21 10:24:09 -0800 | [diff] [blame] | 3588 | FragmentManager fragmentManager = mFragments.getFragmentManager(); |
| 3589 | |
| 3590 | if (fragmentManager.isStateSaved() || !fragmentManager.popBackStackImmediate()) { |
Craig Mautner | 73f843d | 2014-05-19 09:42:28 -0700 | [diff] [blame] | 3591 | finishAfterTransition(); |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 3592 | } |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3593 | } |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 3594 | |
| 3595 | /** |
| 3596 | * Called when a key shortcut event is not handled by any of the views in the Activity. |
| 3597 | * Override this method to implement global key shortcuts for the Activity. |
| 3598 | * Key shortcuts can also be implemented by setting the |
| 3599 | * {@link MenuItem#setShortcut(char, char) shortcut} property of menu items. |
| 3600 | * |
| 3601 | * @param keyCode The value in event.getKeyCode(). |
| 3602 | * @param event Description of the key event. |
| 3603 | * @return True if the key shortcut was handled. |
| 3604 | */ |
| 3605 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
Abodunrinwa Toki | a04b7ad | 2015-06-30 17:44:04 -0700 | [diff] [blame] | 3606 | // Let the Action Bar have a chance at handling the shortcut. |
| 3607 | ActionBar actionBar = getActionBar(); |
| 3608 | return (actionBar != null && actionBar.onKeyShortcut(keyCode, event)); |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 3609 | } |
| 3610 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3611 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3612 | * Called when a touch screen event was not handled by any of the views |
| 3613 | * under it. This is most useful to process touch events that happen |
| 3614 | * outside of your window bounds, where there is no view to receive it. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3615 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3616 | * @param event The touch screen event being processed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3617 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | * @return Return true if you have consumed the event, false if you haven't. |
| 3619 | * The default implementation always returns false. |
| 3620 | */ |
| 3621 | public boolean onTouchEvent(MotionEvent event) { |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 3622 | if (mWindow.shouldCloseOnTouch(this, event)) { |
| 3623 | finish(); |
| 3624 | return true; |
| 3625 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3627 | return false; |
| 3628 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3630 | /** |
| 3631 | * Called when the trackball was moved and not handled by any of the |
| 3632 | * views inside of the activity. So, for example, if the trackball moves |
| 3633 | * while focus is on a button, you will receive a call here because |
| 3634 | * buttons do not normally do anything with trackball events. The call |
| 3635 | * here happens <em>before</em> trackball movements are converted to |
| 3636 | * DPAD key events, which then get sent back to the view hierarchy, and |
| 3637 | * will be processed at the point for things like focus navigation. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3638 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3639 | * @param event The trackball event being processed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3640 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | * @return Return true if you have consumed the event, false if you haven't. |
| 3642 | * The default implementation always returns false. |
| 3643 | */ |
| 3644 | public boolean onTrackballEvent(MotionEvent event) { |
| 3645 | return false; |
| 3646 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3647 | |
| 3648 | /** |
| 3649 | * Called when a generic motion event was not handled by any of the |
| 3650 | * views inside of the activity. |
| 3651 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3652 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 3653 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3654 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 3655 | * the class of input that was received. Implementations of this method |
| 3656 | * must examine the bits in the source before processing the event. |
| 3657 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3658 | * </p><p> |
| 3659 | * Generic motion events with source class |
| 3660 | * {@link android.view.InputDevice#SOURCE_CLASS_POINTER} |
| 3661 | * are delivered to the view under the pointer. All other generic motion events are |
| 3662 | * delivered to the focused view. |
| 3663 | * </p><p> |
| 3664 | * See {@link View#onGenericMotionEvent(MotionEvent)} for an example of how to |
| 3665 | * handle this event. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3666 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3667 | * |
| 3668 | * @param event The generic motion event being processed. |
| 3669 | * |
| 3670 | * @return Return true if you have consumed the event, false if you haven't. |
| 3671 | * The default implementation always returns false. |
| 3672 | */ |
| 3673 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 3674 | return false; |
| 3675 | } |
| 3676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3677 | /** |
| 3678 | * Called whenever a key, touch, or trackball event is dispatched to the |
| 3679 | * activity. Implement this method if you wish to know that the user has |
| 3680 | * interacted with the device in some way while your activity is running. |
| 3681 | * This callback and {@link #onUserLeaveHint} are intended to help |
| 3682 | * activities manage status bar notifications intelligently; specifically, |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 3683 | * for helping activities determine the proper time to cancel a notification. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3684 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3685 | * <p>All calls to your activity's {@link #onUserLeaveHint} callback will |
| 3686 | * be accompanied by calls to {@link #onUserInteraction}. This |
| 3687 | * ensures that your activity will be told of relevant user activity such |
| 3688 | * as pulling down the notification pane and touching an item there. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3689 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3690 | * <p>Note that this callback will be invoked for the touch down action |
| 3691 | * that begins a touch gesture, but may not be invoked for the touch-moved |
| 3692 | * and touch-up actions that follow. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3693 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3694 | * @see #onUserLeaveHint() |
| 3695 | */ |
| 3696 | public void onUserInteraction() { |
| 3697 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3699 | public void onWindowAttributesChanged(WindowManager.LayoutParams params) { |
| 3700 | // Update window manager if: we have a view, that view is |
| 3701 | // attached to its parent (which will be a RootView), and |
| 3702 | // this activity is not embedded. |
| 3703 | if (mParent == null) { |
| 3704 | View decor = mDecor; |
| 3705 | if (decor != null && decor.getParent() != null) { |
| 3706 | getWindowManager().updateViewLayout(decor, params); |
| 3707 | } |
| 3708 | } |
| 3709 | } |
| 3710 | |
| 3711 | public void onContentChanged() { |
| 3712 | } |
| 3713 | |
| 3714 | /** |
| 3715 | * Called when the current {@link Window} of the activity gains or loses |
| 3716 | * focus. This is the best indicator of whether this activity is visible |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3717 | * to the user. The default implementation clears the key tracking |
| 3718 | * state, so should always be called. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3719 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3720 | * <p>Note that this provides information about global focus state, which |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3721 | * is managed independently of activity lifecycles. As such, while focus |
| 3722 | * changes will generally have some relation to lifecycle changes (an |
| 3723 | * activity that is stopped will not generally get window focus), you |
| 3724 | * should not rely on any particular order between the callbacks here and |
| 3725 | * those in the other lifecycle methods such as {@link #onResume}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3726 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3727 | * <p>As a general rule, however, a resumed activity will have window |
| 3728 | * focus... unless it has displayed other dialogs or popups that take |
| 3729 | * input focus, in which case the activity itself will not have focus |
| 3730 | * when the other windows have it. Likewise, the system may display |
| 3731 | * system-level windows (such as the status bar notification panel or |
| 3732 | * a system alert) which will temporarily take window input focus without |
| 3733 | * pausing the foreground activity. |
| 3734 | * |
| 3735 | * @param hasFocus Whether the window of this activity has focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3736 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3737 | * @see #hasWindowFocus() |
| 3738 | * @see #onResume |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3739 | * @see View#onWindowFocusChanged(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3740 | */ |
| 3741 | public void onWindowFocusChanged(boolean hasFocus) { |
| 3742 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3743 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3744 | /** |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3745 | * Called when the main window associated with the activity has been |
| 3746 | * attached to the window manager. |
| 3747 | * See {@link View#onAttachedToWindow() View.onAttachedToWindow()} |
| 3748 | * for more information. |
| 3749 | * @see View#onAttachedToWindow |
| 3750 | */ |
| 3751 | public void onAttachedToWindow() { |
| 3752 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3753 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3754 | /** |
| 3755 | * Called when the main window associated with the activity has been |
| 3756 | * detached from the window manager. |
| 3757 | * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()} |
| 3758 | * for more information. |
| 3759 | * @see View#onDetachedFromWindow |
| 3760 | */ |
| 3761 | public void onDetachedFromWindow() { |
| 3762 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3763 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3764 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3765 | * Returns true if this activity's <em>main</em> window currently has window focus. |
| 3766 | * Note that this is not the same as the view itself having focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3767 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3768 | * @return True if this activity's main window currently has window focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3769 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3770 | * @see #onWindowAttributesChanged(android.view.WindowManager.LayoutParams) |
| 3771 | */ |
| 3772 | public boolean hasWindowFocus() { |
| 3773 | Window w = getWindow(); |
| 3774 | if (w != null) { |
| 3775 | View d = w.getDecorView(); |
| 3776 | if (d != null) { |
| 3777 | return d.hasWindowFocus(); |
| 3778 | } |
| 3779 | } |
| 3780 | return false; |
| 3781 | } |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3782 | |
| 3783 | /** |
| 3784 | * Called when the main window associated with the activity has been dismissed. |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 3785 | * @hide |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3786 | */ |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 3787 | @Override |
Ned Burns | 7d6cb91 | 2016-12-02 17:25:33 -0500 | [diff] [blame] | 3788 | public void onWindowDismissed(boolean finishTask, boolean suppressWindowTransition) { |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 3789 | finish(finishTask ? FINISH_TASK_WITH_ACTIVITY : DONT_FINISH_TASK_WITH_ACTIVITY); |
Ned Burns | 7d6cb91 | 2016-12-02 17:25:33 -0500 | [diff] [blame] | 3790 | if (suppressWindowTransition) { |
| 3791 | overridePendingTransition(0, 0); |
| 3792 | } |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3793 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3794 | |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3795 | |
Skuhne | ce2faa5 | 2015-08-11 10:36:38 -0700 | [diff] [blame] | 3796 | /** |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3797 | * Moves the activity between {@link WindowConfiguration#WINDOWING_MODE_FREEFORM} windowing mode |
| 3798 | * and {@link WindowConfiguration#WINDOWING_MODE_FULLSCREEN}. |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3799 | * |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3800 | * @hide |
| 3801 | */ |
| 3802 | @Override |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3803 | public void toggleFreeformWindowingMode() throws RemoteException { |
| 3804 | ActivityTaskManager.getService().toggleFreeformWindowingMode(mToken); |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3805 | } |
| 3806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3807 | /** |
Jaewan Kim | d98dcab | 2016-05-03 02:52:18 +0900 | [diff] [blame] | 3808 | * Puts the activity in picture-in-picture mode if the activity supports. |
| 3809 | * @see android.R.attr#supportsPictureInPicture |
| 3810 | * @hide |
| 3811 | */ |
| 3812 | @Override |
| 3813 | public void enterPictureInPictureModeIfPossible() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 3814 | if (mActivityInfo.supportsPictureInPicture()) { |
Jaewan Kim | d98dcab | 2016-05-03 02:52:18 +0900 | [diff] [blame] | 3815 | enterPictureInPictureMode(); |
| 3816 | } |
| 3817 | } |
| 3818 | |
| 3819 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3820 | * Called to process key events. You can override this to intercept all |
| 3821 | * 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] | 3822 | * this implementation for key events that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3823 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3824 | * @param event The key event. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3825 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3826 | * @return boolean Return true if this event was consumed. |
| 3827 | */ |
| 3828 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 3829 | onUserInteraction(); |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3830 | |
| 3831 | // Let action bars open menus in response to the menu key prioritized over |
| 3832 | // the window handling it |
George Mount | 5beb2617 | 2015-12-15 13:36:01 -0800 | [diff] [blame] | 3833 | final int keyCode = event.getKeyCode(); |
| 3834 | if (keyCode == KeyEvent.KEYCODE_MENU && |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3835 | mActionBar != null && mActionBar.onMenuKeyEvent(event)) { |
| 3836 | return true; |
| 3837 | } |
| 3838 | |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3839 | Window win = getWindow(); |
| 3840 | if (win.superDispatchKeyEvent(event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3841 | return true; |
| 3842 | } |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3843 | View decor = mDecor; |
| 3844 | if (decor == null) decor = win.getDecorView(); |
| 3845 | return event.dispatch(this, decor != null |
| 3846 | ? decor.getKeyDispatcherState() : null, this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 3850 | * Called to process a key shortcut event. |
| 3851 | * You can override this to intercept all key shortcut events before they are |
| 3852 | * dispatched to the window. Be sure to call this implementation for key shortcut |
| 3853 | * events that should be handled normally. |
| 3854 | * |
| 3855 | * @param event The key shortcut event. |
| 3856 | * @return True if this event was consumed. |
| 3857 | */ |
| 3858 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 3859 | onUserInteraction(); |
| 3860 | if (getWindow().superDispatchKeyShortcutEvent(event)) { |
| 3861 | return true; |
| 3862 | } |
| 3863 | return onKeyShortcut(event.getKeyCode(), event); |
| 3864 | } |
| 3865 | |
| 3866 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3867 | * Called to process touch screen events. You can override this to |
| 3868 | * intercept all touch screen events before they are dispatched to the |
| 3869 | * window. Be sure to call this implementation for touch screen events |
| 3870 | * that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3871 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3872 | * @param ev The touch screen event. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3873 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3874 | * @return boolean Return true if this event was consumed. |
| 3875 | */ |
| 3876 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 3877 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 3878 | onUserInteraction(); |
| 3879 | } |
| 3880 | if (getWindow().superDispatchTouchEvent(ev)) { |
| 3881 | return true; |
| 3882 | } |
| 3883 | return onTouchEvent(ev); |
| 3884 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3885 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3886 | /** |
| 3887 | * Called to process trackball events. You can override this to |
| 3888 | * intercept all trackball events before they are dispatched to the |
| 3889 | * window. Be sure to call this implementation for trackball events |
| 3890 | * that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3891 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3892 | * @param ev The trackball event. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3893 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3894 | * @return boolean Return true if this event was consumed. |
| 3895 | */ |
| 3896 | public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 3897 | onUserInteraction(); |
| 3898 | if (getWindow().superDispatchTrackballEvent(ev)) { |
| 3899 | return true; |
| 3900 | } |
| 3901 | return onTrackballEvent(ev); |
| 3902 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3903 | |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3904 | /** |
| 3905 | * Called to process generic motion events. You can override this to |
| 3906 | * intercept all generic motion events before they are dispatched to the |
| 3907 | * window. Be sure to call this implementation for generic motion events |
| 3908 | * that should be handled normally. |
| 3909 | * |
| 3910 | * @param ev The generic motion event. |
| 3911 | * |
| 3912 | * @return boolean Return true if this event was consumed. |
| 3913 | */ |
| 3914 | public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 3915 | onUserInteraction(); |
| 3916 | if (getWindow().superDispatchGenericMotionEvent(ev)) { |
| 3917 | return true; |
| 3918 | } |
| 3919 | return onGenericMotionEvent(ev); |
| 3920 | } |
| 3921 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3922 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 3923 | event.setClassName(getClass().getName()); |
| 3924 | event.setPackageName(getPackageName()); |
| 3925 | |
| 3926 | LayoutParams params = getWindow().getAttributes(); |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 3927 | boolean isFullScreen = (params.width == LayoutParams.MATCH_PARENT) && |
| 3928 | (params.height == LayoutParams.MATCH_PARENT); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3929 | event.setFullScreen(isFullScreen); |
| 3930 | |
| 3931 | CharSequence title = getTitle(); |
| 3932 | if (!TextUtils.isEmpty(title)) { |
| 3933 | event.getText().add(title); |
| 3934 | } |
| 3935 | |
| 3936 | return true; |
| 3937 | } |
| 3938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3939 | /** |
| 3940 | * Default implementation of |
| 3941 | * {@link android.view.Window.Callback#onCreatePanelView} |
| 3942 | * for activities. This |
| 3943 | * simply returns null so that all panel sub-windows will have the default |
| 3944 | * menu behavior. |
| 3945 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3946 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3947 | public View onCreatePanelView(int featureId) { |
| 3948 | return null; |
| 3949 | } |
| 3950 | |
| 3951 | /** |
| 3952 | * Default implementation of |
| 3953 | * {@link android.view.Window.Callback#onCreatePanelMenu} |
| 3954 | * for activities. This calls through to the new |
| 3955 | * {@link #onCreateOptionsMenu} method for the |
| 3956 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} panel, |
| 3957 | * so that subclasses of Activity don't need to deal with feature codes. |
| 3958 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 3959 | public boolean onCreatePanelMenu(int featureId, @NonNull Menu menu) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3960 | if (featureId == Window.FEATURE_OPTIONS_PANEL) { |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3961 | boolean show = onCreateOptionsMenu(menu); |
| 3962 | show |= mFragments.dispatchCreateOptionsMenu(menu, getMenuInflater()); |
| 3963 | return show; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3964 | } |
| 3965 | return false; |
| 3966 | } |
| 3967 | |
| 3968 | /** |
| 3969 | * Default implementation of |
| 3970 | * {@link android.view.Window.Callback#onPreparePanel} |
| 3971 | * for activities. This |
| 3972 | * calls through to the new {@link #onPrepareOptionsMenu} method for the |
| 3973 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} |
| 3974 | * panel, so that subclasses of |
| 3975 | * Activity don't need to deal with feature codes. |
| 3976 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 3977 | public boolean onPreparePanel(int featureId, @Nullable View view, @NonNull Menu menu) { |
| 3978 | if (featureId == Window.FEATURE_OPTIONS_PANEL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3979 | boolean goforit = onPrepareOptionsMenu(menu); |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3980 | goforit |= mFragments.dispatchPrepareOptionsMenu(menu); |
Adam Powell | ef31e7c | 2012-05-08 09:59:40 -0700 | [diff] [blame] | 3981 | return goforit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3982 | } |
| 3983 | return true; |
| 3984 | } |
| 3985 | |
| 3986 | /** |
| 3987 | * {@inheritDoc} |
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 The default implementation returns true. |
| 3990 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 3991 | @Override |
| 3992 | public boolean onMenuOpened(int featureId, @NonNull Menu menu) { |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 3993 | if (featureId == Window.FEATURE_ACTION_BAR) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3994 | initWindowDecorActionBar(); |
Adam Powell | 049dd3d | 2010-12-02 13:43:59 -0800 | [diff] [blame] | 3995 | if (mActionBar != null) { |
| 3996 | mActionBar.dispatchMenuVisibilityChanged(true); |
| 3997 | } else { |
| 3998 | Log.e(TAG, "Tried to open action bar menu with no action bar"); |
| 3999 | } |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 4000 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4001 | return true; |
| 4002 | } |
| 4003 | |
| 4004 | /** |
| 4005 | * Default implementation of |
| 4006 | * {@link android.view.Window.Callback#onMenuItemSelected} |
| 4007 | * for activities. This calls through to the new |
| 4008 | * {@link #onOptionsItemSelected} method for the |
| 4009 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} |
| 4010 | * panel, so that subclasses of |
| 4011 | * Activity don't need to deal with feature codes. |
| 4012 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 4013 | public boolean onMenuItemSelected(int featureId, @NonNull MenuItem item) { |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 4014 | CharSequence titleCondensed = item.getTitleCondensed(); |
| 4015 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4016 | switch (featureId) { |
| 4017 | case Window.FEATURE_OPTIONS_PANEL: |
| 4018 | // Put event logging here so it gets called even if subclass |
| 4019 | // doesn't call through to superclass's implmeentation of each |
| 4020 | // of these methods below |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 4021 | if(titleCondensed != null) { |
| 4022 | EventLog.writeEvent(50000, 0, titleCondensed.toString()); |
| 4023 | } |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 4024 | if (onOptionsItemSelected(item)) { |
| 4025 | return true; |
| 4026 | } |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 4027 | if (mFragments.dispatchOptionsItemSelected(item)) { |
| 4028 | return true; |
| 4029 | } |
| 4030 | if (item.getItemId() == android.R.id.home && mActionBar != null && |
| 4031 | (mActionBar.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) != 0) { |
| 4032 | if (mParent == null) { |
Adam Powell | 07304f529 | 2012-05-07 17:32:44 -0700 | [diff] [blame] | 4033 | return onNavigateUp(); |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 4034 | } else { |
Adam Powell | 07304f529 | 2012-05-07 17:32:44 -0700 | [diff] [blame] | 4035 | return mParent.onNavigateUpFromChild(this); |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 4036 | } |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 4037 | } |
| 4038 | return false; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4040 | case Window.FEATURE_CONTEXT_MENU: |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 4041 | if(titleCondensed != null) { |
| 4042 | EventLog.writeEvent(50000, 1, titleCondensed.toString()); |
| 4043 | } |
Dianne Hackborn | 5ddd127 | 2010-06-12 10:15:28 -0700 | [diff] [blame] | 4044 | if (onContextItemSelected(item)) { |
| 4045 | return true; |
| 4046 | } |
| 4047 | return mFragments.dispatchContextItemSelected(item); |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 4048 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4049 | default: |
| 4050 | return false; |
| 4051 | } |
| 4052 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 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#onPanelClosed(int, Menu)} for |
| 4057 | * activities. This calls through to {@link #onOptionsMenuClosed(Menu)} |
| 4058 | * method for the {@link android.view.Window#FEATURE_OPTIONS_PANEL} panel, |
| 4059 | * so that subclasses of Activity don't need to deal with feature codes. |
| 4060 | * For context menus ({@link Window#FEATURE_CONTEXT_MENU}), the |
| 4061 | * {@link #onContextMenuClosed(Menu)} will be called. |
| 4062 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 4063 | public void onPanelClosed(int featureId, @NonNull Menu menu) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4064 | switch (featureId) { |
| 4065 | case Window.FEATURE_OPTIONS_PANEL: |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 4066 | mFragments.dispatchOptionsMenuClosed(menu); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4067 | onOptionsMenuClosed(menu); |
| 4068 | break; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4069 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4070 | case Window.FEATURE_CONTEXT_MENU: |
| 4071 | onContextMenuClosed(menu); |
| 4072 | break; |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 4073 | |
| 4074 | case Window.FEATURE_ACTION_BAR: |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 4075 | initWindowDecorActionBar(); |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 4076 | mActionBar.dispatchMenuVisibilityChanged(false); |
| 4077 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4078 | } |
| 4079 | } |
| 4080 | |
| 4081 | /** |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 4082 | * Declare that the options menu has changed, so should be recreated. |
| 4083 | * The {@link #onCreateOptionsMenu(Menu)} method will be called the next |
| 4084 | * time it needs to be displayed. |
| 4085 | */ |
| 4086 | public void invalidateOptionsMenu() { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 4087 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 4088 | (mActionBar == null || !mActionBar.invalidateOptionsMenu())) { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 4089 | mWindow.invalidatePanelMenu(Window.FEATURE_OPTIONS_PANEL); |
| 4090 | } |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 4091 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4092 | |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 4093 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4094 | * Initialize the contents of the Activity's standard options menu. You |
| 4095 | * should place your menu items in to <var>menu</var>. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4096 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | * <p>This is only called once, the first time the options menu is |
| 4098 | * displayed. To update the menu every time it is displayed, see |
| 4099 | * {@link #onPrepareOptionsMenu}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4100 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4101 | * <p>The default implementation populates the menu with standard system |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4102 | * menu items. These are placed in the {@link Menu#CATEGORY_SYSTEM} group so that |
| 4103 | * they will be correctly ordered with application-defined menu items. |
| 4104 | * Deriving classes should always call through to the base implementation. |
| 4105 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4106 | * <p>You can safely hold on to <var>menu</var> (and any items created |
| 4107 | * from it), making modifications to it as desired, until the next |
| 4108 | * time onCreateOptionsMenu() is called. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4109 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4110 | * <p>When you add items to the menu, you can implement the Activity's |
| 4111 | * {@link #onOptionsItemSelected} method to handle them there. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4112 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4113 | * @param menu The options menu in which you place your items. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4114 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4115 | * @return You must return true for the menu to be displayed; |
| 4116 | * if you return false it will not be shown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4117 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4118 | * @see #onPrepareOptionsMenu |
| 4119 | * @see #onOptionsItemSelected |
| 4120 | */ |
| 4121 | public boolean onCreateOptionsMenu(Menu menu) { |
| 4122 | if (mParent != null) { |
| 4123 | return mParent.onCreateOptionsMenu(menu); |
| 4124 | } |
| 4125 | return true; |
| 4126 | } |
| 4127 | |
| 4128 | /** |
| 4129 | * Prepare the Screen's standard options menu to be displayed. This is |
| 4130 | * called right before the menu is shown, every time it is shown. You can |
| 4131 | * use this method to efficiently enable/disable items or otherwise |
| 4132 | * dynamically modify the contents. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4133 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4134 | * <p>The default implementation updates the system menu items based on the |
| 4135 | * activity's state. Deriving classes should always call through to the |
| 4136 | * base class implementation. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4137 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4138 | * @param menu The options menu as last shown or first initialized by |
| 4139 | * onCreateOptionsMenu(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4140 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4141 | * @return You must return true for the menu to be displayed; |
| 4142 | * if you return false it will not be shown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4143 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4144 | * @see #onCreateOptionsMenu |
| 4145 | */ |
| 4146 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 4147 | if (mParent != null) { |
| 4148 | return mParent.onPrepareOptionsMenu(menu); |
| 4149 | } |
| 4150 | return true; |
| 4151 | } |
| 4152 | |
| 4153 | /** |
| 4154 | * This hook is called whenever an item in your options menu is selected. |
| 4155 | * The default implementation simply returns false to have the normal |
| 4156 | * processing happen (calling the item's Runnable or sending a message to |
| 4157 | * its Handler as appropriate). You can use this method for any items |
| 4158 | * for which you would like to do processing without those other |
| 4159 | * facilities. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4160 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4161 | * <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] | 4162 | * perform the default menu handling.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4163 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4164 | * @param item The menu item that was selected. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4165 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4166 | * @return boolean Return false to allow normal menu processing to |
| 4167 | * proceed, true to consume it here. |
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 | * @see #onCreateOptionsMenu |
| 4170 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 4171 | public boolean onOptionsItemSelected(@NonNull MenuItem item) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4172 | if (mParent != null) { |
| 4173 | return mParent.onOptionsItemSelected(item); |
| 4174 | } |
| 4175 | return false; |
| 4176 | } |
| 4177 | |
| 4178 | /** |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4179 | * This method is called whenever the user chooses to navigate Up within your application's |
| 4180 | * activity hierarchy from the action bar. |
| 4181 | * |
| 4182 | * <p>If the attribute {@link android.R.attr#parentActivityName parentActivityName} |
| 4183 | * was specified in the manifest for this activity or an activity-alias to it, |
| 4184 | * default Up navigation will be handled automatically. If any activity |
| 4185 | * along the parent chain requires extra Intent arguments, the Activity subclass |
| 4186 | * should override the method {@link #onPrepareNavigateUpTaskStack(TaskStackBuilder)} |
| 4187 | * to supply those arguments.</p> |
| 4188 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 4189 | * <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] | 4190 | * from the developer guide and <a href="{@docRoot}design/patterns/navigation.html">Navigation</a> |
| 4191 | * from the design guide for more information about navigating within your app.</p> |
| 4192 | * |
| 4193 | * <p>See the {@link TaskStackBuilder} class and the Activity methods |
| 4194 | * {@link #getParentActivityIntent()}, {@link #shouldUpRecreateTask(Intent)}, and |
| 4195 | * {@link #navigateUpTo(Intent)} for help implementing custom Up navigation. |
| 4196 | * The AppNavigation sample application in the Android SDK is also available for reference.</p> |
| 4197 | * |
| 4198 | * @return true if Up navigation completed successfully and this Activity was finished, |
| 4199 | * false otherwise. |
| 4200 | */ |
| 4201 | public boolean onNavigateUp() { |
| 4202 | // Automatically handle hierarchical Up navigation if the proper |
| 4203 | // metadata is available. |
| 4204 | Intent upIntent = getParentActivityIntent(); |
| 4205 | if (upIntent != null) { |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 4206 | if (mActivityInfo.taskAffinity == null) { |
| 4207 | // Activities with a null affinity are special; they really shouldn't |
| 4208 | // specify a parent activity intent in the first place. Just finish |
| 4209 | // the current activity and call it a day. |
| 4210 | finish(); |
| 4211 | } else if (shouldUpRecreateTask(upIntent)) { |
Adam Powell | f78a844 | 2012-05-01 18:09:32 -0700 | [diff] [blame] | 4212 | TaskStackBuilder b = TaskStackBuilder.create(this); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4213 | onCreateNavigateUpTaskStack(b); |
| 4214 | onPrepareNavigateUpTaskStack(b); |
| 4215 | b.startActivities(); |
Adam Powell | 3d193d9 | 2012-05-15 16:51:55 -0700 | [diff] [blame] | 4216 | |
| 4217 | // We can't finishAffinity if we have a result. |
| 4218 | // Fall back and simply finish the current activity instead. |
| 4219 | if (mResultCode != RESULT_CANCELED || mResultData != null) { |
| 4220 | // Tell the developer what's going on to avoid hair-pulling. |
| 4221 | Log.i(TAG, "onNavigateUp only finishing topmost activity to return a result"); |
| 4222 | finish(); |
| 4223 | } else { |
| 4224 | finishAffinity(); |
| 4225 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4226 | } else { |
| 4227 | navigateUpTo(upIntent); |
| 4228 | } |
| 4229 | return true; |
| 4230 | } |
| 4231 | return false; |
| 4232 | } |
| 4233 | |
| 4234 | /** |
| 4235 | * This is called when a child activity of this one attempts to navigate up. |
| 4236 | * The default implementation simply calls onNavigateUp() on this activity (the parent). |
| 4237 | * |
| 4238 | * @param child The activity making the call. |
| 4239 | */ |
| 4240 | public boolean onNavigateUpFromChild(Activity child) { |
| 4241 | return onNavigateUp(); |
| 4242 | } |
| 4243 | |
| 4244 | /** |
| 4245 | * Define the synthetic task stack that will be generated during Up navigation from |
| 4246 | * a different task. |
| 4247 | * |
| 4248 | * <p>The default implementation of this method adds the parent chain of this activity |
| 4249 | * as specified in the manifest to the supplied {@link TaskStackBuilder}. Applications |
| 4250 | * may choose to override this method to construct the desired task stack in a different |
| 4251 | * way.</p> |
| 4252 | * |
Adam Powell | f019595 | 2012-05-02 21:38:54 -0700 | [diff] [blame] | 4253 | * <p>This method will be invoked by the default implementation of {@link #onNavigateUp()} |
| 4254 | * if {@link #shouldUpRecreateTask(Intent)} returns true when supplied with the intent |
| 4255 | * returned by {@link #getParentActivityIntent()}.</p> |
| 4256 | * |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4257 | * <p>Applications that wish to supply extra Intent parameters to the parent stack defined |
| 4258 | * by the manifest should override {@link #onPrepareNavigateUpTaskStack(TaskStackBuilder)}.</p> |
| 4259 | * |
| 4260 | * @param builder An empty TaskStackBuilder - the application should add intents representing |
| 4261 | * the desired task stack |
| 4262 | */ |
| 4263 | public void onCreateNavigateUpTaskStack(TaskStackBuilder builder) { |
| 4264 | builder.addParentStack(this); |
| 4265 | } |
| 4266 | |
| 4267 | /** |
| 4268 | * Prepare the synthetic task stack that will be generated during Up navigation |
| 4269 | * from a different task. |
| 4270 | * |
| 4271 | * <p>This method receives the {@link TaskStackBuilder} with the constructed series of |
| 4272 | * Intents as generated by {@link #onCreateNavigateUpTaskStack(TaskStackBuilder)}. |
| 4273 | * If any extra data should be added to these intents before launching the new task, |
| 4274 | * the application should override this method and add that data here.</p> |
| 4275 | * |
| 4276 | * @param builder A TaskStackBuilder that has been populated with Intents by |
| 4277 | * onCreateNavigateUpTaskStack. |
| 4278 | */ |
| 4279 | public void onPrepareNavigateUpTaskStack(TaskStackBuilder builder) { |
| 4280 | } |
| 4281 | |
| 4282 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4283 | * This hook is called whenever the options menu is being closed (either by the user canceling |
| 4284 | * the menu with the back/menu button, or when an item is selected). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4285 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4286 | * @param menu The options menu as last shown or first initialized by |
| 4287 | * onCreateOptionsMenu(). |
| 4288 | */ |
| 4289 | public void onOptionsMenuClosed(Menu menu) { |
| 4290 | if (mParent != null) { |
| 4291 | mParent.onOptionsMenuClosed(menu); |
| 4292 | } |
| 4293 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4295 | /** |
| 4296 | * Programmatically opens the options menu. If the options menu is already |
| 4297 | * open, this method does nothing. |
| 4298 | */ |
| 4299 | public void openOptionsMenu() { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 4300 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 4301 | (mActionBar == null || !mActionBar.openOptionsMenu())) { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 4302 | mWindow.openPanel(Window.FEATURE_OPTIONS_PANEL, null); |
| 4303 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4304 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4306 | /** |
| 4307 | * Progammatically closes the options menu. If the options menu is already |
| 4308 | * closed, this method does nothing. |
| 4309 | */ |
| 4310 | public void closeOptionsMenu() { |
Evan Rosky | 41823d1 | 2017-03-21 14:42:35 -0700 | [diff] [blame] | 4311 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 4312 | (mActionBar == null || !mActionBar.closeOptionsMenu())) { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 4313 | mWindow.closePanel(Window.FEATURE_OPTIONS_PANEL); |
| 4314 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4315 | } |
| 4316 | |
| 4317 | /** |
| 4318 | * Called when a context menu for the {@code view} is about to be shown. |
| 4319 | * Unlike {@link #onCreateOptionsMenu(Menu)}, this will be called every |
| 4320 | * time the context menu is about to be shown and should be populated for |
| 4321 | * the view (or item inside the view for {@link AdapterView} subclasses, |
| 4322 | * this can be found in the {@code menuInfo})). |
| 4323 | * <p> |
| 4324 | * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an |
| 4325 | * item has been selected. |
| 4326 | * <p> |
| 4327 | * 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] | 4328 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4329 | */ |
| 4330 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { |
| 4331 | } |
| 4332 | |
| 4333 | /** |
| 4334 | * Registers a context menu to be shown for the given view (multiple views |
| 4335 | * can show the context menu). This method will set the |
| 4336 | * {@link OnCreateContextMenuListener} on the view to this activity, so |
| 4337 | * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be |
| 4338 | * called when it is time to show the context menu. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4339 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4340 | * @see #unregisterForContextMenu(View) |
| 4341 | * @param view The view that should show a context menu. |
| 4342 | */ |
| 4343 | public void registerForContextMenu(View view) { |
| 4344 | view.setOnCreateContextMenuListener(this); |
| 4345 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4347 | /** |
| 4348 | * Prevents a context menu to be shown for the given view. This method will remove the |
| 4349 | * {@link OnCreateContextMenuListener} on the view. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4350 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4351 | * @see #registerForContextMenu(View) |
| 4352 | * @param view The view that should stop showing a context menu. |
| 4353 | */ |
| 4354 | public void unregisterForContextMenu(View view) { |
| 4355 | view.setOnCreateContextMenuListener(null); |
| 4356 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4357 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4358 | /** |
| 4359 | * Programmatically opens the context menu for a particular {@code view}. |
| 4360 | * The {@code view} should have been added via |
| 4361 | * {@link #registerForContextMenu(View)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4362 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4363 | * @param view The view to show the context menu for. |
| 4364 | */ |
| 4365 | public void openContextMenu(View view) { |
| 4366 | view.showContextMenu(); |
| 4367 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4369 | /** |
| 4370 | * Programmatically closes the most recently opened context menu, if showing. |
| 4371 | */ |
| 4372 | public void closeContextMenu() { |
Jose Lima | bd769a1 | 2015-01-28 10:43:15 -0800 | [diff] [blame] | 4373 | if (mWindow.hasFeature(Window.FEATURE_CONTEXT_MENU)) { |
| 4374 | mWindow.closePanel(Window.FEATURE_CONTEXT_MENU); |
| 4375 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4376 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4378 | /** |
| 4379 | * This hook is called whenever an item in a context menu is selected. The |
| 4380 | * default implementation simply returns false to have the normal processing |
| 4381 | * happen (calling the item's Runnable or sending a message to its Handler |
| 4382 | * as appropriate). You can use this method for any items for which you |
| 4383 | * would like to do processing without those other facilities. |
| 4384 | * <p> |
| 4385 | * Use {@link MenuItem#getMenuInfo()} to get extra information set by the |
| 4386 | * View that added this menu item. |
| 4387 | * <p> |
| 4388 | * Derived classes should call through to the base class for it to perform |
| 4389 | * the default menu handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4390 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4391 | * @param item The context menu item that was selected. |
| 4392 | * @return boolean Return false to allow normal context menu processing to |
| 4393 | * proceed, true to consume it here. |
| 4394 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 4395 | public boolean onContextItemSelected(@NonNull MenuItem item) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4396 | if (mParent != null) { |
| 4397 | return mParent.onContextItemSelected(item); |
| 4398 | } |
| 4399 | return false; |
| 4400 | } |
| 4401 | |
| 4402 | /** |
| 4403 | * This hook is called whenever the context menu is being closed (either by |
| 4404 | * the user canceling the menu with the back/menu button, or when an item is |
| 4405 | * selected). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4406 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4407 | * @param menu The context menu that is being closed. |
| 4408 | */ |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 4409 | public void onContextMenuClosed(@NonNull Menu menu) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4410 | if (mParent != null) { |
| 4411 | mParent.onContextMenuClosed(menu); |
| 4412 | } |
| 4413 | } |
| 4414 | |
| 4415 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4416 | * @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] | 4417 | */ |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4418 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4419 | protected Dialog onCreateDialog(int id) { |
| 4420 | return null; |
| 4421 | } |
| 4422 | |
| 4423 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4424 | * Callback for creating dialogs that are managed (saved and restored) for you |
| 4425 | * by the activity. The default implementation calls through to |
| 4426 | * {@link #onCreateDialog(int)} for compatibility. |
| 4427 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 4428 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 4429 | * or later, consider instead using a {@link DialogFragment} instead.</em> |
| 4430 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4431 | * <p>If you use {@link #showDialog(int)}, the activity will call through to |
| 4432 | * this method the first time, and hang onto it thereafter. Any dialog |
| 4433 | * that is created by this method will automatically be saved and restored |
| 4434 | * for you, including whether it is showing. |
| 4435 | * |
| 4436 | * <p>If you would like the activity to manage saving and restoring dialogs |
| 4437 | * for you, you should override this method and handle any ids that are |
| 4438 | * passed to {@link #showDialog}. |
| 4439 | * |
| 4440 | * <p>If you would like an opportunity to prepare your dialog before it is shown, |
| 4441 | * override {@link #onPrepareDialog(int, Dialog, Bundle)}. |
| 4442 | * |
| 4443 | * @param id The id of the dialog. |
| 4444 | * @param args The dialog arguments provided to {@link #showDialog(int, Bundle)}. |
| 4445 | * @return The dialog. If you return null, the dialog will not be created. |
| 4446 | * |
| 4447 | * @see #onPrepareDialog(int, Dialog, Bundle) |
| 4448 | * @see #showDialog(int, Bundle) |
| 4449 | * @see #dismissDialog(int) |
| 4450 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4451 | * |
| 4452 | * @deprecated Use the new {@link DialogFragment} class with |
| 4453 | * {@link FragmentManager} instead; this is also |
| 4454 | * available on older platforms through the Android compatibility package. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4455 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4456 | @Nullable |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4457 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4458 | protected Dialog onCreateDialog(int id, Bundle args) { |
| 4459 | return onCreateDialog(id); |
| 4460 | } |
| 4461 | |
| 4462 | /** |
| 4463 | * @deprecated Old no-arguments version of |
| 4464 | * {@link #onPrepareDialog(int, Dialog, Bundle)}. |
| 4465 | */ |
| 4466 | @Deprecated |
| 4467 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 4468 | dialog.setOwnerActivity(this); |
| 4469 | } |
| 4470 | |
| 4471 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4472 | * Provides an opportunity to prepare a managed dialog before it is being |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4473 | * shown. The default implementation calls through to |
| 4474 | * {@link #onPrepareDialog(int, Dialog)} for compatibility. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4475 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4476 | * <p> |
| 4477 | * Override this if you need to update a managed dialog based on the state |
| 4478 | * of the application each time it is shown. For example, a time picker |
| 4479 | * dialog might want to be updated with the current time. You should call |
| 4480 | * through to the superclass's implementation. The default implementation |
| 4481 | * will set this Activity as the owner activity on the Dialog. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4482 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4483 | * @param id The id of the managed dialog. |
| 4484 | * @param dialog The dialog. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4485 | * @param args The dialog arguments provided to {@link #showDialog(int, Bundle)}. |
| 4486 | * @see #onCreateDialog(int, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4487 | * @see #showDialog(int) |
| 4488 | * @see #dismissDialog(int) |
| 4489 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4490 | * |
| 4491 | * @deprecated Use the new {@link DialogFragment} class with |
| 4492 | * {@link FragmentManager} instead; this is also |
| 4493 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4494 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4495 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4496 | protected void onPrepareDialog(int id, Dialog dialog, Bundle args) { |
| 4497 | onPrepareDialog(id, dialog); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4498 | } |
| 4499 | |
| 4500 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4501 | * Simple version of {@link #showDialog(int, Bundle)} that does not |
| 4502 | * take any arguments. Simply calls {@link #showDialog(int, Bundle)} |
| 4503 | * with null arguments. |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4504 | * |
| 4505 | * @deprecated Use the new {@link DialogFragment} class with |
| 4506 | * {@link FragmentManager} instead; this is also |
| 4507 | * available on older platforms through the Android compatibility package. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4508 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4509 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4510 | public final void showDialog(int id) { |
| 4511 | showDialog(id, null); |
| 4512 | } |
| 4513 | |
| 4514 | /** |
| 4515 | * 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] | 4516 | * will be made with the same id the first time this is called for a given |
| 4517 | * id. From thereafter, the dialog will be automatically saved and restored. |
| 4518 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 4519 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 4520 | * or later, consider instead using a {@link DialogFragment} instead.</em> |
| 4521 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4522 | * <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] | 4523 | * be made to provide an opportunity to do any timely preparation. |
| 4524 | * |
| 4525 | * @param id The id of the managed dialog. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4526 | * @param args Arguments to pass through to the dialog. These will be saved |
| 4527 | * and restored for you. Note that if the dialog is already created, |
| 4528 | * {@link #onCreateDialog(int, Bundle)} will not be called with the new |
| 4529 | * arguments but {@link #onPrepareDialog(int, Dialog, Bundle)} will be. |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 4530 | * If you need to rebuild the dialog, call {@link #removeDialog(int)} first. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4531 | * @return Returns true if the Dialog was created; false is returned if |
| 4532 | * it is not created because {@link #onCreateDialog(int, Bundle)} returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4533 | * |
Joe Onorato | 37296dc | 2009-07-31 17:58:55 -0700 | [diff] [blame] | 4534 | * @see Dialog |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4535 | * @see #onCreateDialog(int, Bundle) |
| 4536 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4537 | * @see #dismissDialog(int) |
| 4538 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4539 | * |
| 4540 | * @deprecated Use the new {@link DialogFragment} class with |
| 4541 | * {@link FragmentManager} instead; this is also |
| 4542 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4543 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4544 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4545 | public final boolean showDialog(int id, Bundle args) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4546 | if (mManagedDialogs == null) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4547 | mManagedDialogs = new SparseArray<ManagedDialog>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4548 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4549 | ManagedDialog md = mManagedDialogs.get(id); |
| 4550 | if (md == null) { |
| 4551 | md = new ManagedDialog(); |
| 4552 | md.mDialog = createDialog(id, null, args); |
| 4553 | if (md.mDialog == null) { |
| 4554 | return false; |
| 4555 | } |
| 4556 | mManagedDialogs.put(id, md); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4557 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4558 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4559 | md.mArgs = args; |
| 4560 | onPrepareDialog(id, md.mDialog, args); |
| 4561 | md.mDialog.show(); |
| 4562 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4563 | } |
| 4564 | |
| 4565 | /** |
| 4566 | * Dismiss a dialog that was previously shown via {@link #showDialog(int)}. |
| 4567 | * |
| 4568 | * @param id The id of the managed dialog. |
| 4569 | * |
| 4570 | * @throws IllegalArgumentException if the id was not previously shown via |
| 4571 | * {@link #showDialog(int)}. |
| 4572 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4573 | * @see #onCreateDialog(int, Bundle) |
| 4574 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4575 | * @see #showDialog(int) |
| 4576 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4577 | * |
| 4578 | * @deprecated Use the new {@link DialogFragment} class with |
| 4579 | * {@link FragmentManager} instead; this is also |
| 4580 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4581 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4582 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4583 | public final void dismissDialog(int id) { |
| 4584 | if (mManagedDialogs == null) { |
| 4585 | throw missingDialog(id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4586 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4587 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4588 | final ManagedDialog md = mManagedDialogs.get(id); |
| 4589 | if (md == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4590 | throw missingDialog(id); |
| 4591 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4592 | md.mDialog.dismiss(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4593 | } |
| 4594 | |
| 4595 | /** |
| 4596 | * Creates an exception to throw if a user passed in a dialog id that is |
| 4597 | * unexpected. |
| 4598 | */ |
| 4599 | private IllegalArgumentException missingDialog(int id) { |
| 4600 | return new IllegalArgumentException("no dialog with id " + id + " was ever " |
| 4601 | + "shown via Activity#showDialog"); |
| 4602 | } |
| 4603 | |
| 4604 | /** |
| 4605 | * Removes any internal references to a dialog managed by this Activity. |
| 4606 | * If the dialog is showing, it will dismiss it as part of the clean up. |
| 4607 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4608 | * <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] | 4609 | * want to avoid the overhead of saving and restoring it in the future. |
| 4610 | * |
Dianne Hackborn | d2ce8bbb | 2010-10-06 16:46:05 -0700 | [diff] [blame] | 4611 | * <p>As of {@link android.os.Build.VERSION_CODES#GINGERBREAD}, this function |
| 4612 | * will not throw an exception if you try to remove an ID that does not |
| 4613 | * currently have an associated dialog.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4614 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4615 | * @param id The id of the managed dialog. |
| 4616 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4617 | * @see #onCreateDialog(int, Bundle) |
| 4618 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4619 | * @see #showDialog(int) |
| 4620 | * @see #dismissDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4621 | * |
| 4622 | * @deprecated Use the new {@link DialogFragment} class with |
| 4623 | * {@link FragmentManager} instead; this is also |
| 4624 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4625 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4626 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4627 | public final void removeDialog(int id) { |
Dianne Hackborn | d2ce8bbb | 2010-10-06 16:46:05 -0700 | [diff] [blame] | 4628 | if (mManagedDialogs != null) { |
| 4629 | final ManagedDialog md = mManagedDialogs.get(id); |
| 4630 | if (md != null) { |
| 4631 | md.mDialog.dismiss(); |
| 4632 | mManagedDialogs.remove(id); |
| 4633 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4634 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4635 | } |
| 4636 | |
| 4637 | /** |
| 4638 | * 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] | 4639 | * |
Bjorn Bringert | 6266e40 | 2009-09-25 14:25:41 +0100 | [diff] [blame] | 4640 | * <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] | 4641 | * menu item, search button, or other widgets within your activity. Unless overidden, |
Bjorn Bringert | 6266e40 | 2009-09-25 14:25:41 +0100 | [diff] [blame] | 4642 | * calling this function is the same as calling |
| 4643 | * {@link #startSearch startSearch(null, false, null, false)}, which launches |
| 4644 | * search for the current activity as specified in its manifest, see {@link SearchManager}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4645 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4646 | * <p>You can override this function to force global search, e.g. in response to a dedicated |
| 4647 | * search key, or to block search entirely (by simply returning false). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4648 | * |
Erik Wolsheimer | ac5cecd | 2017-12-05 13:11:50 -0800 | [diff] [blame] | 4649 | * <p>Note: when running in a {@link Configuration#UI_MODE_TYPE_TELEVISION} or |
| 4650 | * {@link Configuration#UI_MODE_TYPE_WATCH}, the default implementation changes to simply |
| 4651 | * return false and you must supply your own custom implementation if you want to support |
| 4652 | * search. |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 4653 | * |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 4654 | * @param searchEvent The {@link SearchEvent} that signaled this search. |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 4655 | * @return Returns {@code true} if search launched, and {@code false} if the activity does |
| 4656 | * not respond to search. The default implementation always returns {@code true}, except |
| 4657 | * when in {@link Configuration#UI_MODE_TYPE_TELEVISION} mode where it returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4658 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4659 | * @see android.app.SearchManager |
| 4660 | */ |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 4661 | public boolean onSearchRequested(@Nullable SearchEvent searchEvent) { |
| 4662 | mSearchEvent = searchEvent; |
| 4663 | boolean result = onSearchRequested(); |
| 4664 | mSearchEvent = null; |
| 4665 | return result; |
| 4666 | } |
| 4667 | |
| 4668 | /** |
| 4669 | * @see #onSearchRequested(SearchEvent) |
| 4670 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4671 | public boolean onSearchRequested() { |
Erik Wolsheimer | ac5cecd | 2017-12-05 13:11:50 -0800 | [diff] [blame] | 4672 | final int uiMode = getResources().getConfiguration().uiMode |
| 4673 | & Configuration.UI_MODE_TYPE_MASK; |
| 4674 | if (uiMode != Configuration.UI_MODE_TYPE_TELEVISION |
| 4675 | && uiMode != Configuration.UI_MODE_TYPE_WATCH) { |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 4676 | startSearch(null, false, null, false); |
| 4677 | return true; |
| 4678 | } else { |
| 4679 | return false; |
| 4680 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4681 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4682 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4683 | /** |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 4684 | * During the onSearchRequested() callbacks, this function will return the |
| 4685 | * {@link SearchEvent} that triggered the callback, if it exists. |
| 4686 | * |
| 4687 | * @return SearchEvent The SearchEvent that triggered the {@link |
| 4688 | * #onSearchRequested} callback. |
| 4689 | */ |
| 4690 | public final SearchEvent getSearchEvent() { |
| 4691 | return mSearchEvent; |
| 4692 | } |
| 4693 | |
| 4694 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4695 | * This hook is called to launch the search UI. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4696 | * |
| 4697 | * <p>It is typically called from onSearchRequested(), either directly from |
| 4698 | * 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] | 4699 | * 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] | 4700 | * 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] | 4701 | * is to inject specific data such as context data, it is preferred to <i>override</i> |
| 4702 | * onSearchRequested(), so that any callers to it will benefit from the override. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4703 | * |
Erik Wolsheimer | ac5cecd | 2017-12-05 13:11:50 -0800 | [diff] [blame] | 4704 | * <p>Note: when running in a {@link Configuration#UI_MODE_TYPE_WATCH}, use of this API is |
| 4705 | * not supported. |
| 4706 | * |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4707 | * @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] | 4708 | * pre-entered text in the search query box. |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4709 | * @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] | 4710 | * any further typing will replace it. This is useful for cases where an entire pre-formed |
| 4711 | * query is being inserted. If false, the selection point will be placed at the end of the |
| 4712 | * inserted query. This is useful when the inserted query is text that the user entered, |
| 4713 | * and the user would expect to be able to keep typing. <i>This parameter is only meaningful |
| 4714 | * if initialQuery is a non-empty string.</i> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4715 | * @param appSearchData An application can insert application-specific |
| 4716 | * 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] | 4717 | * searches. This data will be returned with SEARCH intent(s). Null if |
| 4718 | * no extra data is required. |
| 4719 | * @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] | 4720 | * 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] | 4721 | * 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] | 4722 | * 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] | 4723 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4724 | * @see android.app.SearchManager |
| 4725 | * @see #onSearchRequested |
| 4726 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4727 | public void startSearch(@Nullable String initialQuery, boolean selectInitialQuery, |
| 4728 | @Nullable Bundle appSearchData, boolean globalSearch) { |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 4729 | ensureSearchManager(); |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 4730 | mSearchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4731 | appSearchData, globalSearch); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4732 | } |
| 4733 | |
| 4734 | /** |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4735 | * Similar to {@link #startSearch}, but actually fires off the search query after invoking |
| 4736 | * the search dialog. Made available for testing purposes. |
| 4737 | * |
| 4738 | * @param query The query to trigger. If empty, the request will be ignored. |
| 4739 | * @param appSearchData An application can insert application-specific |
| 4740 | * context here, in order to improve quality or specificity of its own |
| 4741 | * searches. This data will be returned with SEARCH intent(s). Null if |
| 4742 | * no extra data is required. |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4743 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4744 | public void triggerSearch(String query, @Nullable Bundle appSearchData) { |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4745 | ensureSearchManager(); |
Bjorn Bringert | b782a2f | 2009-10-01 09:57:33 +0100 | [diff] [blame] | 4746 | mSearchManager.triggerSearch(query, getComponentName(), appSearchData); |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4750 | * Request that key events come to this activity. Use this if your |
| 4751 | * activity has no views with focus, but the activity still wants |
| 4752 | * a chance to process key events. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4753 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4754 | * @see android.view.Window#takeKeyEvents |
| 4755 | */ |
| 4756 | public void takeKeyEvents(boolean get) { |
| 4757 | getWindow().takeKeyEvents(get); |
| 4758 | } |
| 4759 | |
| 4760 | /** |
| 4761 | * Enable extended window features. This is a convenience for calling |
| 4762 | * {@link android.view.Window#requestFeature getWindow().requestFeature()}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4763 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4764 | * @param featureId The desired feature as defined in |
| 4765 | * {@link android.view.Window}. |
| 4766 | * @return Returns true if the requested feature is supported and now |
| 4767 | * enabled. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4768 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4769 | * @see android.view.Window#requestFeature |
| 4770 | */ |
| 4771 | public final boolean requestWindowFeature(int featureId) { |
| 4772 | return getWindow().requestFeature(featureId); |
| 4773 | } |
| 4774 | |
| 4775 | /** |
| 4776 | * Convenience for calling |
| 4777 | * {@link android.view.Window#setFeatureDrawableResource}. |
| 4778 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 4779 | public final void setFeatureDrawableResource(int featureId, @DrawableRes int resId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4780 | getWindow().setFeatureDrawableResource(featureId, resId); |
| 4781 | } |
| 4782 | |
| 4783 | /** |
| 4784 | * Convenience for calling |
| 4785 | * {@link android.view.Window#setFeatureDrawableUri}. |
| 4786 | */ |
| 4787 | public final void setFeatureDrawableUri(int featureId, Uri uri) { |
| 4788 | getWindow().setFeatureDrawableUri(featureId, uri); |
| 4789 | } |
| 4790 | |
| 4791 | /** |
| 4792 | * Convenience for calling |
| 4793 | * {@link android.view.Window#setFeatureDrawable(int, Drawable)}. |
| 4794 | */ |
| 4795 | public final void setFeatureDrawable(int featureId, Drawable drawable) { |
| 4796 | getWindow().setFeatureDrawable(featureId, drawable); |
| 4797 | } |
| 4798 | |
| 4799 | /** |
| 4800 | * Convenience for calling |
| 4801 | * {@link android.view.Window#setFeatureDrawableAlpha}. |
| 4802 | */ |
| 4803 | public final void setFeatureDrawableAlpha(int featureId, int alpha) { |
| 4804 | getWindow().setFeatureDrawableAlpha(featureId, alpha); |
| 4805 | } |
| 4806 | |
| 4807 | /** |
| 4808 | * Convenience for calling |
| 4809 | * {@link android.view.Window#getLayoutInflater}. |
| 4810 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4811 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4812 | public LayoutInflater getLayoutInflater() { |
| 4813 | return getWindow().getLayoutInflater(); |
| 4814 | } |
| 4815 | |
| 4816 | /** |
| 4817 | * Returns a {@link MenuInflater} with this context. |
| 4818 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4819 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4820 | public MenuInflater getMenuInflater() { |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 4821 | // Make sure that action views can get an appropriate theme. |
| 4822 | if (mMenuInflater == null) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 4823 | initWindowDecorActionBar(); |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 4824 | if (mActionBar != null) { |
Dianne Hackborn | 9275197 | 2012-05-18 19:22:14 -0700 | [diff] [blame] | 4825 | mMenuInflater = new MenuInflater(mActionBar.getThemedContext(), this); |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 4826 | } else { |
| 4827 | mMenuInflater = new MenuInflater(this); |
| 4828 | } |
| 4829 | } |
| 4830 | return mMenuInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4831 | } |
| 4832 | |
| 4833 | @Override |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 4834 | public void setTheme(int resid) { |
| 4835 | super.setTheme(resid); |
| 4836 | mWindow.setTheme(resid); |
| 4837 | } |
| 4838 | |
| 4839 | @Override |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 4840 | protected void onApplyThemeResource(Resources.Theme theme, @StyleRes int resid, |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4841 | boolean first) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4842 | if (mParent == null) { |
| 4843 | super.onApplyThemeResource(theme, resid, first); |
| 4844 | } else { |
| 4845 | try { |
| 4846 | theme.setTo(mParent.getTheme()); |
| 4847 | } catch (Exception e) { |
| 4848 | // Empty |
| 4849 | } |
| 4850 | theme.applyStyle(resid, false); |
| 4851 | } |
Winson | 073a526 | 2016-02-29 16:04:40 -0800 | [diff] [blame] | 4852 | |
| 4853 | // Get the primary color and update the TaskDescription for this activity |
| 4854 | TypedArray a = theme.obtainStyledAttributes( |
| 4855 | com.android.internal.R.styleable.ActivityTaskDescription); |
| 4856 | if (mTaskDescription.getPrimaryColor() == 0) { |
| 4857 | int colorPrimary = a.getColor( |
| 4858 | com.android.internal.R.styleable.ActivityTaskDescription_colorPrimary, 0); |
| 4859 | if (colorPrimary != 0 && Color.alpha(colorPrimary) == 0xFF) { |
| 4860 | mTaskDescription.setPrimaryColor(colorPrimary); |
| 4861 | } |
| 4862 | } |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 4863 | |
| 4864 | int colorBackground = a.getColor( |
| 4865 | com.android.internal.R.styleable.ActivityTaskDescription_colorBackground, 0); |
| 4866 | if (colorBackground != 0 && Color.alpha(colorBackground) == 0xFF) { |
| 4867 | mTaskDescription.setBackgroundColor(colorBackground); |
Winson | 073a526 | 2016-02-29 16:04:40 -0800 | [diff] [blame] | 4868 | } |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 4869 | |
| 4870 | final int statusBarColor = a.getColor( |
| 4871 | com.android.internal.R.styleable.ActivityTaskDescription_statusBarColor, 0); |
| 4872 | if (statusBarColor != 0) { |
| 4873 | mTaskDescription.setStatusBarColor(statusBarColor); |
| 4874 | } |
| 4875 | |
| 4876 | final int navigationBarColor = a.getColor( |
| 4877 | com.android.internal.R.styleable.ActivityTaskDescription_navigationBarColor, 0); |
| 4878 | if (navigationBarColor != 0) { |
| 4879 | mTaskDescription.setNavigationBarColor(navigationBarColor); |
| 4880 | } |
| 4881 | |
Winson | 073a526 | 2016-02-29 16:04:40 -0800 | [diff] [blame] | 4882 | a.recycle(); |
| 4883 | setTaskDescription(mTaskDescription); |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 4884 | } |
| 4885 | |
| 4886 | /** |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4887 | * Requests permissions to be granted to this application. These permissions |
| 4888 | * 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] | 4889 | * and they should have protection level {@link |
| 4890 | * android.content.pm.PermissionInfo#PROTECTION_DANGEROUS dangerous}, regardless |
| 4891 | * whether they are declared by the platform or a third-party app. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4892 | * <p> |
| 4893 | * Normal permissions {@link android.content.pm.PermissionInfo#PROTECTION_NORMAL} |
| 4894 | * are granted at install time if requested in the manifest. Signature permissions |
| 4895 | * {@link android.content.pm.PermissionInfo#PROTECTION_SIGNATURE} are granted at |
| 4896 | * install time if requested in the manifest and the signature of your app matches |
| 4897 | * the signature of the app declaring the permissions. |
| 4898 | * </p> |
| 4899 | * <p> |
| 4900 | * If your app does not have the requested permissions the user will be presented |
| 4901 | * with UI for accepting them. After the user has accepted or rejected the |
| 4902 | * requested permissions you will receive a callback on {@link |
| 4903 | * #onRequestPermissionsResult(int, String[], int[])} reporting whether the |
| 4904 | * permissions were granted or not. |
| 4905 | * </p> |
| 4906 | * <p> |
| 4907 | * Note that requesting a permission does not guarantee it will be granted and |
| 4908 | * your app should be able to run without having this permission. |
| 4909 | * </p> |
| 4910 | * <p> |
| 4911 | * This method may start an activity allowing the user to choose which permissions |
| 4912 | * to grant and which to reject. Hence, you should be prepared that your activity |
| 4913 | * may be paused and resumed. Further, granting some permissions may require |
| 4914 | * a restart of you application. In such a case, the system will recreate the |
| 4915 | * activity stack before delivering the result to {@link |
| 4916 | * #onRequestPermissionsResult(int, String[], int[])}. |
| 4917 | * </p> |
| 4918 | * <p> |
| 4919 | * When checking whether you have a permission you should use {@link |
| 4920 | * #checkSelfPermission(String)}. |
| 4921 | * </p> |
| 4922 | * <p> |
Svet Ganov | d7ad54e | 2015-08-21 06:18:09 -0700 | [diff] [blame] | 4923 | * Calling this API for permissions already granted to your app would show UI |
| 4924 | * to the user to decide whether the app can still hold these permissions. This |
| 4925 | * can be useful if the way your app uses data guarded by the permissions |
| 4926 | * changes significantly. |
| 4927 | * </p> |
| 4928 | * <p> |
Svet Ganov | 255aece | 2015-07-03 16:03:53 -0700 | [diff] [blame] | 4929 | * You cannot request a permission if your activity sets {@link |
| 4930 | * android.R.styleable#AndroidManifestActivity_noHistory noHistory} to |
| 4931 | * <code>true</code> because in this case the activity would not receive |
| 4932 | * result callbacks including {@link #onRequestPermissionsResult(int, String[], int[])}. |
| 4933 | * </p> |
| 4934 | * <p> |
Peter Visontay | 2c6b6c4 | 2018-06-14 14:47:12 +0100 | [diff] [blame] | 4935 | * The <a href="https://github.com/googlesamples/android-RuntimePermissions"> |
Trevor Johns | 682c24e | 2016-04-12 10:13:47 -0700 | [diff] [blame] | 4936 | * RuntimePermissions</a> sample app demonstrates how to use this method to |
| 4937 | * request permissions at run time. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4938 | * </p> |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4939 | * |
Svet Ganov | f66381c | 2016-02-18 20:02:36 -0800 | [diff] [blame] | 4940 | * @param permissions The requested permissions. Must me non-null and not empty. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4941 | * @param requestCode Application specific request code to match with a result |
| 4942 | * reported to {@link #onRequestPermissionsResult(int, String[], int[])}. |
Svet Ganov | 255aece | 2015-07-03 16:03:53 -0700 | [diff] [blame] | 4943 | * Should be >= 0. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4944 | * |
Paul Miller | 77a0e13 | 2016-02-11 13:46:49 -0800 | [diff] [blame] | 4945 | * @throws IllegalArgumentException if requestCode is negative. |
| 4946 | * |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4947 | * @see #onRequestPermissionsResult(int, String[], int[]) |
| 4948 | * @see #checkSelfPermission(String) |
Svetoslav | aa048b6 | 2015-06-02 15:08:48 -0700 | [diff] [blame] | 4949 | * @see #shouldShowRequestPermissionRationale(String) |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4950 | */ |
| 4951 | public final void requestPermissions(@NonNull String[] permissions, int requestCode) { |
Paul Miller | 77a0e13 | 2016-02-11 13:46:49 -0800 | [diff] [blame] | 4952 | if (requestCode < 0) { |
| 4953 | throw new IllegalArgumentException("requestCode should be >= 0"); |
| 4954 | } |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 4955 | if (mHasCurrentPermissionsRequest) { |
Ahmad Melegy | e2bfbf1 | 2017-11-14 21:27:28 +0000 | [diff] [blame] | 4956 | Log.w(TAG, "Can request only one set of permissions at a time"); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 4957 | // Dispatch the callback with empty arrays which means a cancellation. |
| 4958 | onRequestPermissionsResult(requestCode, new String[0], new int[0]); |
| 4959 | return; |
| 4960 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4961 | Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions); |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 4962 | startActivityForResult(REQUEST_PERMISSIONS_WHO_PREFIX, intent, requestCode, null); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 4963 | mHasCurrentPermissionsRequest = true; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4964 | } |
| 4965 | |
| 4966 | /** |
| 4967 | * Callback for the result from requesting permissions. This method |
| 4968 | * is invoked for every call on {@link #requestPermissions(String[], int)}. |
Svet Ganov | 0f45c7c | 2015-07-16 16:28:51 -0700 | [diff] [blame] | 4969 | * <p> |
| 4970 | * <strong>Note:</strong> It is possible that the permissions request interaction |
| 4971 | * with the user is interrupted. In this case you will receive empty permissions |
| 4972 | * and results arrays which should be treated as a cancellation. |
| 4973 | * </p> |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4974 | * |
| 4975 | * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}. |
| 4976 | * @param permissions The requested permissions. Never null. |
| 4977 | * @param grantResults The grant results for the corresponding permissions |
| 4978 | * which is either {@link android.content.pm.PackageManager#PERMISSION_GRANTED} |
| 4979 | * or {@link android.content.pm.PackageManager#PERMISSION_DENIED}. Never null. |
| 4980 | * |
| 4981 | * @see #requestPermissions(String[], int) |
| 4982 | */ |
| 4983 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, |
| 4984 | @NonNull int[] grantResults) { |
| 4985 | /* callback - no nothing */ |
| 4986 | } |
| 4987 | |
| 4988 | /** |
Svetoslav | 20770dd | 2015-05-29 15:43:04 -0700 | [diff] [blame] | 4989 | * Gets whether you should show UI with rationale for requesting a permission. |
| 4990 | * You should do this only if you do not have the permission and the context in |
| 4991 | * which the permission is requested does not clearly communicate to the user |
| 4992 | * what would be the benefit from granting this permission. |
| 4993 | * <p> |
| 4994 | * For example, if you write a camera app, requesting the camera permission |
| 4995 | * would be expected by the user and no rationale for why it is requested is |
| 4996 | * needed. If however, the app needs location for tagging photos then a non-tech |
| 4997 | * savvy user may wonder how location is related to taking photos. In this case |
| 4998 | * you may choose to show UI with rationale of requesting this permission. |
| 4999 | * </p> |
| 5000 | * |
| 5001 | * @param permission A permission your app wants to request. |
| 5002 | * @return Whether you can show permission rationale UI. |
| 5003 | * |
| 5004 | * @see #checkSelfPermission(String) |
| 5005 | * @see #requestPermissions(String[], int) |
| 5006 | * @see #onRequestPermissionsResult(int, String[], int[]) |
| 5007 | */ |
Svetoslav | 9ce9a15 | 2015-06-02 17:59:31 -0700 | [diff] [blame] | 5008 | public boolean shouldShowRequestPermissionRationale(@NonNull String permission) { |
Svetoslav | 20770dd | 2015-05-29 15:43:04 -0700 | [diff] [blame] | 5009 | return getPackageManager().shouldShowRequestPermissionRationale(permission); |
| 5010 | } |
| 5011 | |
| 5012 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5013 | * Same as calling {@link #startActivityForResult(Intent, int, Bundle)} |
| 5014 | * with no options. |
| 5015 | * |
| 5016 | * @param intent The intent to start. |
| 5017 | * @param requestCode If >= 0, this code will be returned in |
| 5018 | * onActivityResult() when the activity exits. |
| 5019 | * |
| 5020 | * @throws android.content.ActivityNotFoundException |
| 5021 | * |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 5022 | * @see #startActivity |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5023 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5024 | public void startActivityForResult(@RequiresPermission Intent intent, int requestCode) { |
George Mount | abb63cb | 2014-06-23 11:17:58 -0700 | [diff] [blame] | 5025 | startActivityForResult(intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5026 | } |
| 5027 | |
| 5028 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5029 | * Launch an activity for which you would like a result when it finished. |
| 5030 | * When this activity exits, your |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 5031 | * onActivityResult() method will be called with the given requestCode. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5032 | * Using a negative requestCode is the same as calling |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | * {@link #startActivity} (the activity is not launched as a sub-activity). |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5034 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5035 | * <p>Note that this method should only be used with Intent protocols |
| 5036 | * that are defined to return a result. In other protocols (such as |
| 5037 | * {@link Intent#ACTION_MAIN} or {@link Intent#ACTION_VIEW}), you may |
| 5038 | * 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] | 5039 | * are launching uses {@link Intent#FLAG_ACTIVITY_NEW_TASK}, it will not |
| 5040 | * 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] | 5041 | * |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5042 | * <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] | 5043 | * >= 0 during the initial onCreate(Bundle savedInstanceState)/onResume() of your |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 5044 | * activity, then your window will not be displayed until a result is |
| 5045 | * returned back from the started activity. This is to avoid visible |
| 5046 | * flickering when redirecting to another activity. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5047 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5048 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 5049 | * if there was no Activity found to run the given Intent. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5050 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5051 | * @param intent The intent to start. |
| 5052 | * @param requestCode If >= 0, this code will be returned in |
| 5053 | * onActivityResult() when the activity exits. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5054 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5055 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5056 | * Context.startActivity(Intent, Bundle)} for more details. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5057 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5058 | * @throws android.content.ActivityNotFoundException |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5059 | * |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 5060 | * @see #startActivity |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5061 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5062 | public void startActivityForResult(@RequiresPermission Intent intent, int requestCode, |
| 5063 | @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5064 | if (mParent == null) { |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5065 | options = transferSpringboardActivityOptions(options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5066 | Instrumentation.ActivityResult ar = |
| 5067 | mInstrumentation.execStartActivity( |
| 5068 | this, mMainThread.getApplicationThread(), mToken, this, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5069 | intent, requestCode, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5070 | if (ar != null) { |
| 5071 | mMainThread.sendActivityResult( |
| 5072 | mToken, mEmbeddedID, requestCode, ar.getResultCode(), |
| 5073 | ar.getResultData()); |
| 5074 | } |
| 5075 | if (requestCode >= 0) { |
| 5076 | // If this start is requesting a result, we can avoid making |
| 5077 | // the activity visible until the result is received. Setting |
| 5078 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 5079 | // activity hidden during this time, to avoid flickering. |
| 5080 | // This can only be done when a result is requested because |
| 5081 | // that guarantees we will get information back when the |
| 5082 | // activity is finished, no matter what happens to it. |
| 5083 | mStartedActivity = true; |
| 5084 | } |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 5085 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5086 | cancelInputsAndStartExitTransition(options); |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 5087 | // 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] | 5088 | } else { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5089 | if (options != null) { |
| 5090 | mParent.startActivityFromChild(this, intent, requestCode, options); |
| 5091 | } else { |
| 5092 | // Note we want to go through this method for compatibility with |
| 5093 | // existing applications that may have overridden it. |
| 5094 | mParent.startActivityFromChild(this, intent, requestCode); |
| 5095 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5096 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5097 | } |
| 5098 | |
| 5099 | /** |
| 5100 | * Cancels pending inputs and if an Activity Transition is to be run, starts the transition. |
| 5101 | * |
| 5102 | * @param options The ActivityOptions bundle used to start an Activity. |
| 5103 | */ |
| 5104 | private void cancelInputsAndStartExitTransition(Bundle options) { |
| 5105 | final View decor = mWindow != null ? mWindow.peekDecorView() : null; |
| 5106 | if (decor != null) { |
| 5107 | decor.cancelPendingInputEvents(); |
| 5108 | } |
Sunny Goyal | d85bed5 | 2018-09-25 12:01:01 -0700 | [diff] [blame] | 5109 | if (options != null) { |
George Mount | ff24328 | 2014-07-07 16:12:07 -0700 | [diff] [blame] | 5110 | mActivityTransitionState.startExitOutTransition(this, options); |
| 5111 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5112 | } |
| 5113 | |
Chet Haase | b64e777f | 2016-12-09 07:17:10 -0800 | [diff] [blame] | 5114 | /** |
| 5115 | * Returns whether there are any activity transitions currently running on this |
| 5116 | * activity. A return value of {@code true} can mean that either an enter or |
| 5117 | * exit transition is running, including whether the background of the activity |
| 5118 | * is animating as a part of that transition. |
| 5119 | * |
| 5120 | * @return true if a transition is currently running on this activity, false otherwise. |
| 5121 | */ |
| 5122 | public boolean isActivityTransitionRunning() { |
| 5123 | return mActivityTransitionState.isTransitionRunning(); |
| 5124 | } |
| 5125 | |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5126 | private Bundle transferSpringboardActivityOptions(Bundle options) { |
| 5127 | if (options == null && (mWindow != null && !mWindow.isActive())) { |
| 5128 | final ActivityOptions activityOptions = getActivityOptions(); |
George Mount | 9638378 | 2016-06-08 15:13:52 -0700 | [diff] [blame] | 5129 | if (activityOptions != null && |
| 5130 | activityOptions.getAnimationType() == ActivityOptions.ANIM_SCENE_TRANSITION) { |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5131 | return activityOptions.toBundle(); |
| 5132 | } |
| 5133 | } |
| 5134 | return options; |
| 5135 | } |
| 5136 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5137 | /** |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 5138 | * @hide Implement to provide correct calling token. |
| 5139 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5140 | @UnsupportedAppUsage |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 5141 | public void startActivityForResultAsUser(Intent intent, int requestCode, UserHandle user) { |
| 5142 | startActivityForResultAsUser(intent, requestCode, null, user); |
| 5143 | } |
| 5144 | |
| 5145 | /** |
| 5146 | * @hide Implement to provide correct calling token. |
| 5147 | */ |
| 5148 | public void startActivityForResultAsUser(Intent intent, int requestCode, |
| 5149 | @Nullable Bundle options, UserHandle user) { |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 5150 | startActivityForResultAsUser(intent, mEmbeddedID, requestCode, options, user); |
| 5151 | } |
| 5152 | |
| 5153 | /** |
| 5154 | * @hide Implement to provide correct calling token. |
| 5155 | */ |
| 5156 | public void startActivityForResultAsUser(Intent intent, String resultWho, int requestCode, |
| 5157 | @Nullable Bundle options, UserHandle user) { |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 5158 | if (mParent != null) { |
| 5159 | throw new RuntimeException("Can't be called from a child"); |
| 5160 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5161 | options = transferSpringboardActivityOptions(options); |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 5162 | Instrumentation.ActivityResult ar = mInstrumentation.execStartActivity( |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 5163 | this, mMainThread.getApplicationThread(), mToken, resultWho, intent, requestCode, |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 5164 | options, user); |
| 5165 | if (ar != null) { |
| 5166 | mMainThread.sendActivityResult( |
| 5167 | mToken, mEmbeddedID, requestCode, ar.getResultCode(), ar.getResultData()); |
| 5168 | } |
| 5169 | if (requestCode >= 0) { |
| 5170 | // If this start is requesting a result, we can avoid making |
| 5171 | // the activity visible until the result is received. Setting |
| 5172 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 5173 | // activity hidden during this time, to avoid flickering. |
| 5174 | // This can only be done when a result is requested because |
| 5175 | // that guarantees we will get information back when the |
| 5176 | // activity is finished, no matter what happens to it. |
| 5177 | mStartedActivity = true; |
| 5178 | } |
| 5179 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5180 | cancelInputsAndStartExitTransition(options); |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 5181 | } |
| 5182 | |
| 5183 | /** |
| 5184 | * @hide Implement to provide correct calling token. |
| 5185 | */ |
Philip P. Moltmann | 4e615e6 | 2018-08-28 14:57:49 -0700 | [diff] [blame] | 5186 | @Override |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 5187 | public void startActivityAsUser(Intent intent, UserHandle user) { |
| 5188 | startActivityAsUser(intent, null, user); |
| 5189 | } |
| 5190 | |
| 5191 | /** |
| 5192 | * @hide Implement to provide correct calling token. |
| 5193 | */ |
| 5194 | public void startActivityAsUser(Intent intent, Bundle options, UserHandle user) { |
| 5195 | if (mParent != null) { |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 5196 | throw new RuntimeException("Can't be called from a child"); |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 5197 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5198 | options = transferSpringboardActivityOptions(options); |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 5199 | Instrumentation.ActivityResult ar = |
| 5200 | mInstrumentation.execStartActivity( |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 5201 | this, mMainThread.getApplicationThread(), mToken, mEmbeddedID, |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 5202 | intent, -1, options, user); |
| 5203 | if (ar != null) { |
| 5204 | mMainThread.sendActivityResult( |
| 5205 | mToken, mEmbeddedID, -1, ar.getResultCode(), |
| 5206 | ar.getResultData()); |
| 5207 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5208 | cancelInputsAndStartExitTransition(options); |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 5209 | } |
| 5210 | |
| 5211 | /** |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 5212 | * Start a new activity as if it was started by the activity that started our |
| 5213 | * current activity. This is for the resolver and chooser activities, which operate |
| 5214 | * as intermediaries that dispatch their intent to the target the user selects -- to |
| 5215 | * do this, they must perform all security checks including permission grants as if |
| 5216 | * their launch had come from the original activity. |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 5217 | * @param intent The Intent to start. |
| 5218 | * @param options ActivityOptions or null. |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5219 | * @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] | 5220 | * @param ignoreTargetSecurity If true, the activity manager will not check whether the |
| 5221 | * caller it is doing the start is, is actually allowed to start the target activity. |
| 5222 | * If you set this to true, you must set an explicit component in the Intent and do any |
| 5223 | * appropriate security checks yourself. |
| 5224 | * @param userId The user the new activity should run as. |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 5225 | * @hide |
| 5226 | */ |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 5227 | public void startActivityAsCaller(Intent intent, @Nullable Bundle options, |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5228 | IBinder permissionToken, boolean ignoreTargetSecurity, int userId) { |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 5229 | if (mParent != null) { |
| 5230 | throw new RuntimeException("Can't be called from a child"); |
| 5231 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5232 | options = transferSpringboardActivityOptions(options); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 5233 | Instrumentation.ActivityResult ar = |
| 5234 | mInstrumentation.execStartActivityAsCaller( |
| 5235 | this, mMainThread.getApplicationThread(), mToken, this, |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5236 | intent, -1, options, permissionToken, ignoreTargetSecurity, userId); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 5237 | if (ar != null) { |
| 5238 | mMainThread.sendActivityResult( |
| 5239 | mToken, mEmbeddedID, -1, ar.getResultCode(), |
| 5240 | ar.getResultData()); |
| 5241 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5242 | cancelInputsAndStartExitTransition(options); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 5243 | } |
| 5244 | |
| 5245 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5246 | * Same as calling {@link #startIntentSenderForResult(IntentSender, int, |
| 5247 | * Intent, int, int, int, Bundle)} with no options. |
| 5248 | * |
| 5249 | * @param intent The IntentSender to launch. |
| 5250 | * @param requestCode If >= 0, this code will be returned in |
| 5251 | * onActivityResult() when the activity exits. |
| 5252 | * @param fillInIntent If non-null, this will be provided as the |
| 5253 | * intent parameter to {@link IntentSender#sendIntent}. |
| 5254 | * @param flagsMask Intent flags in the original IntentSender that you |
| 5255 | * would like to change. |
| 5256 | * @param flagsValues Desired values for any bits set in |
| 5257 | * <var>flagsMask</var> |
| 5258 | * @param extraFlags Always set to 0. |
| 5259 | */ |
| 5260 | public void startIntentSenderForResult(IntentSender intent, int requestCode, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5261 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5262 | throws IntentSender.SendIntentException { |
| 5263 | startIntentSenderForResult(intent, requestCode, fillInIntent, flagsMask, |
| 5264 | flagsValues, extraFlags, null); |
| 5265 | } |
| 5266 | |
| 5267 | /** |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5268 | * Like {@link #startActivityForResult(Intent, int)}, but allowing you |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5269 | * to use a IntentSender to describe the activity to be started. If |
| 5270 | * the IntentSender is for an activity, that activity will be started |
| 5271 | * as if you had called the regular {@link #startActivityForResult(Intent, int)} |
| 5272 | * here; otherwise, its associated action will be executed (such as |
| 5273 | * sending a broadcast) as if you had called |
| 5274 | * {@link IntentSender#sendIntent IntentSender.sendIntent} on it. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5275 | * |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5276 | * @param intent The IntentSender to launch. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5277 | * @param requestCode If >= 0, this code will be returned in |
| 5278 | * onActivityResult() when the activity exits. |
| 5279 | * @param fillInIntent If non-null, this will be provided as the |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5280 | * intent parameter to {@link IntentSender#sendIntent}. |
| 5281 | * @param flagsMask Intent flags in the original IntentSender that you |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5282 | * would like to change. |
| 5283 | * @param flagsValues Desired values for any bits set in |
| 5284 | * <var>flagsMask</var> |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5285 | * @param extraFlags Always set to 0. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5286 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5287 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5288 | * Context.startActivity(Intent, Bundle)} for more details. If options |
| 5289 | * have also been supplied by the IntentSender, options given here will |
| 5290 | * override any that conflict with those given by the IntentSender. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5291 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5292 | public void startIntentSenderForResult(IntentSender intent, int requestCode, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5293 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5294 | Bundle options) throws IntentSender.SendIntentException { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5295 | if (mParent == null) { |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 5296 | startIntentSenderForResultInner(intent, mEmbeddedID, requestCode, fillInIntent, |
| 5297 | flagsMask, flagsValues, options); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5298 | } else if (options != null) { |
| 5299 | mParent.startIntentSenderFromChild(this, intent, requestCode, |
| 5300 | fillInIntent, flagsMask, flagsValues, extraFlags, options); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5301 | } else { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5302 | // Note we want to go through this call for compatibility with |
| 5303 | // existing applications that may have overridden the method. |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5304 | mParent.startIntentSenderFromChild(this, intent, requestCode, |
| 5305 | fillInIntent, flagsMask, flagsValues, extraFlags); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5306 | } |
| 5307 | } |
| 5308 | |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 5309 | private void startIntentSenderForResultInner(IntentSender intent, String who, int requestCode, |
| 5310 | Intent fillInIntent, int flagsMask, int flagsValues, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5311 | Bundle options) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5312 | throws IntentSender.SendIntentException { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5313 | try { |
Sunny Goyal | d85bed5 | 2018-09-25 12:01:01 -0700 | [diff] [blame] | 5314 | options = transferSpringboardActivityOptions(options); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5315 | String resolvedType = null; |
| 5316 | if (fillInIntent != null) { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 5317 | fillInIntent.migrateExtraStreamToClipData(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5318 | fillInIntent.prepareToLeaveProcess(this); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5319 | resolvedType = fillInIntent.resolveTypeIfNeeded(getContentResolver()); |
| 5320 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 5321 | int result = ActivityTaskManager.getService() |
Dianne Hackborn | 3e6e385 | 2017-05-19 16:12:08 -0700 | [diff] [blame] | 5322 | .startActivityIntentSender(mMainThread.getApplicationThread(), |
| 5323 | intent != null ? intent.getTarget() : null, |
| 5324 | intent != null ? intent.getWhitelistToken() : null, |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 5325 | fillInIntent, resolvedType, mToken, who, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5326 | requestCode, flagsMask, flagsValues, options); |
| 5327 | if (result == ActivityManager.START_CANCELED) { |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5328 | throw new IntentSender.SendIntentException(); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5329 | } |
| 5330 | Instrumentation.checkStartActivityResult(result, null); |
Sunny Goyal | d85bed5 | 2018-09-25 12:01:01 -0700 | [diff] [blame] | 5331 | |
| 5332 | if (options != null) { |
| 5333 | // Only when the options are not null, as the intent can point to something other |
| 5334 | // than an Activity. |
| 5335 | cancelInputsAndStartExitTransition(options); |
| 5336 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5337 | } catch (RemoteException e) { |
| 5338 | } |
| 5339 | if (requestCode >= 0) { |
| 5340 | // If this start is requesting a result, we can avoid making |
| 5341 | // the activity visible until the result is received. Setting |
| 5342 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 5343 | // activity hidden during this time, to avoid flickering. |
| 5344 | // This can only be done when a result is requested because |
| 5345 | // that guarantees we will get information back when the |
| 5346 | // activity is finished, no matter what happens to it. |
| 5347 | mStartedActivity = true; |
| 5348 | } |
| 5349 | } |
| 5350 | |
| 5351 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5352 | * Same as {@link #startActivity(Intent, Bundle)} with no options |
| 5353 | * specified. |
| 5354 | * |
| 5355 | * @param intent The intent to start. |
| 5356 | * |
| 5357 | * @throws android.content.ActivityNotFoundException |
| 5358 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 5359 | * @see #startActivity(Intent, Bundle) |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5360 | * @see #startActivityForResult |
| 5361 | */ |
| 5362 | @Override |
| 5363 | public void startActivity(Intent intent) { |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 5364 | this.startActivity(intent, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5368 | * Launch a new activity. You will not receive any information about when |
| 5369 | * the activity exits. This implementation overrides the base version, |
| 5370 | * providing information about |
| 5371 | * the activity performing the launch. Because of this additional |
| 5372 | * information, the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag is not |
| 5373 | * required; if not specified, the new activity will be added to the |
| 5374 | * task of the caller. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5375 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5376 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 5377 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5378 | * |
| 5379 | * @param intent The intent to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5380 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5381 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5382 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5383 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5384 | * @throws android.content.ActivityNotFoundException |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5385 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 5386 | * @see #startActivity(Intent) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5387 | * @see #startActivityForResult |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5388 | */ |
| 5389 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5390 | public void startActivity(Intent intent, @Nullable Bundle options) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5391 | if (options != null) { |
| 5392 | startActivityForResult(intent, -1, options); |
| 5393 | } else { |
| 5394 | // Note we want to go through this call for compatibility with |
| 5395 | // applications that may have overridden the method. |
| 5396 | startActivityForResult(intent, -1); |
| 5397 | } |
| 5398 | } |
| 5399 | |
| 5400 | /** |
| 5401 | * Same as {@link #startActivities(Intent[], Bundle)} with no options |
| 5402 | * specified. |
| 5403 | * |
| 5404 | * @param intents The intents to start. |
| 5405 | * |
| 5406 | * @throws android.content.ActivityNotFoundException |
| 5407 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 5408 | * @see #startActivities(Intent[], Bundle) |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5409 | * @see #startActivityForResult |
| 5410 | */ |
| 5411 | @Override |
| 5412 | public void startActivities(Intent[] intents) { |
| 5413 | startActivities(intents, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | /** |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 5417 | * Launch a new activity. You will not receive any information about when |
| 5418 | * the activity exits. This implementation overrides the base version, |
| 5419 | * providing information about |
| 5420 | * the activity performing the launch. Because of this additional |
| 5421 | * information, the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag is not |
| 5422 | * required; if not specified, the new activity will be added to the |
| 5423 | * task of the caller. |
| 5424 | * |
| 5425 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 5426 | * if there was no Activity found to run the given Intent. |
| 5427 | * |
| 5428 | * @param intents The intents to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5429 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5430 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5431 | * Context.startActivity(Intent, Bundle)} for more details. |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 5432 | * |
| 5433 | * @throws android.content.ActivityNotFoundException |
| 5434 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 5435 | * @see #startActivities(Intent[]) |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 5436 | * @see #startActivityForResult |
| 5437 | */ |
| 5438 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5439 | public void startActivities(Intent[] intents, @Nullable Bundle options) { |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 5440 | mInstrumentation.execStartActivities(this, mMainThread.getApplicationThread(), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5441 | mToken, this, intents, options); |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 5442 | } |
| 5443 | |
| 5444 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5445 | * Same as calling {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)} |
| 5446 | * with no options. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5447 | * |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5448 | * @param intent The IntentSender to launch. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5449 | * @param fillInIntent If non-null, this will be provided as the |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5450 | * intent parameter to {@link IntentSender#sendIntent}. |
| 5451 | * @param flagsMask Intent flags in the original IntentSender that you |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5452 | * would like to change. |
| 5453 | * @param flagsValues Desired values for any bits set in |
| 5454 | * <var>flagsMask</var> |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5455 | * @param extraFlags Always set to 0. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5456 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5457 | public void startIntentSender(IntentSender intent, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5458 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5459 | throws IntentSender.SendIntentException { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5460 | startIntentSender(intent, fillInIntent, flagsMask, flagsValues, |
| 5461 | extraFlags, null); |
| 5462 | } |
| 5463 | |
| 5464 | /** |
| 5465 | * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender |
| 5466 | * to start; see |
| 5467 | * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int, Bundle)} |
| 5468 | * for more information. |
| 5469 | * |
| 5470 | * @param intent The IntentSender to launch. |
| 5471 | * @param fillInIntent If non-null, this will be provided as the |
| 5472 | * intent parameter to {@link IntentSender#sendIntent}. |
| 5473 | * @param flagsMask Intent flags in the original IntentSender that you |
| 5474 | * would like to change. |
| 5475 | * @param flagsValues Desired values for any bits set in |
| 5476 | * <var>flagsMask</var> |
| 5477 | * @param extraFlags Always set to 0. |
| 5478 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5479 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5480 | * Context.startActivity(Intent, Bundle)} for more details. If options |
| 5481 | * have also been supplied by the IntentSender, options given here will |
| 5482 | * override any that conflict with those given by the IntentSender. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5483 | */ |
| 5484 | public void startIntentSender(IntentSender intent, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5485 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5486 | Bundle options) throws IntentSender.SendIntentException { |
| 5487 | if (options != null) { |
| 5488 | startIntentSenderForResult(intent, -1, fillInIntent, flagsMask, |
| 5489 | flagsValues, extraFlags, options); |
| 5490 | } else { |
| 5491 | // Note we want to go through this call for compatibility with |
| 5492 | // applications that may have overridden the method. |
| 5493 | startIntentSenderForResult(intent, -1, fillInIntent, flagsMask, |
| 5494 | flagsValues, extraFlags); |
| 5495 | } |
| 5496 | } |
| 5497 | |
| 5498 | /** |
| 5499 | * Same as calling {@link #startActivityIfNeeded(Intent, int, Bundle)} |
| 5500 | * with no options. |
| 5501 | * |
| 5502 | * @param intent The intent to start. |
| 5503 | * @param requestCode If >= 0, this code will be returned in |
| 5504 | * onActivityResult() when the activity exits, as described in |
| 5505 | * {@link #startActivityForResult}. |
| 5506 | * |
| 5507 | * @return If a new activity was launched then true is returned; otherwise |
| 5508 | * false is returned and you must handle the Intent yourself. |
| 5509 | * |
| 5510 | * @see #startActivity |
| 5511 | * @see #startActivityForResult |
| 5512 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5513 | public boolean startActivityIfNeeded(@RequiresPermission @NonNull Intent intent, |
| 5514 | int requestCode) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5515 | return startActivityIfNeeded(intent, requestCode, null); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5519 | * A special variation to launch an activity only if a new activity |
| 5520 | * instance is needed to handle the given Intent. In other words, this is |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5521 | * 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] | 5522 | * using the {@link Intent#FLAG_ACTIVITY_SINGLE_TOP} flag, or |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5523 | * singleTask or singleTop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5524 | * {@link android.R.styleable#AndroidManifestActivity_launchMode launchMode}, |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5525 | * and the activity |
| 5526 | * that handles <var>intent</var> is the same as your currently running |
| 5527 | * activity, then a new instance is not needed. In this case, instead of |
| 5528 | * the normal behavior of calling {@link #onNewIntent} this function will |
| 5529 | * return and you can handle the Intent yourself. |
| 5530 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5531 | * <p>This function can only be called from a top-level activity; if it is |
| 5532 | * called from a child activity, a runtime exception will be thrown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5533 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5534 | * @param intent The intent to start. |
| 5535 | * @param requestCode If >= 0, this code will be returned in |
| 5536 | * onActivityResult() when the activity exits, as described in |
| 5537 | * {@link #startActivityForResult}. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5538 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5539 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5540 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5541 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5542 | * @return If a new activity was launched then true is returned; otherwise |
| 5543 | * false is returned and you must handle the Intent yourself. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5544 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5545 | * @see #startActivity |
| 5546 | * @see #startActivityForResult |
| 5547 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5548 | public boolean startActivityIfNeeded(@RequiresPermission @NonNull Intent intent, |
| 5549 | int requestCode, @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5550 | if (mParent == null) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5551 | int result = ActivityManager.START_RETURN_INTENT_TO_CALLER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5552 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 5553 | Uri referrer = onProvideReferrer(); |
| 5554 | if (referrer != null) { |
| 5555 | intent.putExtra(Intent.EXTRA_REFERRER, referrer); |
| 5556 | } |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 5557 | intent.migrateExtraStreamToClipData(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5558 | intent.prepareToLeaveProcess(this); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 5559 | result = ActivityTaskManager.getService() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5560 | .startActivity(mMainThread.getApplicationThread(), getBasePackageName(), |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5561 | intent, intent.resolveTypeIfNeeded(getContentResolver()), mToken, |
| 5562 | mEmbeddedID, requestCode, ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
| 5563 | null, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5564 | } catch (RemoteException e) { |
| 5565 | // Empty |
| 5566 | } |
Siva Velusamy | 92a8b22 | 2012-03-09 16:24:04 -0800 | [diff] [blame] | 5567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5568 | Instrumentation.checkStartActivityResult(result, intent); |
Siva Velusamy | 92a8b22 | 2012-03-09 16:24:04 -0800 | [diff] [blame] | 5569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5570 | if (requestCode >= 0) { |
| 5571 | // If this start is requesting a result, we can avoid making |
| 5572 | // the activity visible until the result is received. Setting |
| 5573 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 5574 | // activity hidden during this time, to avoid flickering. |
| 5575 | // This can only be done when a result is requested because |
| 5576 | // that guarantees we will get information back when the |
| 5577 | // activity is finished, no matter what happens to it. |
| 5578 | mStartedActivity = true; |
| 5579 | } |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5580 | return result != ActivityManager.START_RETURN_INTENT_TO_CALLER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5581 | } |
| 5582 | |
| 5583 | throw new UnsupportedOperationException( |
| 5584 | "startActivityIfNeeded can only be called from a top-level activity"); |
| 5585 | } |
| 5586 | |
| 5587 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5588 | * Same as calling {@link #startNextMatchingActivity(Intent, Bundle)} with |
| 5589 | * no options. |
| 5590 | * |
| 5591 | * @param intent The intent to dispatch to the next activity. For |
| 5592 | * correct behavior, this must be the same as the Intent that started |
| 5593 | * your own activity; the only changes you can make are to the extras |
| 5594 | * inside of it. |
| 5595 | * |
| 5596 | * @return Returns a boolean indicating whether there was another Activity |
| 5597 | * to start: true if there was a next activity to start, false if there |
| 5598 | * wasn't. In general, if true is returned you will then want to call |
| 5599 | * finish() on yourself. |
| 5600 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5601 | public boolean startNextMatchingActivity(@RequiresPermission @NonNull Intent intent) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5602 | return startNextMatchingActivity(intent, null); |
| 5603 | } |
| 5604 | |
| 5605 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5606 | * Special version of starting an activity, for use when you are replacing |
| 5607 | * other activity components. You can use this to hand the Intent off |
| 5608 | * to the next Activity that can handle it. You typically call this in |
| 5609 | * {@link #onCreate} with the Intent returned by {@link #getIntent}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5610 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5611 | * @param intent The intent to dispatch to the next activity. For |
| 5612 | * correct behavior, this must be the same as the Intent that started |
| 5613 | * your own activity; the only changes you can make are to the extras |
| 5614 | * inside of it. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5615 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5616 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5617 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5618 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5619 | * @return Returns a boolean indicating whether there was another Activity |
| 5620 | * to start: true if there was a next activity to start, false if there |
| 5621 | * wasn't. In general, if true is returned you will then want to call |
| 5622 | * finish() on yourself. |
| 5623 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5624 | public boolean startNextMatchingActivity(@RequiresPermission @NonNull Intent intent, |
| 5625 | @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5626 | if (mParent == null) { |
| 5627 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 5628 | intent.migrateExtraStreamToClipData(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5629 | intent.prepareToLeaveProcess(this); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 5630 | return ActivityTaskManager.getService() |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5631 | .startNextMatchingActivity(mToken, intent, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5632 | } catch (RemoteException e) { |
| 5633 | // Empty |
| 5634 | } |
| 5635 | return false; |
| 5636 | } |
| 5637 | |
| 5638 | throw new UnsupportedOperationException( |
| 5639 | "startNextMatchingActivity can only be called from a top-level activity"); |
| 5640 | } |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5641 | |
| 5642 | /** |
| 5643 | * Same as calling {@link #startActivityFromChild(Activity, Intent, int, Bundle)} |
| 5644 | * with no options. |
| 5645 | * |
| 5646 | * @param child The activity making the call. |
| 5647 | * @param intent The intent to start. |
| 5648 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 5649 | * |
| 5650 | * @throws android.content.ActivityNotFoundException |
| 5651 | * |
| 5652 | * @see #startActivity |
| 5653 | * @see #startActivityForResult |
| 5654 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5655 | public void startActivityFromChild(@NonNull Activity child, @RequiresPermission Intent intent, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5656 | int requestCode) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 5657 | startActivityFromChild(child, intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5658 | } |
| 5659 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5660 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5661 | * 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] | 5662 | * {@link #startActivity} or {@link #startActivityForResult} method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5663 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5664 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 5665 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5666 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5667 | * @param child The activity making the call. |
| 5668 | * @param intent The intent to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5669 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 5670 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5671 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5672 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5673 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5674 | * @throws android.content.ActivityNotFoundException |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5675 | * |
| 5676 | * @see #startActivity |
| 5677 | * @see #startActivityForResult |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5678 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5679 | public void startActivityFromChild(@NonNull Activity child, @RequiresPermission Intent intent, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5680 | int requestCode, @Nullable Bundle options) { |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5681 | options = transferSpringboardActivityOptions(options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5682 | Instrumentation.ActivityResult ar = |
| 5683 | mInstrumentation.execStartActivity( |
| 5684 | this, mMainThread.getApplicationThread(), mToken, child, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5685 | intent, requestCode, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5686 | if (ar != null) { |
| 5687 | mMainThread.sendActivityResult( |
| 5688 | mToken, child.mEmbeddedID, requestCode, |
| 5689 | ar.getResultCode(), ar.getResultData()); |
| 5690 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5691 | cancelInputsAndStartExitTransition(options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5692 | } |
| 5693 | |
| 5694 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5695 | * Same as calling {@link #startActivityFromFragment(Fragment, Intent, int, Bundle)} |
| 5696 | * with no options. |
| 5697 | * |
| 5698 | * @param fragment The fragment making the call. |
| 5699 | * @param intent The intent to start. |
| 5700 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 5701 | * |
| 5702 | * @throws android.content.ActivityNotFoundException |
| 5703 | * |
| 5704 | * @see Fragment#startActivity |
| 5705 | * @see Fragment#startActivityForResult |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 5706 | * |
| 5707 | * @deprecated Use {@link android.support.v4.app.FragmentActivity#startActivityFromFragment( |
| 5708 | * android.support.v4.app.Fragment,Intent,int)} |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5709 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 5710 | @Deprecated |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5711 | public void startActivityFromFragment(@NonNull Fragment fragment, |
| 5712 | @RequiresPermission Intent intent, int requestCode) { |
George Mount | abb63cb | 2014-06-23 11:17:58 -0700 | [diff] [blame] | 5713 | startActivityFromFragment(fragment, intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5714 | } |
| 5715 | |
| 5716 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5717 | * This is called when a Fragment in this activity calls its |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5718 | * {@link Fragment#startActivity} or {@link Fragment#startActivityForResult} |
| 5719 | * method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5720 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5721 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 5722 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5723 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5724 | * @param fragment The fragment making the call. |
| 5725 | * @param intent The intent to start. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5726 | * @param requestCode Reply request code. < 0 if reply is not requested. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5727 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5728 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5729 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5730 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5731 | * @throws android.content.ActivityNotFoundException |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5732 | * |
| 5733 | * @see Fragment#startActivity |
| 5734 | * @see Fragment#startActivityForResult |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 5735 | * |
| 5736 | * @deprecated Use {@link android.support.v4.app.FragmentActivity#startActivityFromFragment( |
| 5737 | * android.support.v4.app.Fragment,Intent,int,Bundle)} |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5738 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 5739 | @Deprecated |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5740 | public void startActivityFromFragment(@NonNull Fragment fragment, |
| 5741 | @RequiresPermission Intent intent, int requestCode, @Nullable Bundle options) { |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5742 | startActivityForResult(fragment.mWho, intent, requestCode, options); |
| 5743 | } |
| 5744 | |
| 5745 | /** |
| 5746 | * @hide |
| 5747 | */ |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 5748 | public void startActivityAsUserFromFragment(@NonNull Fragment fragment, |
| 5749 | @RequiresPermission Intent intent, int requestCode, @Nullable Bundle options, |
| 5750 | UserHandle user) { |
| 5751 | startActivityForResultAsUser(intent, fragment.mWho, requestCode, options, user); |
| 5752 | } |
| 5753 | |
| 5754 | /** |
| 5755 | * @hide |
| 5756 | */ |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5757 | @Override |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5758 | @UnsupportedAppUsage |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5759 | public void startActivityForResult( |
| 5760 | String who, Intent intent, int requestCode, @Nullable Bundle options) { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 5761 | Uri referrer = onProvideReferrer(); |
| 5762 | if (referrer != null) { |
| 5763 | intent.putExtra(Intent.EXTRA_REFERRER, referrer); |
| 5764 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5765 | options = transferSpringboardActivityOptions(options); |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5766 | Instrumentation.ActivityResult ar = |
| 5767 | mInstrumentation.execStartActivity( |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5768 | this, mMainThread.getApplicationThread(), mToken, who, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5769 | intent, requestCode, options); |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5770 | if (ar != null) { |
| 5771 | mMainThread.sendActivityResult( |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5772 | mToken, who, requestCode, |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5773 | ar.getResultCode(), ar.getResultData()); |
| 5774 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5775 | cancelInputsAndStartExitTransition(options); |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5776 | } |
| 5777 | |
| 5778 | /** |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5779 | * @hide |
| 5780 | */ |
| 5781 | @Override |
| 5782 | public boolean canStartActivityForResult() { |
| 5783 | return true; |
| 5784 | } |
| 5785 | |
| 5786 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5787 | * Same as calling {@link #startIntentSenderFromChild(Activity, IntentSender, |
| 5788 | * int, Intent, int, int, int, Bundle)} with no options. |
| 5789 | */ |
| 5790 | public void startIntentSenderFromChild(Activity child, IntentSender intent, |
| 5791 | int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, |
| 5792 | int extraFlags) |
| 5793 | throws IntentSender.SendIntentException { |
| 5794 | startIntentSenderFromChild(child, intent, requestCode, fillInIntent, |
| 5795 | flagsMask, flagsValues, extraFlags, null); |
| 5796 | } |
| 5797 | |
| 5798 | /** |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5799 | * Like {@link #startActivityFromChild(Activity, Intent, int)}, but |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5800 | * taking a IntentSender; see |
Dianne Hackborn | ae22c05 | 2009-09-17 18:46:22 -0700 | [diff] [blame] | 5801 | * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int)} |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5802 | * for more information. |
| 5803 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5804 | public void startIntentSenderFromChild(Activity child, IntentSender intent, |
| 5805 | int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5806 | int extraFlags, @Nullable Bundle options) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5807 | throws IntentSender.SendIntentException { |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 5808 | startIntentSenderForResultInner(intent, child.mEmbeddedID, requestCode, fillInIntent, |
| 5809 | flagsMask, flagsValues, options); |
| 5810 | } |
| 5811 | |
| 5812 | /** |
| 5813 | * Like {@link #startIntentSenderFromChild}, but taking a Fragment; see |
| 5814 | * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int)} |
| 5815 | * for more information. |
| 5816 | * |
| 5817 | * @hide |
| 5818 | */ |
| 5819 | public void startIntentSenderFromChildFragment(Fragment child, IntentSender intent, |
| 5820 | int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, |
| 5821 | int extraFlags, @Nullable Bundle options) |
| 5822 | throws IntentSender.SendIntentException { |
| 5823 | startIntentSenderForResultInner(intent, child.mWho, requestCode, fillInIntent, |
| 5824 | flagsMask, flagsValues, options); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5825 | } |
| 5826 | |
| 5827 | /** |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5828 | * Call immediately after one of the flavors of {@link #startActivity(Intent)} |
| 5829 | * or {@link #finish} to specify an explicit transition animation to |
| 5830 | * perform next. |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5831 | * |
| 5832 | * <p>As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN} an alternative |
| 5833 | * to using this with starting activities is to supply the desired animation |
| 5834 | * information through a {@link ActivityOptions} bundle to |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 5835 | * {@link #startActivity(Intent, Bundle)} or a related function. This allows |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5836 | * you to specify a custom animation even when starting an activity from |
| 5837 | * outside the context of the current top activity. |
| 5838 | * |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5839 | * @param enterAnim A resource ID of the animation resource to use for |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 5840 | * the incoming activity. Use 0 for no animation. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5841 | * @param exitAnim A resource ID of the animation resource to use for |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 5842 | * the outgoing activity. Use 0 for no animation. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5843 | */ |
| 5844 | public void overridePendingTransition(int enterAnim, int exitAnim) { |
| 5845 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 5846 | ActivityTaskManager.getService().overridePendingTransition( |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5847 | mToken, getPackageName(), enterAnim, exitAnim); |
| 5848 | } catch (RemoteException e) { |
| 5849 | } |
| 5850 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5851 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5852 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5853 | * Call this to set the result that your activity will return to its |
| 5854 | * caller. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5855 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5856 | * @param resultCode The result code to propagate back to the originating |
| 5857 | * activity, often RESULT_CANCELED or RESULT_OK |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5858 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5859 | * @see #RESULT_CANCELED |
| 5860 | * @see #RESULT_OK |
| 5861 | * @see #RESULT_FIRST_USER |
| 5862 | * @see #setResult(int, Intent) |
| 5863 | */ |
| 5864 | public final void setResult(int resultCode) { |
| 5865 | synchronized (this) { |
| 5866 | mResultCode = resultCode; |
| 5867 | mResultData = null; |
| 5868 | } |
| 5869 | } |
| 5870 | |
| 5871 | /** |
| 5872 | * Call this to set the result that your activity will return to its |
| 5873 | * caller. |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 5874 | * |
| 5875 | * <p>As of {@link android.os.Build.VERSION_CODES#GINGERBREAD}, the Intent |
| 5876 | * you supply here can have {@link Intent#FLAG_GRANT_READ_URI_PERMISSION |
| 5877 | * Intent.FLAG_GRANT_READ_URI_PERMISSION} and/or {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 5878 | * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} set. This will grant the |
| 5879 | * Activity receiving the result access to the specific URIs in the Intent. |
| 5880 | * Access will remain until the Activity has finished (it will remain across the hosting |
| 5881 | * process being killed and other temporary destruction) and will be added |
| 5882 | * to any existing set of URI permissions it already holds. |
| 5883 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5884 | * @param resultCode The result code to propagate back to the originating |
| 5885 | * activity, often RESULT_CANCELED or RESULT_OK |
| 5886 | * @param data The data to propagate back to the originating activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5887 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5888 | * @see #RESULT_CANCELED |
| 5889 | * @see #RESULT_OK |
| 5890 | * @see #RESULT_FIRST_USER |
| 5891 | * @see #setResult(int) |
| 5892 | */ |
| 5893 | public final void setResult(int resultCode, Intent data) { |
| 5894 | synchronized (this) { |
| 5895 | mResultCode = resultCode; |
| 5896 | mResultData = data; |
| 5897 | } |
| 5898 | } |
| 5899 | |
| 5900 | /** |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 5901 | * Return information about who launched this activity. If the launching Intent |
| 5902 | * contains an {@link android.content.Intent#EXTRA_REFERRER Intent.EXTRA_REFERRER}, |
| 5903 | * that will be returned as-is; otherwise, if known, an |
| 5904 | * {@link Intent#URI_ANDROID_APP_SCHEME android-app:} referrer URI containing the |
| 5905 | * package name that started the Intent will be returned. This may return null if no |
| 5906 | * referrer can be identified -- it is neither explicitly specified, nor is it known which |
| 5907 | * application package was involved. |
| 5908 | * |
| 5909 | * <p>If called while inside the handling of {@link #onNewIntent}, this function will |
| 5910 | * return the referrer that submitted that new intent to the activity. Otherwise, it |
| 5911 | * always returns the referrer of the original Intent.</p> |
| 5912 | * |
| 5913 | * <p>Note that this is <em>not</em> a security feature -- you can not trust the |
| 5914 | * referrer information, applications can spoof it.</p> |
| 5915 | */ |
| 5916 | @Nullable |
| 5917 | public Uri getReferrer() { |
| 5918 | Intent intent = getIntent(); |
Adam Powell | d3c63a6 | 2016-06-09 12:36:16 -0700 | [diff] [blame] | 5919 | try { |
| 5920 | Uri referrer = intent.getParcelableExtra(Intent.EXTRA_REFERRER); |
| 5921 | if (referrer != null) { |
| 5922 | return referrer; |
| 5923 | } |
| 5924 | String referrerName = intent.getStringExtra(Intent.EXTRA_REFERRER_NAME); |
| 5925 | if (referrerName != null) { |
| 5926 | return Uri.parse(referrerName); |
| 5927 | } |
| 5928 | } catch (BadParcelableException e) { |
| 5929 | Log.w(TAG, "Cannot read referrer from intent;" |
| 5930 | + " intent extras contain unknown custom Parcelable objects"); |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 5931 | } |
| 5932 | if (mReferrer != null) { |
| 5933 | return new Uri.Builder().scheme("android-app").authority(mReferrer).build(); |
| 5934 | } |
| 5935 | return null; |
| 5936 | } |
| 5937 | |
| 5938 | /** |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 5939 | * Override to generate the desired referrer for the content currently being shown |
| 5940 | * by the app. The default implementation returns null, meaning the referrer will simply |
| 5941 | * be the android-app: of the package name of this activity. Return a non-null Uri to |
| 5942 | * have that supplied as the {@link Intent#EXTRA_REFERRER} of any activities started from it. |
| 5943 | */ |
| 5944 | public Uri onProvideReferrer() { |
| 5945 | return null; |
| 5946 | } |
| 5947 | |
| 5948 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5949 | * Return the name of the package that invoked this activity. This is who |
| 5950 | * the data in {@link #setResult setResult()} will be sent to. You can |
| 5951 | * use this information to validate that the recipient is allowed to |
| 5952 | * receive the data. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5953 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 5954 | * <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] | 5955 | * did not use the {@link #startActivityForResult} |
| 5956 | * form that includes a request code), then the calling package will be |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 5957 | * null.</p> |
| 5958 | * |
| 5959 | * <p class="note">Note: prior to {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, |
| 5960 | * the result from this method was unstable. If the process hosting the calling |
| 5961 | * package was no longer running, it would return null instead of the proper package |
| 5962 | * name. You can use {@link #getCallingActivity()} and retrieve the package name |
| 5963 | * from that instead.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5964 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5965 | * @return The package of the activity that will receive your |
| 5966 | * reply, or null if none. |
| 5967 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5968 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5969 | public String getCallingPackage() { |
| 5970 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 5971 | return ActivityTaskManager.getService().getCallingPackage(mToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5972 | } catch (RemoteException e) { |
| 5973 | return null; |
| 5974 | } |
| 5975 | } |
| 5976 | |
| 5977 | /** |
| 5978 | * Return the name of the activity that invoked this activity. This is |
| 5979 | * who the data in {@link #setResult setResult()} will be sent to. You |
| 5980 | * can use this information to validate that the recipient is allowed to |
| 5981 | * receive the data. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5982 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 5983 | * <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] | 5984 | * did not use the {@link #startActivityForResult} |
| 5985 | * form that includes a request code), then the calling package will be |
| 5986 | * null. |
| 5987 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 5988 | * @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] | 5989 | * reply, or null if none. |
| 5990 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5991 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5992 | public ComponentName getCallingActivity() { |
| 5993 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 5994 | return ActivityTaskManager.getService().getCallingActivity(mToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5995 | } catch (RemoteException e) { |
| 5996 | return null; |
| 5997 | } |
| 5998 | } |
| 5999 | |
| 6000 | /** |
| 6001 | * Control whether this activity's main window is visible. This is intended |
| 6002 | * only for the special case of an activity that is not going to show a |
| 6003 | * UI itself, but can't just finish prior to onResume() because it needs |
| 6004 | * to wait for a service binding or such. Setting this to false allows |
| 6005 | * you to prevent your UI from being shown during that time. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6006 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6007 | * <p>The default value for this is taken from the |
| 6008 | * {@link android.R.attr#windowNoDisplay} attribute of the activity's theme. |
| 6009 | */ |
| 6010 | public void setVisible(boolean visible) { |
| 6011 | if (mVisibleFromClient != visible) { |
| 6012 | mVisibleFromClient = visible; |
| 6013 | if (mVisibleFromServer) { |
| 6014 | if (visible) makeVisible(); |
| 6015 | else mDecor.setVisibility(View.INVISIBLE); |
| 6016 | } |
| 6017 | } |
| 6018 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6019 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6020 | void makeVisible() { |
| 6021 | if (!mWindowAdded) { |
| 6022 | ViewManager wm = getWindowManager(); |
| 6023 | wm.addView(mDecor, getWindow().getAttributes()); |
| 6024 | mWindowAdded = true; |
| 6025 | } |
| 6026 | mDecor.setVisibility(View.VISIBLE); |
| 6027 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6028 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6029 | /** |
| 6030 | * Check to see whether this activity is in the process of finishing, |
| 6031 | * either because you called {@link #finish} on it or someone else |
| 6032 | * has requested that it finished. This is often used in |
| 6033 | * {@link #onPause} to determine whether the activity is simply pausing or |
| 6034 | * completely finishing. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6035 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6036 | * @return If the activity is finishing, returns true; else returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6037 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6038 | * @see #finish |
| 6039 | */ |
| 6040 | public boolean isFinishing() { |
| 6041 | return mFinished; |
| 6042 | } |
| 6043 | |
| 6044 | /** |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 6045 | * Returns true if the final {@link #onDestroy()} call has been made |
| 6046 | * on the Activity, so this instance is now dead. |
| 6047 | */ |
| 6048 | public boolean isDestroyed() { |
| 6049 | return mDestroyed; |
| 6050 | } |
| 6051 | |
| 6052 | /** |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 6053 | * Check to see whether this activity is in the process of being destroyed in order to be |
| 6054 | * recreated with a new configuration. This is often used in |
| 6055 | * {@link #onStop} to determine whether the state needs to be cleaned up or will be passed |
| 6056 | * on to the next instance of the activity via {@link #onRetainNonConfigurationInstance()}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6057 | * |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 6058 | * @return If the activity is being torn down in order to be recreated with a new configuration, |
| 6059 | * returns true; else returns false. |
| 6060 | */ |
| 6061 | public boolean isChangingConfigurations() { |
| 6062 | return mChangingConfigurations; |
| 6063 | } |
| 6064 | |
| 6065 | /** |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 6066 | * Cause this Activity to be recreated with a new instance. This results |
| 6067 | * in essentially the same flow as when the Activity is created due to |
| 6068 | * a configuration change -- the current instance will go through its |
| 6069 | * lifecycle to {@link #onDestroy} and a new instance then created after it. |
| 6070 | */ |
| 6071 | public void recreate() { |
| 6072 | if (mParent != null) { |
| 6073 | throw new IllegalStateException("Can only be called on top-level activity"); |
| 6074 | } |
Wale Ogunwale | 0527d91 | 2018-05-16 17:23:48 -0700 | [diff] [blame] | 6075 | if (Looper.myLooper() != mMainThread.getLooper()) { |
| 6076 | throw new IllegalStateException("Must be called from main thread"); |
| 6077 | } |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 6078 | mMainThread.scheduleRelaunchActivity(mToken); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 6079 | } |
| 6080 | |
| 6081 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 6082 | * Finishes the current activity and specifies whether to remove the task associated with this |
| 6083 | * activity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6084 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6085 | @UnsupportedAppUsage |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 6086 | private void finish(int finishTask) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6087 | if (mParent == null) { |
| 6088 | int resultCode; |
| 6089 | Intent resultData; |
| 6090 | synchronized (this) { |
| 6091 | resultCode = mResultCode; |
| 6092 | resultData = mResultData; |
| 6093 | } |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 6094 | if (false) Log.v(TAG, "Finishing self: token=" + mToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6095 | try { |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 6096 | if (resultData != null) { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 6097 | resultData.prepareToLeaveProcess(this); |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 6098 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6099 | if (ActivityTaskManager.getService() |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 6100 | .finishActivity(mToken, resultCode, resultData, finishTask)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6101 | mFinished = true; |
| 6102 | } |
| 6103 | } catch (RemoteException e) { |
| 6104 | // Empty |
| 6105 | } |
| 6106 | } else { |
| 6107 | mParent.finishFromChild(this); |
| 6108 | } |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 6109 | |
| 6110 | // Activity was launched when user tapped a link in the Autofill Save UI - Save UI must |
| 6111 | // be restored now. |
| 6112 | if (mIntent != null && mIntent.hasExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN)) { |
| 6113 | getAutofillManager().onPendingSaveUi(AutofillManager.PENDING_UI_OPERATION_RESTORE, |
| 6114 | mIntent.getIBinderExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN)); |
| 6115 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6116 | } |
| 6117 | |
| 6118 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 6119 | * Call this when your activity is done and should be closed. The |
| 6120 | * ActivityResult is propagated back to whoever launched you via |
| 6121 | * onActivityResult(). |
| 6122 | */ |
| 6123 | public void finish() { |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 6124 | finish(DONT_FINISH_TASK_WITH_ACTIVITY); |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 6125 | } |
| 6126 | |
| 6127 | /** |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 6128 | * Finish this activity as well as all activities immediately below it |
| 6129 | * in the current task that have the same affinity. This is typically |
| 6130 | * used when an application can be launched on to another task (such as |
| 6131 | * from an ACTION_VIEW of a content type it understands) and the user |
| 6132 | * has used the up navigation to switch out of the current task and in |
| 6133 | * to its own task. In this case, if the user has navigated down into |
| 6134 | * any other activities of the second application, all of those should |
| 6135 | * be removed from the original task as part of the task switch. |
| 6136 | * |
| 6137 | * <p>Note that this finish does <em>not</em> allow you to deliver results |
| 6138 | * to the previous activity, and an exception will be thrown if you are trying |
| 6139 | * to do so.</p> |
| 6140 | */ |
| 6141 | public void finishAffinity() { |
| 6142 | if (mParent != null) { |
| 6143 | throw new IllegalStateException("Can not be called from an embedded activity"); |
| 6144 | } |
| 6145 | if (mResultCode != RESULT_CANCELED || mResultData != null) { |
| 6146 | throw new IllegalStateException("Can not be called to deliver a result"); |
| 6147 | } |
| 6148 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6149 | if (ActivityTaskManager.getService().finishActivityAffinity(mToken)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 6150 | mFinished = true; |
| 6151 | } |
| 6152 | } catch (RemoteException e) { |
| 6153 | // Empty |
| 6154 | } |
| 6155 | } |
| 6156 | |
| 6157 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6158 | * 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] | 6159 | * {@link #finish} method. The default implementation simply calls |
| 6160 | * finish() on this activity (the parent), finishing the entire group. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6161 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6162 | * @param child The activity making the call. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6163 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6164 | * @see #finish |
| 6165 | */ |
| 6166 | public void finishFromChild(Activity child) { |
| 6167 | finish(); |
| 6168 | } |
| 6169 | |
| 6170 | /** |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 6171 | * Reverses the Activity Scene entry Transition and triggers the calling Activity |
| 6172 | * to reverse its exit Transition. When the exit Transition completes, |
| 6173 | * {@link #finish()} is called. If no entry Transition was used, finish() is called |
| 6174 | * immediately and the Activity exit Transition is run. |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6175 | * @see android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, android.util.Pair[]) |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 6176 | */ |
Craig Mautner | 73f843d | 2014-05-19 09:42:28 -0700 | [diff] [blame] | 6177 | public void finishAfterTransition() { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6178 | if (!mActivityTransitionState.startExitBackTransition(this)) { |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 6179 | finish(); |
| 6180 | } |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 6181 | } |
| 6182 | |
| 6183 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6184 | * Force finish another activity that you had previously started with |
| 6185 | * {@link #startActivityForResult}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6186 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6187 | * @param requestCode The request code of the activity that you had |
| 6188 | * given to startActivityForResult(). If there are multiple |
| 6189 | * activities started with this request code, they |
| 6190 | * will all be finished. |
| 6191 | */ |
| 6192 | public void finishActivity(int requestCode) { |
| 6193 | if (mParent == null) { |
| 6194 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6195 | ActivityTaskManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6196 | .finishSubActivity(mToken, mEmbeddedID, requestCode); |
| 6197 | } catch (RemoteException e) { |
| 6198 | // Empty |
| 6199 | } |
| 6200 | } else { |
| 6201 | mParent.finishActivityFromChild(this, requestCode); |
| 6202 | } |
| 6203 | } |
| 6204 | |
| 6205 | /** |
| 6206 | * This is called when a child activity of this one calls its |
| 6207 | * finishActivity(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6208 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6209 | * @param child The activity making the call. |
| 6210 | * @param requestCode Request code that had been used to start the |
| 6211 | * activity. |
| 6212 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6213 | public void finishActivityFromChild(@NonNull Activity child, int requestCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6214 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6215 | ActivityTaskManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6216 | .finishSubActivity(mToken, child.mEmbeddedID, requestCode); |
| 6217 | } catch (RemoteException e) { |
| 6218 | // Empty |
| 6219 | } |
| 6220 | } |
| 6221 | |
| 6222 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 6223 | * 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] | 6224 | * removed as a part of finishing the root activity of the task. |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 6225 | */ |
| 6226 | public void finishAndRemoveTask() { |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 6227 | finish(FINISH_TASK_WITH_ROOT_ACTIVITY); |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | /** |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6231 | * Ask that the local app instance of this activity be released to free up its memory. |
| 6232 | * This is asking for the activity to be destroyed, but does <b>not</b> finish the activity -- |
| 6233 | * a new instance of the activity will later be re-created if needed due to the user |
| 6234 | * navigating back to it. |
| 6235 | * |
| 6236 | * @return Returns true if the activity was in a state that it has started the process |
| 6237 | * of destroying its current instance; returns false if for any reason this could not |
| 6238 | * be done: it is currently visible to the user, it is already being destroyed, it is |
| 6239 | * being finished, it hasn't yet saved its state, etc. |
| 6240 | */ |
| 6241 | public boolean releaseInstance() { |
| 6242 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6243 | return ActivityTaskManager.getService().releaseActivityInstance(mToken); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6244 | } catch (RemoteException e) { |
| 6245 | // Empty |
| 6246 | } |
| 6247 | return false; |
| 6248 | } |
| 6249 | |
| 6250 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6251 | * Called when an activity you launched exits, giving you the requestCode |
| 6252 | * you started it with, the resultCode it returned, and any additional |
| 6253 | * data from it. The <var>resultCode</var> will be |
| 6254 | * {@link #RESULT_CANCELED} if the activity explicitly returned that, |
| 6255 | * didn't return any result, or crashed during its operation. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6256 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6257 | * <p>You will receive this call immediately before onResume() when your |
| 6258 | * activity is re-starting. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6259 | * |
Ricardo Cervera | 92f6a74 | 2014-04-04 11:17:06 -0700 | [diff] [blame] | 6260 | * <p>This method is never invoked if your activity sets |
| 6261 | * {@link android.R.styleable#AndroidManifestActivity_noHistory noHistory} to |
| 6262 | * <code>true</code>. |
Ricardo Cervera | 93f94c2 | 2015-01-16 09:54:30 -0800 | [diff] [blame] | 6263 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6264 | * @param requestCode The integer request code originally supplied to |
| 6265 | * startActivityForResult(), allowing you to identify who this |
| 6266 | * result came from. |
| 6267 | * @param resultCode The integer result code returned by the child activity |
| 6268 | * through its setResult(). |
| 6269 | * @param data An Intent, which can return result data to the caller |
| 6270 | * (various data can be attached to Intent "extras"). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6271 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6272 | * @see #startActivityForResult |
| 6273 | * @see #createPendingResult |
| 6274 | * @see #setResult(int) |
| 6275 | */ |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 6276 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6277 | } |
| 6278 | |
| 6279 | /** |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6280 | * Called when an activity you launched with an activity transition exposes this |
| 6281 | * Activity through a returning activity transition, giving you the resultCode |
| 6282 | * and any additional data from it. This method will only be called if the activity |
| 6283 | * 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] | 6284 | * transitions with {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6285 | * |
| 6286 | * <p>The purpose of this function is to let the called Activity send a hint about |
| 6287 | * its state so that this underlying Activity can prepare to be exposed. A call to |
| 6288 | * this method does not guarantee that the called Activity has or will be exiting soon. |
| 6289 | * It only indicates that it will expose this Activity's Window and it has |
| 6290 | * some data to pass to prepare it.</p> |
| 6291 | * |
| 6292 | * @param resultCode The integer result code returned by the child activity |
| 6293 | * through its setResult(). |
| 6294 | * @param data An Intent, which can return result data to the caller |
| 6295 | * (various data can be attached to Intent "extras"). |
| 6296 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 6297 | public void onActivityReenter(int resultCode, Intent data) { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6298 | } |
| 6299 | |
| 6300 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6301 | * Create a new PendingIntent object which you can hand to others |
| 6302 | * for them to use to send result data back to your |
| 6303 | * {@link #onActivityResult} callback. The created object will be either |
| 6304 | * one-shot (becoming invalid after a result is sent back) or multiple |
| 6305 | * (allowing any number of results to be sent through it). |
| 6306 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6307 | * @param requestCode Private request code for the sender that will be |
| 6308 | * associated with the result data when it is returned. The sender can not |
| 6309 | * modify this value, allowing you to identify incoming results. |
| 6310 | * @param data Default data to supply in the result, which may be modified |
| 6311 | * by the sender. |
| 6312 | * @param flags May be {@link PendingIntent#FLAG_ONE_SHOT PendingIntent.FLAG_ONE_SHOT}, |
| 6313 | * {@link PendingIntent#FLAG_NO_CREATE PendingIntent.FLAG_NO_CREATE}, |
| 6314 | * {@link PendingIntent#FLAG_CANCEL_CURRENT PendingIntent.FLAG_CANCEL_CURRENT}, |
| 6315 | * {@link PendingIntent#FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT}, |
| 6316 | * or any of the flags as supported by |
| 6317 | * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts |
| 6318 | * of the intent that can be supplied when the actual send happens. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6319 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6320 | * @return Returns an existing or new PendingIntent matching the given |
| 6321 | * parameters. May return null only if |
| 6322 | * {@link PendingIntent#FLAG_NO_CREATE PendingIntent.FLAG_NO_CREATE} has been |
| 6323 | * supplied. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6324 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6325 | * @see PendingIntent |
| 6326 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6327 | public PendingIntent createPendingResult(int requestCode, @NonNull Intent data, |
| 6328 | @PendingIntent.Flags int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6329 | String packageName = getPackageName(); |
| 6330 | try { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 6331 | data.prepareToLeaveProcess(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6332 | IIntentSender target = |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6333 | ActivityManager.getService().getIntentSender( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6334 | ActivityManager.INTENT_SENDER_ACTIVITY_RESULT, packageName, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6335 | mParent == null ? mToken : mParent.mToken, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 6336 | mEmbeddedID, requestCode, new Intent[] { data }, null, flags, null, |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 6337 | getUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6338 | return target != null ? new PendingIntent(target) : null; |
| 6339 | } catch (RemoteException e) { |
| 6340 | // Empty |
| 6341 | } |
| 6342 | return null; |
| 6343 | } |
| 6344 | |
| 6345 | /** |
| 6346 | * Change the desired orientation of this activity. If the activity |
| 6347 | * is currently in the foreground or otherwise impacting the screen |
| 6348 | * orientation, the screen will immediately be changed (possibly causing |
| 6349 | * the activity to be restarted). Otherwise, this will be used the next |
| 6350 | * time the activity is visible. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6351 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6352 | * @param requestedOrientation An orientation constant as used in |
| 6353 | * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}. |
| 6354 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6355 | public void setRequestedOrientation(@ActivityInfo.ScreenOrientation int requestedOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6356 | if (mParent == null) { |
| 6357 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6358 | ActivityTaskManager.getService().setRequestedOrientation( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6359 | mToken, requestedOrientation); |
| 6360 | } catch (RemoteException e) { |
| 6361 | // Empty |
| 6362 | } |
| 6363 | } else { |
| 6364 | mParent.setRequestedOrientation(requestedOrientation); |
| 6365 | } |
| 6366 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6368 | /** |
| 6369 | * Return the current requested orientation of the activity. This will |
| 6370 | * either be the orientation requested in its component's manifest, or |
| 6371 | * the last requested orientation given to |
| 6372 | * {@link #setRequestedOrientation(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6373 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6374 | * @return Returns an orientation constant as used in |
| 6375 | * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}. |
| 6376 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6377 | @ActivityInfo.ScreenOrientation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6378 | public int getRequestedOrientation() { |
| 6379 | if (mParent == null) { |
| 6380 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6381 | return ActivityTaskManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6382 | .getRequestedOrientation(mToken); |
| 6383 | } catch (RemoteException e) { |
| 6384 | // Empty |
| 6385 | } |
| 6386 | } else { |
| 6387 | return mParent.getRequestedOrientation(); |
| 6388 | } |
| 6389 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 6390 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6391 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6392 | /** |
| 6393 | * Return the identifier of the task this activity is in. This identifier |
| 6394 | * will remain the same for the lifetime of the activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6395 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6396 | * @return Task identifier, an opaque integer. |
| 6397 | */ |
| 6398 | public int getTaskId() { |
| 6399 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6400 | return ActivityTaskManager.getService().getTaskForActivity(mToken, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6401 | } catch (RemoteException e) { |
| 6402 | return -1; |
| 6403 | } |
| 6404 | } |
| 6405 | |
| 6406 | /** |
| 6407 | * Return whether this activity is the root of a task. The root is the |
| 6408 | * first activity in a task. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6409 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6410 | * @return True if this is the root activity, else false. |
| 6411 | */ |
Winson Chung | 4d8681f | 2017-05-23 16:22:08 -0700 | [diff] [blame] | 6412 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6413 | public boolean isTaskRoot() { |
| 6414 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6415 | return ActivityTaskManager.getService().getTaskForActivity(mToken, true) >= 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6416 | } catch (RemoteException e) { |
| 6417 | return false; |
| 6418 | } |
| 6419 | } |
| 6420 | |
| 6421 | /** |
| 6422 | * Move the task containing this activity to the back of the activity |
| 6423 | * stack. The activity's order within the task is unchanged. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6424 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6425 | * @param nonRoot If false then this only works if the activity is the root |
| 6426 | * of a task; if true it will work for any activity in |
| 6427 | * a task. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6428 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6429 | * @return If the task was moved (or it was already at the |
| 6430 | * back) true is returned, else false. |
| 6431 | */ |
| 6432 | public boolean moveTaskToBack(boolean nonRoot) { |
| 6433 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6434 | return ActivityTaskManager.getService().moveActivityTaskToBack(mToken, nonRoot); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6435 | } catch (RemoteException e) { |
| 6436 | // Empty |
| 6437 | } |
| 6438 | return false; |
| 6439 | } |
| 6440 | |
| 6441 | /** |
| 6442 | * Returns class name for this activity with the package prefix removed. |
| 6443 | * This is the default name used to read and write settings. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6444 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6445 | * @return The local class name. |
| 6446 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6447 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6448 | public String getLocalClassName() { |
| 6449 | final String pkg = getPackageName(); |
| 6450 | final String cls = mComponent.getClassName(); |
| 6451 | int packageLen = pkg.length(); |
| 6452 | if (!cls.startsWith(pkg) || cls.length() <= packageLen |
| 6453 | || cls.charAt(packageLen) != '.') { |
| 6454 | return cls; |
| 6455 | } |
| 6456 | return cls.substring(packageLen+1); |
| 6457 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6459 | /** |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 6460 | * Returns the complete component name of this activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6461 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6462 | * @return Returns the complete component name for this activity |
| 6463 | */ |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 6464 | public ComponentName getComponentName() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6465 | return mComponent; |
| 6466 | } |
| 6467 | |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 6468 | /** @hide */ |
| 6469 | @Override |
| 6470 | public final ComponentName autofillClientGetComponentName() { |
| 6471 | return getComponentName(); |
| 6472 | } |
| 6473 | |
Adam He | 6240eab | 2019-02-25 13:34:45 -0800 | [diff] [blame] | 6474 | /** @hide */ |
| 6475 | @Override |
| 6476 | public final ComponentName contentCaptureClientGetComponentName() { |
| 6477 | return getComponentName(); |
| 6478 | } |
| 6479 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6480 | /** |
| 6481 | * Retrieve a {@link SharedPreferences} object for accessing preferences |
| 6482 | * that are private to this activity. This simply calls the underlying |
| 6483 | * {@link #getSharedPreferences(String, int)} method by passing in this activity's |
| 6484 | * class name as the preferences name. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6485 | * |
| 6486 | * @param mode Operating mode. Use {@link #MODE_PRIVATE} for the default |
Jeff Sharkey | 634dc42 | 2016-01-30 17:44:15 -0700 | [diff] [blame] | 6487 | * operation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6488 | * |
| 6489 | * @return Returns the single SharedPreferences instance that can be used |
| 6490 | * to retrieve and modify the preference values. |
| 6491 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 6492 | public SharedPreferences getPreferences(@Context.PreferencesMode int mode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6493 | return getSharedPreferences(getLocalClassName(), mode); |
| 6494 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6495 | |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 6496 | private void ensureSearchManager() { |
| 6497 | if (mSearchManager != null) { |
| 6498 | return; |
| 6499 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6500 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 6501 | try { |
| 6502 | mSearchManager = new SearchManager(this, null); |
| 6503 | } catch (ServiceNotFoundException e) { |
| 6504 | throw new IllegalStateException(e); |
| 6505 | } |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 6506 | } |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6507 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6508 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6509 | public Object getSystemService(@ServiceName @NonNull String name) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6510 | if (getBaseContext() == null) { |
| 6511 | throw new IllegalStateException( |
| 6512 | "System services not available to Activities before onCreate()"); |
| 6513 | } |
| 6514 | |
| 6515 | if (WINDOW_SERVICE.equals(name)) { |
| 6516 | return mWindowManager; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 6517 | } else if (SEARCH_SERVICE.equals(name)) { |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 6518 | ensureSearchManager(); |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 6519 | return mSearchManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6520 | } |
| 6521 | return super.getSystemService(name); |
| 6522 | } |
| 6523 | |
| 6524 | /** |
| 6525 | * Change the title associated with this activity. If this is a |
| 6526 | * top-level activity, the title for its window will change. If it |
| 6527 | * is an embedded activity, the parent can do whatever it wants |
| 6528 | * with it. |
| 6529 | */ |
| 6530 | public void setTitle(CharSequence title) { |
| 6531 | mTitle = title; |
| 6532 | onTitleChanged(title, mTitleColor); |
| 6533 | |
| 6534 | if (mParent != null) { |
| 6535 | mParent.onChildTitleChanged(this, title); |
| 6536 | } |
| 6537 | } |
| 6538 | |
| 6539 | /** |
| 6540 | * Change the title associated with this activity. If this is a |
| 6541 | * top-level activity, the title for its window will change. If it |
| 6542 | * is an embedded activity, the parent can do whatever it wants |
| 6543 | * with it. |
| 6544 | */ |
| 6545 | public void setTitle(int titleId) { |
| 6546 | setTitle(getText(titleId)); |
| 6547 | } |
| 6548 | |
Alan Viverette | 2525d9c | 2013-11-15 14:42:19 -0800 | [diff] [blame] | 6549 | /** |
| 6550 | * Change the color of the title associated with this activity. |
| 6551 | * <p> |
| 6552 | * This method is deprecated starting in API Level 11 and replaced by action |
| 6553 | * bar styles. For information on styling the Action Bar, read the <a |
| 6554 | * href="{@docRoot} guide/topics/ui/actionbar.html">Action Bar</a> developer |
| 6555 | * guide. |
| 6556 | * |
| 6557 | * @deprecated Use action bar styles instead. |
| 6558 | */ |
| 6559 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6560 | public void setTitleColor(int textColor) { |
| 6561 | mTitleColor = textColor; |
| 6562 | onTitleChanged(mTitle, textColor); |
| 6563 | } |
| 6564 | |
| 6565 | public final CharSequence getTitle() { |
| 6566 | return mTitle; |
| 6567 | } |
| 6568 | |
| 6569 | public final int getTitleColor() { |
| 6570 | return mTitleColor; |
| 6571 | } |
| 6572 | |
| 6573 | protected void onTitleChanged(CharSequence title, int color) { |
| 6574 | if (mTitleReady) { |
| 6575 | final Window win = getWindow(); |
| 6576 | if (win != null) { |
| 6577 | win.setTitle(title); |
| 6578 | if (color != 0) { |
| 6579 | win.setTitleColor(color); |
| 6580 | } |
| 6581 | } |
Adam Powell | af2d859 | 2014-08-26 18:06:40 -0700 | [diff] [blame] | 6582 | if (mActionBar != null) { |
| 6583 | mActionBar.setWindowTitle(title); |
| 6584 | } |
Adam Powell | a557fdc | 2014-08-21 18:05:53 -0700 | [diff] [blame] | 6585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6586 | } |
| 6587 | |
| 6588 | protected void onChildTitleChanged(Activity childActivity, CharSequence title) { |
| 6589 | } |
| 6590 | |
| 6591 | /** |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 6592 | * Sets information describing the task with this activity for presentation inside the Recents |
| 6593 | * System UI. When {@link ActivityManager#getRecentTasks} is called, the activities of each task |
| 6594 | * are traversed in order from the topmost activity to the bottommost. The traversal continues |
| 6595 | * for each property until a suitable value is found. For each task the taskDescription will be |
| 6596 | * returned in {@link android.app.ActivityManager.TaskDescription}. |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6597 | * |
| 6598 | * @see ActivityManager#getRecentTasks |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 6599 | * @see android.app.ActivityManager.TaskDescription |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6600 | * |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 6601 | * @param taskDescription The TaskDescription properties that describe the task with this activity |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6602 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 6603 | public void setTaskDescription(ActivityManager.TaskDescription taskDescription) { |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 6604 | if (mTaskDescription != taskDescription) { |
Jorim Jaggi | f4156ea | 2017-04-10 18:39:04 -0700 | [diff] [blame] | 6605 | mTaskDescription.copyFromPreserveHiddenFields(taskDescription); |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 6606 | // Scale the icon down to something reasonable if it is provided |
| 6607 | if (taskDescription.getIconFilename() == null && taskDescription.getIcon() != null) { |
| 6608 | final int size = ActivityManager.getLauncherLargeIconSizeInner(this); |
| 6609 | final Bitmap icon = Bitmap.createScaledBitmap(taskDescription.getIcon(), size, size, |
| 6610 | true); |
| 6611 | mTaskDescription.setIcon(icon); |
| 6612 | } |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6613 | } |
| 6614 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6615 | ActivityTaskManager.getService().setTaskDescription(mToken, mTaskDescription); |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6616 | } catch (RemoteException e) { |
| 6617 | } |
| 6618 | } |
| 6619 | |
| 6620 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6621 | * Sets the visibility of the progress bar in the title. |
| 6622 | * <p> |
| 6623 | * In order for the progress bar to be shown, the feature must be requested |
| 6624 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6625 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6626 | * @param visible Whether to show the progress bars in the title. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6627 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6628 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6629 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6630 | public final void setProgressBarVisibility(boolean visible) { |
| 6631 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, visible ? Window.PROGRESS_VISIBILITY_ON : |
| 6632 | Window.PROGRESS_VISIBILITY_OFF); |
| 6633 | } |
| 6634 | |
| 6635 | /** |
| 6636 | * Sets the visibility of the indeterminate progress bar in the title. |
| 6637 | * <p> |
| 6638 | * In order for the progress bar to be shown, the feature must be requested |
| 6639 | * via {@link #requestWindowFeature(int)}. |
| 6640 | * |
| 6641 | * @param visible Whether to show the progress bars in the title. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6642 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6643 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6644 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6645 | public final void setProgressBarIndeterminateVisibility(boolean visible) { |
| 6646 | getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, |
| 6647 | visible ? Window.PROGRESS_VISIBILITY_ON : Window.PROGRESS_VISIBILITY_OFF); |
| 6648 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6649 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6650 | /** |
| 6651 | * Sets whether the horizontal progress bar in the title should be indeterminate (the circular |
| 6652 | * is always indeterminate). |
| 6653 | * <p> |
| 6654 | * In order for the progress bar to be shown, the feature must be requested |
| 6655 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6656 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6657 | * @param indeterminate Whether the horizontal progress bar should be indeterminate. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6658 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6659 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6660 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6661 | public final void setProgressBarIndeterminate(boolean indeterminate) { |
| 6662 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 6663 | indeterminate ? Window.PROGRESS_INDETERMINATE_ON |
| 6664 | : Window.PROGRESS_INDETERMINATE_OFF); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6665 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6666 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6667 | /** |
| 6668 | * Sets the progress for the progress bars in the title. |
| 6669 | * <p> |
| 6670 | * In order for the progress bar to be shown, the feature must be requested |
| 6671 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6672 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6673 | * @param progress The progress for the progress bar. Valid ranges are from |
| 6674 | * 0 to 10000 (both inclusive). If 10000 is given, the progress |
| 6675 | * bar will be completely filled and will fade out. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6676 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6677 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6678 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6679 | public final void setProgress(int progress) { |
| 6680 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, progress + Window.PROGRESS_START); |
| 6681 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6682 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6683 | /** |
| 6684 | * Sets the secondary progress for the progress bar in the title. This |
| 6685 | * progress is drawn between the primary progress (set via |
| 6686 | * {@link #setProgress(int)} and the background. It can be ideal for media |
| 6687 | * scenarios such as showing the buffering progress while the default |
| 6688 | * progress shows the play progress. |
| 6689 | * <p> |
| 6690 | * In order for the progress bar to be shown, the feature must be requested |
| 6691 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6692 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6693 | * @param secondaryProgress The secondary progress for the progress bar. Valid ranges are from |
| 6694 | * 0 to 10000 (both inclusive). |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6695 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6696 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6697 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6698 | public final void setSecondaryProgress(int secondaryProgress) { |
| 6699 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, |
| 6700 | secondaryProgress + Window.PROGRESS_SECONDARY_START); |
| 6701 | } |
| 6702 | |
| 6703 | /** |
| 6704 | * Suggests an audio stream whose volume should be changed by the hardware |
| 6705 | * volume controls. |
| 6706 | * <p> |
| 6707 | * The suggested audio stream will be tied to the window of this Activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6708 | * Volume requests which are received while the Activity is in the |
| 6709 | * foreground will affect this stream. |
| 6710 | * <p> |
| 6711 | * It is not guaranteed that the hardware volume controls will always change |
| 6712 | * this stream's volume (for example, if a call is in progress, its stream's |
| 6713 | * volume may be changed instead). To reset back to the default, use |
| 6714 | * {@link AudioManager#USE_DEFAULT_STREAM_TYPE}. |
| 6715 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6716 | * @param streamType The type of the audio stream whose volume should be |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6717 | * changed by the hardware volume controls. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6718 | */ |
| 6719 | public final void setVolumeControlStream(int streamType) { |
| 6720 | getWindow().setVolumeControlStream(streamType); |
| 6721 | } |
| 6722 | |
| 6723 | /** |
| 6724 | * Gets the suggested audio stream whose volume should be changed by the |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6725 | * hardware volume controls. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6726 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6727 | * @return The suggested audio stream type whose volume should be changed by |
| 6728 | * the hardware volume controls. |
| 6729 | * @see #setVolumeControlStream(int) |
| 6730 | */ |
| 6731 | public final int getVolumeControlStream() { |
| 6732 | return getWindow().getVolumeControlStream(); |
| 6733 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6734 | |
| 6735 | /** |
| 6736 | * Sets a {@link MediaController} to send media keys and volume changes to. |
| 6737 | * <p> |
| 6738 | * The controller will be tied to the window of this Activity. Media key and |
| 6739 | * volume events which are received while the Activity is in the foreground |
| 6740 | * will be forwarded to the controller and used to invoke transport controls |
| 6741 | * or adjust the volume. This may be used instead of or in addition to |
| 6742 | * {@link #setVolumeControlStream} to affect a specific session instead of a |
| 6743 | * specific stream. |
| 6744 | * <p> |
| 6745 | * It is not guaranteed that the hardware volume controls will always change |
| 6746 | * this session's volume (for example, if a call is in progress, its |
| 6747 | * stream's volume may be changed instead). To reset back to the default use |
| 6748 | * null as the controller. |
| 6749 | * |
| 6750 | * @param controller The controller for the session which should receive |
| 6751 | * media keys and volume changes. |
| 6752 | */ |
| 6753 | public final void setMediaController(MediaController controller) { |
| 6754 | getWindow().setMediaController(controller); |
| 6755 | } |
| 6756 | |
| 6757 | /** |
| 6758 | * Gets the controller which should be receiving media key and volume events |
| 6759 | * while this activity is in the foreground. |
| 6760 | * |
| 6761 | * @return The controller which should receive events. |
| 6762 | * @see #setMediaController(android.media.session.MediaController) |
| 6763 | */ |
| 6764 | public final MediaController getMediaController() { |
| 6765 | return getWindow().getMediaController(); |
| 6766 | } |
| 6767 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6768 | /** |
| 6769 | * Runs the specified action on the UI thread. If the current thread is the UI |
| 6770 | * thread, then the action is executed immediately. If the current thread is |
| 6771 | * not the UI thread, the action is posted to the event queue of the UI thread. |
| 6772 | * |
| 6773 | * @param action the action to run on the UI thread |
| 6774 | */ |
| 6775 | public final void runOnUiThread(Runnable action) { |
| 6776 | if (Thread.currentThread() != mUiThread) { |
| 6777 | mHandler.post(action); |
| 6778 | } else { |
| 6779 | action.run(); |
| 6780 | } |
| 6781 | } |
| 6782 | |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 6783 | /** @hide */ |
| 6784 | @Override |
| 6785 | public final void autofillClientRunOnUiThread(Runnable action) { |
| 6786 | runOnUiThread(action); |
| 6787 | } |
| 6788 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6789 | /** |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6790 | * Standard implementation of |
| 6791 | * {@link android.view.LayoutInflater.Factory#onCreateView} used when |
| 6792 | * inflating with the LayoutInflater returned by {@link #getSystemService}. |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6793 | * This implementation does nothing and is for |
| 6794 | * pre-{@link android.os.Build.VERSION_CODES#HONEYCOMB} apps. Newer apps |
| 6795 | * should use {@link #onCreateView(View, String, Context, AttributeSet)}. |
| 6796 | * |
| 6797 | * @see android.view.LayoutInflater#createView |
| 6798 | * @see android.view.Window#getLayoutInflater |
| 6799 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6800 | @Nullable |
Ian Lake | 0c807f4 | 2018-09-12 14:03:27 -0700 | [diff] [blame] | 6801 | public View onCreateView(@NonNull String name, @NonNull Context context, |
| 6802 | @NonNull AttributeSet attrs) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6803 | return null; |
| 6804 | } |
| 6805 | |
| 6806 | /** |
| 6807 | * Standard implementation of |
| 6808 | * {@link android.view.LayoutInflater.Factory2#onCreateView(View, String, Context, AttributeSet)} |
| 6809 | * used when inflating with the LayoutInflater returned by {@link #getSystemService}. |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6810 | * This implementation handles <fragment> tags to embed fragments inside |
| 6811 | * of the activity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6812 | * |
| 6813 | * @see android.view.LayoutInflater#createView |
| 6814 | * @see android.view.Window#getLayoutInflater |
| 6815 | */ |
Ian Lake | 0c807f4 | 2018-09-12 14:03:27 -0700 | [diff] [blame] | 6816 | @Nullable |
| 6817 | public View onCreateView(@Nullable View parent, @NonNull String name, |
| 6818 | @NonNull Context context, @NonNull AttributeSet attrs) { |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6819 | if (!"fragment".equals(name)) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6820 | return onCreateView(name, context, attrs); |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6821 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6822 | |
Adam Powell | 371a809 | 2014-06-20 12:51:12 -0700 | [diff] [blame] | 6823 | return mFragments.onCreateView(parent, name, context, attrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6824 | } |
| 6825 | |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6826 | /** |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6827 | * 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] | 6828 | * you run "adb shell dumpsys activity <activity_component_name>". |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6829 | * |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 6830 | * @param prefix Desired prefix to prepend at each line of output. |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6831 | * @param fd The raw file descriptor that the dump is being sent to. |
| 6832 | * @param writer The PrintWriter to which you should dump your state. This will be |
| 6833 | * closed for you after you return. |
| 6834 | * @param args additional arguments to the dump request. |
| 6835 | */ |
Ian Lake | 140fe12 | 2018-09-13 14:59:38 -0700 | [diff] [blame] | 6836 | public void dump(@NonNull String prefix, @Nullable FileDescriptor fd, |
| 6837 | @NonNull PrintWriter writer, @Nullable String[] args) { |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 6838 | dumpInner(prefix, fd, writer, args); |
| 6839 | } |
| 6840 | |
Ian Lake | 140fe12 | 2018-09-13 14:59:38 -0700 | [diff] [blame] | 6841 | void dumpInner(@NonNull String prefix, @Nullable FileDescriptor fd, |
| 6842 | @NonNull PrintWriter writer, @Nullable String[] args) { |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 6843 | if (args != null && args.length > 0) { |
| 6844 | // Handle special cases |
| 6845 | switch (args[0]) { |
| 6846 | case "--autofill": |
| 6847 | dumpAutofillManager(prefix, writer); |
| 6848 | return; |
Felipe Leme | b718e03 | 2018-12-10 09:44:23 -0800 | [diff] [blame] | 6849 | case "--contentcapture": |
| 6850 | dumpContentCaptureManager(prefix, writer); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 6851 | return; |
| 6852 | } |
Felipe Leme | b546ca7 | 2018-08-15 08:44:12 -0700 | [diff] [blame] | 6853 | } |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 6854 | writer.print(prefix); writer.print("Local Activity "); |
| 6855 | writer.print(Integer.toHexString(System.identityHashCode(this))); |
| 6856 | writer.println(" State:"); |
| 6857 | String innerPrefix = prefix + " "; |
| 6858 | writer.print(innerPrefix); writer.print("mResumed="); |
| 6859 | writer.print(mResumed); writer.print(" mStopped="); |
| 6860 | writer.print(mStopped); writer.print(" mFinished="); |
| 6861 | writer.println(mFinished); |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 6862 | writer.print(innerPrefix); writer.print("mChangingConfigurations="); |
| 6863 | writer.println(mChangingConfigurations); |
| 6864 | writer.print(innerPrefix); writer.print("mCurrentConfig="); |
| 6865 | writer.println(mCurrentConfig); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6866 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 6867 | mFragments.dumpLoaders(innerPrefix, fd, writer, args); |
| 6868 | mFragments.getFragmentManager().dump(innerPrefix, fd, writer, args); |
Dianne Hackborn | 57dd737 | 2015-07-27 18:11:14 -0700 | [diff] [blame] | 6869 | if (mVoiceInteractor != null) { |
| 6870 | mVoiceInteractor.dump(innerPrefix, fd, writer, args); |
| 6871 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6872 | |
Michael Wright | 5f48dc7 | 2013-11-01 12:42:49 -0700 | [diff] [blame] | 6873 | if (getWindow() != null && |
| 6874 | getWindow().peekDecorView() != null && |
| 6875 | getWindow().peekDecorView().getViewRootImpl() != null) { |
| 6876 | getWindow().peekDecorView().getViewRootImpl().dump(prefix, fd, writer, args); |
| 6877 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6878 | |
| 6879 | mHandler.getLooper().dump(new PrintWriterPrinter(writer), prefix); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 6880 | |
Felipe Leme | b546ca7 | 2018-08-15 08:44:12 -0700 | [diff] [blame] | 6881 | dumpAutofillManager(prefix, writer); |
Felipe Leme | b718e03 | 2018-12-10 09:44:23 -0800 | [diff] [blame] | 6882 | dumpContentCaptureManager(prefix, writer); |
Felipe Leme | b546ca7 | 2018-08-15 08:44:12 -0700 | [diff] [blame] | 6883 | |
| 6884 | ResourcesManager.getInstance().dump(prefix, writer); |
| 6885 | } |
| 6886 | |
| 6887 | void dumpAutofillManager(String prefix, PrintWriter writer) { |
Felipe Leme | 9d16dff | 2018-01-29 18:12:43 -0800 | [diff] [blame] | 6888 | final AutofillManager afm = getAutofillManager(); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 6889 | if (afm != null) { |
Felipe Leme | b546ca7 | 2018-08-15 08:44:12 -0700 | [diff] [blame] | 6890 | afm.dump(prefix, writer); |
Svet Ganov | 47b37aa | 2018-02-16 00:11:39 -0800 | [diff] [blame] | 6891 | writer.print(prefix); writer.print("Autofill Compat Mode: "); |
| 6892 | writer.println(isAutofillCompatibilityEnabled()); |
Felipe Leme | 686128e | 2017-10-17 14:02:20 -0700 | [diff] [blame] | 6893 | } else { |
| 6894 | writer.print(prefix); writer.println("No AutofillManager"); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 6895 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6896 | } |
| 6897 | |
Felipe Leme | b718e03 | 2018-12-10 09:44:23 -0800 | [diff] [blame] | 6898 | void dumpContentCaptureManager(String prefix, PrintWriter writer) { |
| 6899 | final ContentCaptureManager cm = getContentCaptureManager(); |
| 6900 | if (cm != null) { |
| 6901 | cm.dump(prefix, writer); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 6902 | } else { |
Felipe Leme | b718e03 | 2018-12-10 09:44:23 -0800 | [diff] [blame] | 6903 | writer.print(prefix); writer.println("No ContentCaptureManager"); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 6904 | } |
| 6905 | } |
| 6906 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6907 | /** |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6908 | * Bit indicating that this activity is "immersive" and should not be |
| 6909 | * interrupted by notifications if possible. |
| 6910 | * |
| 6911 | * This value is initially set by the manifest property |
| 6912 | * <code>android:immersive</code> but may be changed at runtime by |
| 6913 | * {@link #setImmersive}. |
| 6914 | * |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 6915 | * @see #setImmersive(boolean) |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6916 | * @see android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 6917 | */ |
| 6918 | public boolean isImmersive() { |
| 6919 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6920 | return ActivityTaskManager.getService().isImmersive(mToken); |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6921 | } catch (RemoteException e) { |
| 6922 | return false; |
| 6923 | } |
| 6924 | } |
| 6925 | |
| 6926 | /** |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 6927 | * Indication of whether this is the highest level activity in this task. Can be used to |
| 6928 | * determine whether an activity launched by this activity was placed in the same task or |
| 6929 | * another task. |
| 6930 | * |
| 6931 | * @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] | 6932 | */ |
Sunny Goyal | d85bed5 | 2018-09-25 12:01:01 -0700 | [diff] [blame] | 6933 | final boolean isTopOfTask() { |
George Mount | f43ea5d | 2016-05-26 09:52:53 -0700 | [diff] [blame] | 6934 | if (mToken == null || mWindow == null) { |
George Mount | d0ca0e0 | 2016-03-29 10:32:56 -0700 | [diff] [blame] | 6935 | return false; |
| 6936 | } |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 6937 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6938 | return ActivityTaskManager.getService().isTopOfTask(getActivityToken()); |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 6939 | } catch (RemoteException e) { |
| 6940 | return false; |
| 6941 | } |
| 6942 | } |
| 6943 | |
| 6944 | /** |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6945 | * Convert a translucent themed Activity {@link android.R.attr#windowIsTranslucent} to a |
| 6946 | * fullscreen opaque Activity. |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6947 | * <p> |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6948 | * 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] | 6949 | * Doing so will allow the {@link android.view.Surface} of the Activity behind to be released. |
| 6950 | * <p> |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6951 | * This call has no effect on non-translucent activities or on activities with the |
| 6952 | * {@link android.R.attr#windowIsFloating} attribute. |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6953 | * |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6954 | * @see #convertToTranslucent(android.app.Activity.TranslucentConversionListener, |
| 6955 | * ActivityOptions) |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6956 | * @see TranslucentConversionListener |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 6957 | * |
| 6958 | * @hide |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6959 | */ |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6960 | @SystemApi |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6961 | public void convertFromTranslucent() { |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6962 | try { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6963 | mTranslucentCallback = null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6964 | if (ActivityTaskManager.getService().convertFromTranslucent(mToken)) { |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 6965 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, true); |
| 6966 | } |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6967 | } catch (RemoteException e) { |
| 6968 | // pass |
| 6969 | } |
| 6970 | } |
| 6971 | |
| 6972 | /** |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6973 | * Convert a translucent themed Activity {@link android.R.attr#windowIsTranslucent} back from |
| 6974 | * opaque to translucent following a call to {@link #convertFromTranslucent()}. |
| 6975 | * <p> |
| 6976 | * Calling this allows the Activity behind this one to be seen again. Once all such Activities |
| 6977 | * have been redrawn {@link TranslucentConversionListener#onTranslucentConversionComplete} will |
| 6978 | * be called indicating that it is safe to make this activity translucent again. Until |
| 6979 | * {@link TranslucentConversionListener#onTranslucentConversionComplete} is called the image |
| 6980 | * behind the frontmost Activity will be indeterminate. |
| 6981 | * <p> |
| 6982 | * This call has no effect on non-translucent activities or on activities with the |
| 6983 | * {@link android.R.attr#windowIsFloating} attribute. |
| 6984 | * |
| 6985 | * @param callback the method to call when all visible Activities behind this one have been |
| 6986 | * drawn and it is safe to make this Activity translucent again. |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6987 | * @param options activity options delivered to the activity below this one. The options |
| 6988 | * are retrieved using {@link #getActivityOptions}. |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 6989 | * @return <code>true</code> if Window was opaque and will become translucent or |
| 6990 | * <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] | 6991 | * |
| 6992 | * @see #convertFromTranslucent() |
| 6993 | * @see TranslucentConversionListener |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 6994 | * |
| 6995 | * @hide |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6996 | */ |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6997 | @SystemApi |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 6998 | public boolean convertToTranslucent(TranslucentConversionListener callback, |
Jose Lima | 5517ea7 | 2014-06-10 12:31:43 -0700 | [diff] [blame] | 6999 | ActivityOptions options) { |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7000 | boolean drawComplete; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7001 | try { |
| 7002 | mTranslucentCallback = callback; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7003 | mChangeCanvasToTranslucent = ActivityTaskManager.getService().convertToTranslucent( |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 7004 | mToken, options == null ? null : options.toBundle()); |
George Mount | 9e18397 | 2014-09-03 12:35:09 -0700 | [diff] [blame] | 7005 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, false); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7006 | drawComplete = true; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7007 | } catch (RemoteException e) { |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7008 | // Make callback return as though it timed out. |
| 7009 | mChangeCanvasToTranslucent = false; |
| 7010 | drawComplete = false; |
| 7011 | } |
| 7012 | if (!mChangeCanvasToTranslucent && mTranslucentCallback != null) { |
| 7013 | // Window is already translucent. |
| 7014 | mTranslucentCallback.onTranslucentConversionComplete(drawComplete); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7015 | } |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 7016 | return mChangeCanvasToTranslucent; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7017 | } |
| 7018 | |
| 7019 | /** @hide */ |
| 7020 | void onTranslucentConversionComplete(boolean drawComplete) { |
| 7021 | if (mTranslucentCallback != null) { |
| 7022 | mTranslucentCallback.onTranslucentConversionComplete(drawComplete); |
| 7023 | mTranslucentCallback = null; |
| 7024 | } |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 7025 | if (mChangeCanvasToTranslucent) { |
| 7026 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, false); |
| 7027 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7028 | } |
| 7029 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 7030 | /** @hide */ |
| 7031 | public void onNewActivityOptions(ActivityOptions options) { |
| 7032 | mActivityTransitionState.setEnterActivityOptions(this, options); |
| 7033 | if (!mStopped) { |
| 7034 | mActivityTransitionState.enterReady(this); |
| 7035 | } |
| 7036 | } |
| 7037 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7038 | /** |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7039 | * Retrieve the ActivityOptions passed in from the launching activity or passed back |
| 7040 | * from an activity launched by this activity in its call to {@link |
| 7041 | * #convertToTranslucent(TranslucentConversionListener, ActivityOptions)} |
| 7042 | * |
| 7043 | * @return The ActivityOptions passed to {@link #convertToTranslucent}. |
| 7044 | * @hide |
| 7045 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7046 | @UnsupportedAppUsage |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7047 | ActivityOptions getActivityOptions() { |
| 7048 | try { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 7049 | return ActivityOptions.fromBundle( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7050 | ActivityTaskManager.getService().getActivityOptions(mToken)); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7051 | } catch (RemoteException e) { |
| 7052 | } |
| 7053 | return null; |
| 7054 | } |
| 7055 | |
| 7056 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7057 | * 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] | 7058 | * this method anytime between the start of {@link #onResume()} and the return from |
| 7059 | * {@link #onPause()}. If this call is successful then the activity will remain visible after |
| 7060 | * {@link #onPause()} is called, and is allowed to continue playing media in the background. |
| 7061 | * |
| 7062 | * <p>The actions of this call are reset each time that this activity is brought to the |
| 7063 | * front. That is, every time {@link #onResume()} is called the activity will be assumed |
| 7064 | * to not have requested visible behind. Therefore, if you want this activity to continue to |
| 7065 | * be visible in the background you must call this method again. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7066 | * |
| 7067 | * <p>Only fullscreen opaque activities may make this call. I.e. this call is a nop |
| 7068 | * for dialog and translucent activities. |
| 7069 | * |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 7070 | * <p>Under all circumstances, the activity must stop playing and release resources prior to or |
| 7071 | * within a call to {@link #onVisibleBehindCanceled()} or if this call returns false. |
| 7072 | * |
| 7073 | * <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] | 7074 | * the next call to onResume. |
| 7075 | * |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7076 | * @deprecated This method's functionality is no longer supported as of |
| 7077 | * {@link android.os.Build.VERSION_CODES#O} and will be removed in a future release. |
| 7078 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7079 | * @param visible true to notify the system that the activity wishes to be visible behind other |
| 7080 | * translucent activities, false to indicate otherwise. Resources must be |
| 7081 | * released when passing false to this method. |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7082 | * |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 7083 | * @return the resulting visibiity state. If true the activity will remain visible beyond |
| 7084 | * {@link #onPause()} if the next activity is translucent or not fullscreen. If false |
| 7085 | * then the activity may not count on being visible behind other translucent activities, |
| 7086 | * and must stop any media playback and release resources. |
| 7087 | * Returning false may occur in lieu of a call to {@link #onVisibleBehindCanceled()} so |
| 7088 | * the return value must be checked. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7089 | * |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 7090 | * @see #onVisibleBehindCanceled() |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7091 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7092 | @Deprecated |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7093 | public boolean requestVisibleBehind(boolean visible) { |
Robert Carr | 8661c5e | 2017-06-27 13:46:14 -0700 | [diff] [blame] | 7094 | return false; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7095 | } |
| 7096 | |
| 7097 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7098 | * Called when a translucent activity over this activity is becoming opaque or another |
| 7099 | * activity is being launched. Activities that override this method must call |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 7100 | * <code>super.onVisibleBehindCanceled()</code> or a SuperNotCalledException will be thrown. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7101 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7102 | * <p>When this method is called the activity has 500 msec to release any resources it may be |
| 7103 | * using while visible in the background. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7104 | * 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] | 7105 | * 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] | 7106 | * process. Otherwise {@link #onStop()} will be called following return. |
| 7107 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7108 | * @see #requestVisibleBehind(boolean) |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7109 | * |
| 7110 | * @deprecated This method's functionality is no longer supported as of |
| 7111 | * {@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] | 7112 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7113 | @Deprecated |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 7114 | @CallSuper |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 7115 | public void onVisibleBehindCanceled() { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7116 | mCalled = true; |
| 7117 | } |
| 7118 | |
| 7119 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7120 | * Translucent activities may call this to determine if there is an activity below them that |
| 7121 | * is currently set to be visible in the background. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7122 | * |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7123 | * @deprecated This method's functionality is no longer supported as of |
| 7124 | * {@link android.os.Build.VERSION_CODES#O} and will be removed in a future release. |
| 7125 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7126 | * @return true if an activity below is set to visible according to the most recent call to |
| 7127 | * {@link #requestVisibleBehind(boolean)}, false otherwise. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7128 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7129 | * @see #requestVisibleBehind(boolean) |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 7130 | * @see #onVisibleBehindCanceled() |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7131 | * @see #onBackgroundVisibleBehindChanged(boolean) |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7132 | * @hide |
| 7133 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7134 | @Deprecated |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7135 | @SystemApi |
| 7136 | public boolean isBackgroundVisibleBehind() { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7137 | return false; |
| 7138 | } |
| 7139 | |
| 7140 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7141 | * The topmost foreground activity will receive this call when the background visibility state |
| 7142 | * of the activity below it changes. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7143 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7144 | * 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] | 7145 | * due to a background activity finishing itself. |
| 7146 | * |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7147 | * @deprecated This method's functionality is no longer supported as of |
| 7148 | * {@link android.os.Build.VERSION_CODES#O} and will be removed in a future release. |
| 7149 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7150 | * @param visible true if a background activity is visible, false otherwise. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7151 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7152 | * @see #requestVisibleBehind(boolean) |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 7153 | * @see #onVisibleBehindCanceled() |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7154 | * @hide |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7155 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 7156 | @Deprecated |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 7157 | @SystemApi |
| 7158 | public void onBackgroundVisibleBehindChanged(boolean visible) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 7159 | } |
| 7160 | |
| 7161 | /** |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 7162 | * Activities cannot draw during the period that their windows are animating in. In order |
| 7163 | * to know when it is safe to begin drawing they can override this method which will be |
| 7164 | * called when the entering animation has completed. |
| 7165 | */ |
| 7166 | public void onEnterAnimationComplete() { |
| 7167 | } |
| 7168 | |
| 7169 | /** |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 7170 | * @hide |
| 7171 | */ |
| 7172 | public void dispatchEnterAnimationComplete() { |
chaviw | feb2e1e | 2018-12-19 17:24:11 -0800 | [diff] [blame] | 7173 | mEnterAnimationComplete = true; |
| 7174 | mInstrumentation.onEnterAnimationComplete(); |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 7175 | onEnterAnimationComplete(); |
| 7176 | if (getWindow() != null && getWindow().getDecorView() != null) { |
Felipe Leme | 0129769 | 2019-01-29 18:16:23 -0800 | [diff] [blame] | 7177 | View decorView = getWindow().getDecorView(); |
| 7178 | decorView.getViewTreeObserver().dispatchOnEnterAnimationComplete(); |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 7179 | } |
| 7180 | } |
| 7181 | |
| 7182 | /** |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 7183 | * Adjust the current immersive mode setting. |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 7184 | * |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 7185 | * Note that changing this value will have no effect on the activity's |
| 7186 | * {@link android.content.pm.ActivityInfo} structure; that is, if |
| 7187 | * <code>android:immersive</code> is set to <code>true</code> |
| 7188 | * in the application's manifest entry for this activity, the {@link |
| 7189 | * android.content.pm.ActivityInfo#flags ActivityInfo.flags} member will |
| 7190 | * always have its {@link android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 7191 | * FLAG_IMMERSIVE} bit set. |
| 7192 | * |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 7193 | * @see #isImmersive() |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 7194 | * @see android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 7195 | */ |
| 7196 | public void setImmersive(boolean i) { |
| 7197 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7198 | ActivityTaskManager.getService().setImmersive(mToken, i); |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 7199 | } catch (RemoteException e) { |
| 7200 | // pass |
| 7201 | } |
| 7202 | } |
| 7203 | |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 7204 | /** |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 7205 | * Enable or disable virtual reality (VR) mode for this Activity. |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 7206 | * |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 7207 | * <p>VR mode is a hint to Android system to switch to a mode optimized for VR applications |
| 7208 | * while this Activity has user focus.</p> |
| 7209 | * |
| 7210 | * <p>It is recommended that applications additionally declare |
| 7211 | * {@link android.R.attr#enableVrMode} in their manifest to allow for smooth activity |
| 7212 | * transitions when switching between VR activities.</p> |
| 7213 | * |
| 7214 | * <p>If the requested {@link android.service.vr.VrListenerService} component is not available, |
| 7215 | * VR mode will not be started. Developers can handle this case as follows:</p> |
| 7216 | * |
| 7217 | * <pre> |
| 7218 | * String servicePackage = "com.whatever.app"; |
| 7219 | * String serviceClass = "com.whatever.app.MyVrListenerService"; |
| 7220 | * |
| 7221 | * // Name of the component of the VrListenerService to start. |
| 7222 | * ComponentName serviceComponent = new ComponentName(servicePackage, serviceClass); |
| 7223 | * |
| 7224 | * try { |
| 7225 | * setVrModeEnabled(true, myComponentName); |
| 7226 | * } catch (PackageManager.NameNotFoundException e) { |
| 7227 | * List<ApplicationInfo> installed = getPackageManager().getInstalledApplications(0); |
| 7228 | * boolean isInstalled = false; |
| 7229 | * for (ApplicationInfo app : installed) { |
| 7230 | * if (app.packageName.equals(servicePackage)) { |
| 7231 | * isInstalled = true; |
| 7232 | * break; |
| 7233 | * } |
| 7234 | * } |
| 7235 | * if (isInstalled) { |
| 7236 | * // Package is installed, but not enabled in Settings. Let user enable it. |
| 7237 | * startActivity(new Intent(Settings.ACTION_VR_LISTENER_SETTINGS)); |
| 7238 | * } else { |
| 7239 | * // Package is not installed. Send an intent to download this. |
| 7240 | * sentIntentToLaunchAppStore(servicePackage); |
| 7241 | * } |
| 7242 | * } |
| 7243 | * </pre> |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 7244 | * |
| 7245 | * @param enabled {@code true} to enable this mode. |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 7246 | * @param requestedComponent the name of the component to use as a |
| 7247 | * {@link android.service.vr.VrListenerService} while VR mode is enabled. |
| 7248 | * |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 7249 | * @throws android.content.pm.PackageManager.NameNotFoundException if the given component |
| 7250 | * to run as a {@link android.service.vr.VrListenerService} is not installed, or has |
| 7251 | * not been enabled in user settings. |
| 7252 | * |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 7253 | * @see android.content.pm.PackageManager#FEATURE_VR_MODE_HIGH_PERFORMANCE |
| 7254 | * @see android.service.vr.VrListenerService |
| 7255 | * @see android.provider.Settings#ACTION_VR_LISTENER_SETTINGS |
| 7256 | * @see android.R.attr#enableVrMode |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 7257 | */ |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 7258 | public void setVrModeEnabled(boolean enabled, @NonNull ComponentName requestedComponent) |
| 7259 | throws PackageManager.NameNotFoundException { |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 7260 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7261 | if (ActivityTaskManager.getService().setVrMode(mToken, enabled, requestedComponent) |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 7262 | != 0) { |
| 7263 | throw new PackageManager.NameNotFoundException( |
| 7264 | requestedComponent.flattenToString()); |
| 7265 | } |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 7266 | } catch (RemoteException e) { |
| 7267 | // pass |
| 7268 | } |
| 7269 | } |
| 7270 | |
| 7271 | /** |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 7272 | * Start an action mode of the default type {@link ActionMode#TYPE_PRIMARY}. |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 7273 | * |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 7274 | * @param callback Callback that will manage lifecycle events for this action mode |
| 7275 | * @return The ActionMode that was started, or null if it was canceled |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 7276 | * |
| 7277 | * @see ActionMode |
| 7278 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 7279 | @Nullable |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 7280 | public ActionMode startActionMode(ActionMode.Callback callback) { |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 7281 | return mWindow.getDecorView().startActionMode(callback); |
| 7282 | } |
| 7283 | |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 7284 | /** |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 7285 | * Start an action mode of the given type. |
| 7286 | * |
| 7287 | * @param callback Callback that will manage lifecycle events for this action mode |
| 7288 | * @param type One of {@link ActionMode#TYPE_PRIMARY} or {@link ActionMode#TYPE_FLOATING}. |
| 7289 | * @return The ActionMode that was started, or null if it was canceled |
| 7290 | * |
| 7291 | * @see ActionMode |
| 7292 | */ |
| 7293 | @Nullable |
| 7294 | public ActionMode startActionMode(ActionMode.Callback callback, int type) { |
| 7295 | return mWindow.getDecorView().startActionMode(callback, type); |
| 7296 | } |
| 7297 | |
| 7298 | /** |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 7299 | * Give the Activity a chance to control the UI for an action mode requested |
| 7300 | * by the system. |
| 7301 | * |
| 7302 | * <p>Note: If you are looking for a notification callback that an action mode |
| 7303 | * has been started for this activity, see {@link #onActionModeStarted(ActionMode)}.</p> |
| 7304 | * |
| 7305 | * @param callback The callback that should control the new action mode |
| 7306 | * @return The new action mode, or <code>null</code> if the activity does not want to |
| 7307 | * provide special handling for this action mode. (It will be handled by the system.) |
| 7308 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 7309 | @Nullable |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7310 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 7311 | public ActionMode onWindowStartingActionMode(ActionMode.Callback callback) { |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 7312 | // Only Primary ActionModes are represented in the ActionBar. |
| 7313 | if (mActionModeTypeStarting == ActionMode.TYPE_PRIMARY) { |
| 7314 | initWindowDecorActionBar(); |
| 7315 | if (mActionBar != null) { |
| 7316 | return mActionBar.startActionMode(callback); |
| 7317 | } |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 7318 | } |
| 7319 | return null; |
| 7320 | } |
| 7321 | |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 7322 | /** |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 7323 | * {@inheritDoc} |
| 7324 | */ |
| 7325 | @Nullable |
| 7326 | @Override |
| 7327 | public ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int type) { |
| 7328 | try { |
| 7329 | mActionModeTypeStarting = type; |
| 7330 | return onWindowStartingActionMode(callback); |
| 7331 | } finally { |
| 7332 | mActionModeTypeStarting = ActionMode.TYPE_PRIMARY; |
| 7333 | } |
| 7334 | } |
| 7335 | |
| 7336 | /** |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 7337 | * Notifies the Activity that an action mode has been started. |
| 7338 | * Activity subclasses overriding this method should call the superclass implementation. |
| 7339 | * |
| 7340 | * @param mode The new action mode. |
| 7341 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 7342 | @CallSuper |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7343 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 7344 | public void onActionModeStarted(ActionMode mode) { |
| 7345 | } |
| 7346 | |
| 7347 | /** |
| 7348 | * Notifies the activity that an action mode has finished. |
| 7349 | * Activity subclasses overriding this method should call the superclass implementation. |
| 7350 | * |
| 7351 | * @param mode The action mode that just finished. |
| 7352 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 7353 | @CallSuper |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7354 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 7355 | public void onActionModeFinished(ActionMode mode) { |
| 7356 | } |
| 7357 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7358 | /** |
| 7359 | * Returns true if the app should recreate the task when navigating 'up' from this activity |
| 7360 | * by using targetIntent. |
| 7361 | * |
| 7362 | * <p>If this method returns false the app can trivially call |
| 7363 | * {@link #navigateUpTo(Intent)} using the same parameters to correctly perform |
| 7364 | * up navigation. If this method returns false, the app should synthesize a new task stack |
| 7365 | * by using {@link TaskStackBuilder} or another similar mechanism to perform up navigation.</p> |
| 7366 | * |
| 7367 | * @param targetIntent An intent representing the target destination for up navigation |
| 7368 | * @return true if navigating up should recreate a new task stack, false if the same task |
| 7369 | * should be used for the destination |
| 7370 | */ |
| 7371 | public boolean shouldUpRecreateTask(Intent targetIntent) { |
| 7372 | try { |
| 7373 | PackageManager pm = getPackageManager(); |
| 7374 | ComponentName cn = targetIntent.getComponent(); |
| 7375 | if (cn == null) { |
| 7376 | cn = targetIntent.resolveActivity(pm); |
| 7377 | } |
| 7378 | ActivityInfo info = pm.getActivityInfo(cn, 0); |
| 7379 | if (info.taskAffinity == null) { |
| 7380 | return false; |
| 7381 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7382 | return ActivityTaskManager.getService().shouldUpRecreateTask(mToken, info.taskAffinity); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7383 | } catch (RemoteException e) { |
| 7384 | return false; |
| 7385 | } catch (NameNotFoundException e) { |
| 7386 | return false; |
| 7387 | } |
| 7388 | } |
| 7389 | |
| 7390 | /** |
| 7391 | * Navigate from this activity to the activity specified by upIntent, finishing this activity |
| 7392 | * in the process. If the activity indicated by upIntent already exists in the task's history, |
| 7393 | * 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] | 7394 | * finished. |
| 7395 | * |
| 7396 | * <p>If the indicated activity does not appear in the history stack, this will finish |
| 7397 | * each activity in this task until the root activity of the task is reached, resulting in |
| 7398 | * an "in-app home" behavior. This can be useful in apps with a complex navigation hierarchy |
| 7399 | * when an activity may be reached by a path not passing through a canonical parent |
| 7400 | * activity.</p> |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7401 | * |
| 7402 | * <p>This method should be used when performing up navigation from within the same task |
| 7403 | * as the destination. If up navigation should cross tasks in some cases, see |
| 7404 | * {@link #shouldUpRecreateTask(Intent)}.</p> |
| 7405 | * |
| 7406 | * @param upIntent An intent representing the target destination for up navigation |
| 7407 | * |
| 7408 | * @return true if up navigation successfully reached the activity indicated by upIntent and |
| 7409 | * upIntent was delivered to it. false if an instance of the indicated activity could |
| 7410 | * not be found and this activity was simply finished normally. |
| 7411 | */ |
| 7412 | public boolean navigateUpTo(Intent upIntent) { |
| 7413 | if (mParent == null) { |
| 7414 | ComponentName destInfo = upIntent.getComponent(); |
| 7415 | if (destInfo == null) { |
| 7416 | destInfo = upIntent.resolveActivity(getPackageManager()); |
| 7417 | if (destInfo == null) { |
| 7418 | return false; |
| 7419 | } |
| 7420 | upIntent = new Intent(upIntent); |
| 7421 | upIntent.setComponent(destInfo); |
| 7422 | } |
| 7423 | int resultCode; |
| 7424 | Intent resultData; |
| 7425 | synchronized (this) { |
| 7426 | resultCode = mResultCode; |
| 7427 | resultData = mResultData; |
| 7428 | } |
| 7429 | if (resultData != null) { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 7430 | resultData.prepareToLeaveProcess(this); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7431 | } |
| 7432 | try { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 7433 | upIntent.prepareToLeaveProcess(this); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7434 | return ActivityTaskManager.getService().navigateUpTo(mToken, upIntent, |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7435 | resultCode, resultData); |
| 7436 | } catch (RemoteException e) { |
| 7437 | return false; |
| 7438 | } |
| 7439 | } else { |
| 7440 | return mParent.navigateUpToFromChild(this, upIntent); |
| 7441 | } |
| 7442 | } |
| 7443 | |
| 7444 | /** |
| 7445 | * This is called when a child activity of this one calls its |
| 7446 | * {@link #navigateUpTo} method. The default implementation simply calls |
| 7447 | * navigateUpTo(upIntent) on this activity (the parent). |
| 7448 | * |
| 7449 | * @param child The activity making the call. |
| 7450 | * @param upIntent An intent representing the target destination for up navigation |
| 7451 | * |
| 7452 | * @return true if up navigation successfully reached the activity indicated by upIntent and |
| 7453 | * upIntent was delivered to it. false if an instance of the indicated activity could |
| 7454 | * not be found and this activity was simply finished normally. |
| 7455 | */ |
| 7456 | public boolean navigateUpToFromChild(Activity child, Intent upIntent) { |
| 7457 | return navigateUpTo(upIntent); |
| 7458 | } |
| 7459 | |
| 7460 | /** |
| 7461 | * Obtain an {@link Intent} that will launch an explicit target activity specified by |
| 7462 | * this activity's logical parent. The logical parent is named in the application's manifest |
| 7463 | * by the {@link android.R.attr#parentActivityName parentActivityName} attribute. |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 7464 | * Activity subclasses may override this method to modify the Intent returned by |
| 7465 | * super.getParentActivityIntent() or to implement a different mechanism of retrieving |
| 7466 | * the parent intent entirely. |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7467 | * |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 7468 | * @return a new Intent targeting the defined parent of this activity or null if |
| 7469 | * there is no valid parent. |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7470 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 7471 | @Nullable |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7472 | public Intent getParentActivityIntent() { |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 7473 | final String parentName = mActivityInfo.parentActivityName; |
| 7474 | if (TextUtils.isEmpty(parentName)) { |
| 7475 | return null; |
| 7476 | } |
Adam Powell | 5a4010c | 2012-09-16 15:14:05 -0700 | [diff] [blame] | 7477 | |
| 7478 | // If the parent itself has no parent, generate a main activity intent. |
| 7479 | final ComponentName target = new ComponentName(this, parentName); |
| 7480 | try { |
| 7481 | final ActivityInfo parentInfo = getPackageManager().getActivityInfo(target, 0); |
| 7482 | final String parentActivity = parentInfo.parentActivityName; |
| 7483 | final Intent parentIntent = parentActivity == null |
| 7484 | ? Intent.makeMainActivity(target) |
| 7485 | : new Intent().setComponent(target); |
| 7486 | return parentIntent; |
| 7487 | } catch (NameNotFoundException e) { |
| 7488 | Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName + |
| 7489 | "' in manifest"); |
| 7490 | return null; |
| 7491 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7492 | } |
| 7493 | |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7494 | /** |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 7495 | * When {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7496 | * 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] | 7497 | * 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] | 7498 | * {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7499 | * |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7500 | * @param callback Used to manipulate shared element transitions on the launched Activity. |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7501 | */ |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7502 | public void setEnterSharedElementCallback(SharedElementCallback callback) { |
| 7503 | if (callback == null) { |
| 7504 | callback = SharedElementCallback.NULL_CALLBACK; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7505 | } |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7506 | mEnterTransitionListener = callback; |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7507 | } |
| 7508 | |
| 7509 | /** |
| 7510 | * When {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7511 | * 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] | 7512 | * will be called to handle shared elements on the <i>launching</i> Activity. Most |
| 7513 | * calls will only come when returning from the started Activity. |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 7514 | * This requires {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7515 | * |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7516 | * @param callback Used to manipulate shared element transitions on the launching Activity. |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7517 | */ |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7518 | public void setExitSharedElementCallback(SharedElementCallback callback) { |
| 7519 | if (callback == null) { |
| 7520 | callback = SharedElementCallback.NULL_CALLBACK; |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7521 | } |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7522 | mExitTransitionListener = callback; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7523 | } |
| 7524 | |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 7525 | /** |
| 7526 | * Postpone the entering activity transition when Activity was started with |
| 7527 | * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
| 7528 | * android.util.Pair[])}. |
| 7529 | * <p>This method gives the Activity the ability to delay starting the entering and |
| 7530 | * shared element transitions until all data is loaded. Until then, the Activity won't |
| 7531 | * draw into its window, leaving the window transparent. This may also cause the |
| 7532 | * returning animation to be delayed until data is ready. This method should be |
| 7533 | * called in {@link #onCreate(android.os.Bundle)} or in |
| 7534 | * {@link #onActivityReenter(int, android.content.Intent)}. |
| 7535 | * {@link #startPostponedEnterTransition()} must be called to allow the Activity to |
| 7536 | * start the transitions. If the Activity did not use |
| 7537 | * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
| 7538 | * android.util.Pair[])}, then this method does nothing.</p> |
| 7539 | */ |
| 7540 | public void postponeEnterTransition() { |
| 7541 | mActivityTransitionState.postponeEnterTransition(); |
| 7542 | } |
| 7543 | |
| 7544 | /** |
| 7545 | * Begin postponed transitions after {@link #postponeEnterTransition()} was called. |
| 7546 | * If postponeEnterTransition() was called, you must call startPostponedEnterTransition() |
| 7547 | * to have your Activity start drawing. |
| 7548 | */ |
| 7549 | public void startPostponedEnterTransition() { |
| 7550 | mActivityTransitionState.startPostponedEnterTransition(); |
| 7551 | } |
| 7552 | |
Vladislav Kaznacheev | b23a757 | 2015-12-18 12:23:43 -0800 | [diff] [blame] | 7553 | /** |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 7554 | * Create {@link DragAndDropPermissions} object bound to this activity and controlling the |
| 7555 | * access permissions for content URIs associated with the {@link DragEvent}. |
Vladislav Kaznacheev | b23a757 | 2015-12-18 12:23:43 -0800 | [diff] [blame] | 7556 | * @param event Drag event |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 7557 | * @return The {@link DragAndDropPermissions} object used to control access to the content URIs. |
| 7558 | * 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] | 7559 | */ |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 7560 | public DragAndDropPermissions requestDragAndDropPermissions(DragEvent event) { |
| 7561 | DragAndDropPermissions dragAndDropPermissions = DragAndDropPermissions.obtain(event); |
| 7562 | if (dragAndDropPermissions != null && dragAndDropPermissions.take(getActivityToken())) { |
| 7563 | return dragAndDropPermissions; |
Vladislav Kaznacheev | b23a757 | 2015-12-18 12:23:43 -0800 | [diff] [blame] | 7564 | } |
| 7565 | return null; |
| 7566 | } |
| 7567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7568 | // ------------------ Internal API ------------------ |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7569 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 7570 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7571 | final void setParent(Activity parent) { |
| 7572 | mParent = parent; |
| 7573 | } |
| 7574 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7575 | @UnsupportedAppUsage |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 7576 | final void attach(Context context, ActivityThread aThread, |
| 7577 | Instrumentation instr, IBinder token, int ident, |
| 7578 | Application application, Intent intent, ActivityInfo info, |
| 7579 | CharSequence title, Activity parent, String id, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 7580 | NonConfigurationInstances lastNonConfigurationInstances, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 7581 | Configuration config, String referrer, IVoiceInteractor voiceInteractor, |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 7582 | Window window, ActivityConfigCallback activityConfigCallback) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7583 | attachBaseContext(context); |
| 7584 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7585 | mFragments.attachHost(null /*parent*/); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7586 | |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 7587 | mWindow = new PhoneWindow(this, window, activityConfigCallback); |
Skuhne | ce2faa5 | 2015-08-11 10:36:38 -0700 | [diff] [blame] | 7588 | mWindow.setWindowControllerCallback(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7589 | mWindow.setCallback(this); |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 7590 | mWindow.setOnWindowDismissedCallback(this); |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 7591 | mWindow.getLayoutInflater().setPrivateFactory(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7592 | if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) { |
| 7593 | mWindow.setSoftInputMode(info.softInputMode); |
| 7594 | } |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 7595 | if (info.uiOptions != 0) { |
| 7596 | mWindow.setUiOptions(info.uiOptions); |
| 7597 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7598 | mUiThread = Thread.currentThread(); |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7600 | mMainThread = aThread; |
| 7601 | mInstrumentation = instr; |
| 7602 | mToken = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 7603 | mIdent = ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7604 | mApplication = application; |
| 7605 | mIntent = intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 7606 | mReferrer = referrer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7607 | mComponent = intent.getComponent(); |
| 7608 | mActivityInfo = info; |
| 7609 | mTitle = title; |
| 7610 | mParent = parent; |
| 7611 | mEmbeddedID = id; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 7612 | mLastNonConfigurationInstances = lastNonConfigurationInstances; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 7613 | if (voiceInteractor != null) { |
| 7614 | if (lastNonConfigurationInstances != null) { |
| 7615 | mVoiceInteractor = lastNonConfigurationInstances.voiceInteractor; |
| 7616 | } else { |
| 7617 | mVoiceInteractor = new VoiceInteractor(voiceInteractor, this, this, |
| 7618 | Looper.myLooper()); |
| 7619 | } |
| 7620 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7621 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7622 | mWindow.setWindowManager( |
| 7623 | (WindowManager)context.getSystemService(Context.WINDOW_SERVICE), |
| 7624 | mToken, mComponent.flattenToString(), |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 7625 | (info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7626 | if (mParent != null) { |
| 7627 | mWindow.setContainer(mParent.getWindow()); |
| 7628 | } |
| 7629 | mWindowManager = mWindow.getWindowManager(); |
| 7630 | mCurrentConfig = config; |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 7631 | |
| 7632 | mWindow.setColorMode(info.colorMode); |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7633 | |
Felipe Leme | a4f39cd | 2019-02-19 15:08:59 -0800 | [diff] [blame] | 7634 | setAutofillOptions(application.getAutofillOptions()); |
Felipe Leme | 326f15a | 2019-02-19 09:42:24 -0800 | [diff] [blame] | 7635 | setContentCaptureOptions(application.getContentCaptureOptions()); |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7636 | } |
| 7637 | |
| 7638 | private void enableAutofillCompatibilityIfNeeded() { |
| 7639 | if (isAutofillCompatibilityEnabled()) { |
| 7640 | final AutofillManager afm = getSystemService(AutofillManager.class); |
| 7641 | if (afm != null) { |
| 7642 | afm.enableCompatibilityMode(); |
| 7643 | } |
| 7644 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7645 | } |
| 7646 | |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 7647 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7648 | @UnsupportedAppUsage |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 7649 | public final IBinder getActivityToken() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7650 | return mParent != null ? mParent.getActivityToken() : mToken; |
| 7651 | } |
| 7652 | |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 7653 | /** @hide */ |
| 7654 | @VisibleForTesting |
| 7655 | public final ActivityThread getActivityThread() { |
| 7656 | return mMainThread; |
| 7657 | } |
| 7658 | |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7659 | final void performCreate(Bundle icicle) { |
| 7660 | performCreate(icicle, null); |
| 7661 | } |
| 7662 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7663 | @UnsupportedAppUsage |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7664 | final void performCreate(Bundle icicle, PersistableBundle persistentState) { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7665 | dispatchActivityPreCreated(icicle); |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7666 | mCanEnterPictureInPicture = true; |
| 7667 | restoreHasCurrentPermissionRequest(icicle); |
| 7668 | if (persistentState != null) { |
| 7669 | onCreate(icicle, persistentState); |
| 7670 | } else { |
| 7671 | onCreate(icicle); |
| 7672 | } |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7673 | writeEventLog(LOG_AM_ON_CREATE_CALLED, "performCreate"); |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7674 | mActivityTransitionState.readState(icicle); |
| 7675 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 7676 | mVisibleFromClient = !mWindow.getWindowStyle().getBoolean( |
| 7677 | com.android.internal.R.styleable.Window_windowNoDisplay, false); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 7678 | mFragments.dispatchActivityCreated(); |
Eino-Ville Talvala | 563df3b | 2016-06-06 22:04:54 +0000 | [diff] [blame] | 7679 | mActivityTransitionState.setEnterActivityOptions(this, getActivityOptions()); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7680 | dispatchActivityPostCreated(icicle); |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7681 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7682 | |
Ian Lake | 0b71b8e | 2018-09-13 13:56:26 -0700 | [diff] [blame] | 7683 | final void performNewIntent(@NonNull Intent intent) { |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7684 | mCanEnterPictureInPicture = true; |
| 7685 | onNewIntent(intent); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7686 | } |
| 7687 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7688 | final void performStart(String reason) { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7689 | dispatchActivityPreStarted(); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 7690 | mActivityTransitionState.setEnterActivityOptions(this, getActivityOptions()); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 7691 | mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7692 | mCalled = false; |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 7693 | mFragments.execPendingActions(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7694 | mInstrumentation.callActivityOnStart(this); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7695 | writeEventLog(LOG_AM_ON_START_CALLED, reason); |
| 7696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7697 | if (!mCalled) { |
| 7698 | throw new SuperNotCalledException( |
| 7699 | "Activity " + mComponent.toShortString() + |
| 7700 | " did not call through to super.onStart()"); |
| 7701 | } |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7702 | mFragments.dispatchStart(); |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7703 | mFragments.reportLoaderStart(); |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 7704 | |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 7705 | boolean isAppDebuggable = |
| 7706 | (mApplication.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 7707 | |
David Brazdil | 795cbfb | 2018-01-26 12:23:15 +0000 | [diff] [blame] | 7708 | // This property is set for all non-user builds except final release |
David Brazdil | 927d6de | 2018-01-24 19:54:30 +0000 | [diff] [blame] | 7709 | boolean isDlwarningEnabled = SystemProperties.getInt("ro.bionic.ld.warning", 0) == 1; |
| 7710 | |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 7711 | if (isAppDebuggable || isDlwarningEnabled) { |
| 7712 | String dlwarning = getDlWarning(); |
| 7713 | if (dlwarning != null) { |
Adam Powell | d93f3b1 | 2016-03-03 08:43:37 -0800 | [diff] [blame] | 7714 | String appName = getApplicationInfo().loadLabel(getPackageManager()) |
| 7715 | .toString(); |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 7716 | String warning = "Detected problems with app native libraries\n" + |
| 7717 | "(please consult log for detail):\n" + dlwarning; |
| 7718 | if (isAppDebuggable) { |
| 7719 | new AlertDialog.Builder(this). |
| 7720 | setTitle(appName). |
| 7721 | setMessage(warning). |
| 7722 | setPositiveButton(android.R.string.ok, null). |
| 7723 | setCancelable(false). |
| 7724 | show(); |
| 7725 | } else { |
| 7726 | Toast.makeText(this, appName + "\n" + warning, Toast.LENGTH_LONG).show(); |
| 7727 | } |
| 7728 | } |
| 7729 | } |
| 7730 | |
Tim Van Patten | ddc4391 | 2018-12-18 17:47:52 -0700 | [diff] [blame] | 7731 | GraphicsEnvironment.getInstance().showAngleInUseDialogBox(this); |
| 7732 | |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 7733 | mActivityTransitionState.enterReady(this); |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7734 | dispatchActivityPostStarted(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7735 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7736 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 7737 | /** |
| 7738 | * Restart the activity. |
| 7739 | * @param start Indicates whether the activity should also be started after restart. |
| 7740 | * The option to not start immediately is needed in case a transaction with |
| 7741 | * multiple lifecycle transitions is in progress. |
| 7742 | */ |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7743 | final void performRestart(boolean start, String reason) { |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 7744 | mCanEnterPictureInPicture = true; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 7745 | mFragments.noteStateNotSaved(); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 7746 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 7747 | if (mToken != null && mParent == null) { |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 7748 | // 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] | 7749 | WindowManagerGlobal.getInstance().setStoppedState(mToken, false /* stopped */); |
| 7750 | } |
| 7751 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7752 | if (mStopped) { |
| 7753 | mStopped = false; |
Dianne Hackborn | 185e3e2 | 2011-06-03 15:26:01 -0700 | [diff] [blame] | 7754 | |
| 7755 | synchronized (mManagedCursors) { |
| 7756 | final int N = mManagedCursors.size(); |
| 7757 | for (int i=0; i<N; i++) { |
| 7758 | ManagedCursor mc = mManagedCursors.get(i); |
| 7759 | if (mc.mReleased || mc.mUpdated) { |
| 7760 | if (!mc.mCursor.requery()) { |
Dianne Hackborn | a5445d3 | 2011-09-01 14:38:24 -0700 | [diff] [blame] | 7761 | if (getApplicationInfo().targetSdkVersion |
| 7762 | >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
| 7763 | throw new IllegalStateException( |
| 7764 | "trying to requery an already closed cursor " |
| 7765 | + mc.mCursor); |
| 7766 | } |
Dianne Hackborn | 185e3e2 | 2011-06-03 15:26:01 -0700 | [diff] [blame] | 7767 | } |
| 7768 | mc.mReleased = false; |
| 7769 | mc.mUpdated = false; |
| 7770 | } |
| 7771 | } |
| 7772 | } |
| 7773 | |
| 7774 | mCalled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7775 | mInstrumentation.callActivityOnRestart(this); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7776 | writeEventLog(LOG_AM_ON_RESTART_CALLED, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7777 | if (!mCalled) { |
| 7778 | throw new SuperNotCalledException( |
| 7779 | "Activity " + mComponent.toShortString() + |
| 7780 | " did not call through to super.onRestart()"); |
| 7781 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 7782 | if (start) { |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7783 | performStart(reason); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 7784 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7785 | } |
| 7786 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7787 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7788 | final void performResume(boolean followedByPause, String reason) { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7789 | dispatchActivityPreResumed(); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7790 | performRestart(true /* start */, reason); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7791 | |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 7792 | mFragments.execPendingActions(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7793 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 7794 | mLastNonConfigurationInstances = null; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7795 | |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 7796 | if (mAutoFillResetNeeded) { |
| 7797 | // When Activity is destroyed in paused state, and relaunch activity, there will be |
| 7798 | // extra onResume and onPause event, ignore the first onResume and onPause. |
| 7799 | // see ActivityThread.handleRelaunchActivity() |
| 7800 | mAutoFillIgnoreFirstResumePause = followedByPause; |
| 7801 | if (mAutoFillIgnoreFirstResumePause && DEBUG_LIFECYCLE) { |
| 7802 | Slog.v(TAG, "autofill will ignore first pause when relaunching " + this); |
| 7803 | } |
| 7804 | } |
| 7805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7806 | mCalled = false; |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 7807 | // mResumed is set by the instrumentation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7808 | mInstrumentation.callActivityOnResume(this); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7809 | writeEventLog(LOG_AM_ON_RESUME_CALLED, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7810 | if (!mCalled) { |
| 7811 | throw new SuperNotCalledException( |
| 7812 | "Activity " + mComponent.toShortString() + |
| 7813 | " did not call through to super.onResume()"); |
| 7814 | } |
| 7815 | |
Todd Kennedy | ee8c9c6 | 2014-12-10 14:22:59 -0800 | [diff] [blame] | 7816 | // invisible activities must be finished before onResume() completes |
| 7817 | if (!mVisibleFromClient && !mFinished) { |
| 7818 | Log.w(TAG, "An activity without a UI must call finish() before onResume() completes"); |
| 7819 | if (getApplicationInfo().targetSdkVersion |
| 7820 | > android.os.Build.VERSION_CODES.LOLLIPOP_MR1) { |
| 7821 | throw new IllegalStateException( |
| 7822 | "Activity " + mComponent.toShortString() + |
| 7823 | " did not call finish() prior to onResume() completing"); |
| 7824 | } |
| 7825 | } |
| 7826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7827 | // 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] | 7828 | mCalled = false; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7829 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7830 | mFragments.dispatchResume(); |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 7831 | mFragments.execPendingActions(); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 7832 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7833 | onPostResume(); |
| 7834 | if (!mCalled) { |
| 7835 | throw new SuperNotCalledException( |
| 7836 | "Activity " + mComponent.toShortString() + |
| 7837 | " did not call through to super.onPostResume()"); |
| 7838 | } |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7839 | dispatchActivityPostResumed(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7840 | } |
| 7841 | |
| 7842 | final void performPause() { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7843 | dispatchActivityPrePaused(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 7844 | mDoReportFullyDrawn = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7845 | mFragments.dispatchPause(); |
Dianne Hackborn | e794e9f | 2010-08-24 12:32:10 -0700 | [diff] [blame] | 7846 | mCalled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7847 | onPause(); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7848 | writeEventLog(LOG_AM_ON_PAUSE_CALLED, "performPause"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 7849 | mResumed = false; |
Dianne Hackborn | e794e9f | 2010-08-24 12:32:10 -0700 | [diff] [blame] | 7850 | if (!mCalled && getApplicationInfo().targetSdkVersion |
| 7851 | >= android.os.Build.VERSION_CODES.GINGERBREAD) { |
| 7852 | throw new SuperNotCalledException( |
| 7853 | "Activity " + mComponent.toShortString() + |
| 7854 | " did not call through to super.onPause()"); |
| 7855 | } |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7856 | dispatchActivityPostPaused(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7857 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7858 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7859 | final void performUserLeaving() { |
| 7860 | onUserInteraction(); |
| 7861 | onUserLeaveHint(); |
| 7862 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7863 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7864 | final void performStop(boolean preserveWindow, String reason) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 7865 | mDoReportFullyDrawn = false; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7866 | mFragments.doLoaderStop(mChangingConfigurations /*retain*/); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 7867 | |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7868 | // Disallow entering picture-in-picture after the activity has been stopped |
| 7869 | mCanEnterPictureInPicture = false; |
| 7870 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7871 | if (!mStopped) { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7872 | dispatchActivityPreStopped(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7873 | if (mWindow != null) { |
| 7874 | mWindow.closeAllPanels(); |
| 7875 | } |
| 7876 | |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 7877 | // If we're preserving the window, don't setStoppedState to true, since we |
| 7878 | // need the window started immediately again. Stopping the window will |
| 7879 | // destroys hardware resources and causes flicker. |
| 7880 | if (!preserveWindow && mToken != null && mParent == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7881 | WindowManagerGlobal.getInstance().setStoppedState(mToken, true); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 7882 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7883 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7884 | mFragments.dispatchStop(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7885 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7886 | mCalled = false; |
| 7887 | mInstrumentation.callActivityOnStop(this); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7888 | writeEventLog(LOG_AM_ON_STOP_CALLED, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7889 | if (!mCalled) { |
| 7890 | throw new SuperNotCalledException( |
| 7891 | "Activity " + mComponent.toShortString() + |
| 7892 | " did not call through to super.onStop()"); |
| 7893 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7894 | |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 7895 | synchronized (mManagedCursors) { |
| 7896 | final int N = mManagedCursors.size(); |
| 7897 | for (int i=0; i<N; i++) { |
| 7898 | ManagedCursor mc = mManagedCursors.get(i); |
| 7899 | if (!mc.mReleased) { |
| 7900 | mc.mCursor.deactivate(); |
| 7901 | mc.mReleased = true; |
| 7902 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7903 | } |
| 7904 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7906 | mStopped = true; |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7907 | dispatchActivityPostStopped(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7908 | } |
| 7909 | mResumed = false; |
| 7910 | } |
| 7911 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7912 | final void performDestroy() { |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7913 | dispatchActivityPreDestroyed(); |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 7914 | mDestroyed = true; |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 7915 | mWindow.destroy(); |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7916 | mFragments.dispatchDestroy(); |
| 7917 | onDestroy(); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7918 | writeEventLog(LOG_AM_ON_DESTROY_CALLED, "performDestroy"); |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7919 | mFragments.doLoaderDestroy(); |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 7920 | if (mVoiceInteractor != null) { |
| 7921 | mVoiceInteractor.detachActivity(); |
| 7922 | } |
Ian Lake | 8a88cd6 | 2018-09-28 13:25:20 -0700 | [diff] [blame] | 7923 | dispatchActivityPostDestroyed(); |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7924 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7925 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7926 | final void dispatchMultiWindowModeChanged(boolean isInMultiWindowMode, |
| 7927 | Configuration newConfig) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7928 | if (DEBUG_LIFECYCLE) Slog.v(TAG, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7929 | "dispatchMultiWindowModeChanged " + this + ": " + isInMultiWindowMode |
| 7930 | + " " + newConfig); |
| 7931 | mFragments.dispatchMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7932 | if (mWindow != null) { |
| 7933 | mWindow.onMultiWindowModeChanged(); |
| 7934 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7935 | onMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7936 | } |
| 7937 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7938 | final void dispatchPictureInPictureModeChanged(boolean isInPictureInPictureMode, |
| 7939 | Configuration newConfig) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7940 | if (DEBUG_LIFECYCLE) Slog.v(TAG, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7941 | "dispatchPictureInPictureModeChanged " + this + ": " + isInPictureInPictureMode |
| 7942 | + " " + newConfig); |
| 7943 | mFragments.dispatchPictureInPictureModeChanged(isInPictureInPictureMode, newConfig); |
Winson Chung | 4d8681f | 2017-05-23 16:22:08 -0700 | [diff] [blame] | 7944 | if (mWindow != null) { |
| 7945 | mWindow.onPictureInPictureModeChanged(isInPictureInPictureMode); |
| 7946 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7947 | onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig); |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7948 | } |
| 7949 | |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7950 | /** |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 7951 | * @hide |
| 7952 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7953 | @UnsupportedAppUsage |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 7954 | public final boolean isResumed() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7955 | return mResumed; |
| 7956 | } |
| 7957 | |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 7958 | private void storeHasCurrentPermissionRequest(Bundle bundle) { |
| 7959 | if (bundle != null && mHasCurrentPermissionsRequest) { |
| 7960 | bundle.putBoolean(HAS_CURENT_PERMISSIONS_REQUEST_KEY, true); |
| 7961 | } |
| 7962 | } |
| 7963 | |
| 7964 | private void restoreHasCurrentPermissionRequest(Bundle bundle) { |
| 7965 | if (bundle != null) { |
| 7966 | mHasCurrentPermissionsRequest = bundle.getBoolean( |
| 7967 | HAS_CURENT_PERMISSIONS_REQUEST_KEY, false); |
| 7968 | } |
| 7969 | } |
| 7970 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7971 | @UnsupportedAppUsage |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 7972 | void dispatchActivityResult(String who, int requestCode, int resultCode, Intent data, |
| 7973 | String reason) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 7974 | if (false) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7975 | TAG, "Dispatching result: who=" + who + ", reqCode=" + requestCode |
| 7976 | + ", resCode=" + resultCode + ", data=" + data); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 7977 | mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7978 | if (who == null) { |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 7979 | onActivityResult(requestCode, resultCode, data); |
| 7980 | } else if (who.startsWith(REQUEST_PERMISSIONS_WHO_PREFIX)) { |
| 7981 | who = who.substring(REQUEST_PERMISSIONS_WHO_PREFIX.length()); |
| 7982 | if (TextUtils.isEmpty(who)) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 7983 | dispatchRequestPermissionsResult(requestCode, data); |
| 7984 | } else { |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 7985 | Fragment frag = mFragments.findFragmentByWho(who); |
| 7986 | if (frag != null) { |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 7987 | dispatchRequestPermissionsResultToFragment(requestCode, data, frag); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 7988 | } |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 7989 | } |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 7990 | } else if (who.startsWith("@android:view:")) { |
| 7991 | ArrayList<ViewRootImpl> views = WindowManagerGlobal.getInstance().getRootViews( |
| 7992 | getActivityToken()); |
| 7993 | for (ViewRootImpl viewRoot : views) { |
| 7994 | if (viewRoot.getView() != null |
| 7995 | && viewRoot.getView().dispatchActivityResult( |
| 7996 | who, requestCode, resultCode, data)) { |
| 7997 | return; |
| 7998 | } |
| 7999 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 8000 | } else if (who.startsWith(AUTO_FILL_AUTH_WHO_PREFIX)) { |
Svet Ganov | 00c771dc | 2017-02-19 00:06:22 -0800 | [diff] [blame] | 8001 | Intent resultData = (resultCode == Activity.RESULT_OK) ? data : null; |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 8002 | getAutofillManager().onAuthenticationResult(requestCode, resultData, getCurrentFocus()); |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 8003 | } else { |
| 8004 | Fragment frag = mFragments.findFragmentByWho(who); |
| 8005 | if (frag != null) { |
| 8006 | frag.onActivityResult(requestCode, resultCode, data); |
| 8007 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8008 | } |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 8009 | writeEventLog(LOG_AM_ON_ACTIVITY_RESULT_CALLED, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8010 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 8011 | |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8012 | /** |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8013 | * Request to put this activity in a mode where the user is locked to a restricted set of |
| 8014 | * applications. |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8015 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8016 | * <p>If {@link DevicePolicyManager#isLockTaskPermitted(String)} returns {@code true} |
| 8017 | * for this component, the current task will be launched directly into LockTask mode. Only apps |
| 8018 | * whitelisted by {@link DevicePolicyManager#setLockTaskPackages(ComponentName, String[])} can |
| 8019 | * be launched while LockTask mode is active. The user will not be able to leave this mode |
| 8020 | * until this activity calls {@link #stopLockTask()}. Calling this method while the device is |
| 8021 | * already in LockTask mode has no effect. |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8022 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8023 | * <p>Otherwise, the current task will be launched into screen pinning mode. In this case, the |
| 8024 | * system will prompt the user with a dialog requesting permission to use this mode. |
| 8025 | * The user can exit at any time through instructions shown on the request dialog. Calling |
| 8026 | * {@link #stopLockTask()} will also terminate this mode. |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 8027 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8028 | * <p><strong>Note:</strong> this method can only be called when the activity is foreground. |
| 8029 | * That is, between {@link #onResume()} and {@link #onPause()}. |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 8030 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8031 | * @see #stopLockTask() |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 8032 | * @see android.R.attr#lockTaskMode |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8033 | */ |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 8034 | public void startLockTask() { |
| 8035 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 8036 | ActivityTaskManager.getService().startLockTaskModeByToken(mToken); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 8037 | } catch (RemoteException e) { |
| 8038 | } |
| 8039 | } |
| 8040 | |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8041 | /** |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8042 | * Stop the current task from being locked. |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8043 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8044 | * <p>Called to end the LockTask or screen pinning mode started by {@link #startLockTask()}. |
| 8045 | * 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] | 8046 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8047 | * <p><strong>Note:</strong> If the device is in LockTask mode that is not initially started |
| 8048 | * by this activity, then calling this method will not terminate the LockTask mode, but only |
| 8049 | * finish its own task. The device will remain in LockTask mode, until the activity which |
| 8050 | * started the LockTask mode calls this method, or until its whitelist authorization is revoked |
| 8051 | * by {@link DevicePolicyManager#setLockTaskPackages(ComponentName, String[])}. |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 8052 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 8053 | * @see #startLockTask() |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 8054 | * @see android.R.attr#lockTaskMode |
| 8055 | * @see ActivityManager#getLockTaskModeState() |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 8056 | */ |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 8057 | public void stopLockTask() { |
| 8058 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 8059 | ActivityTaskManager.getService().stopLockTaskModeByToken(mToken); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 8060 | } catch (RemoteException e) { |
| 8061 | } |
| 8062 | } |
| 8063 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 8064 | /** |
Craig Mautner | c21ae9e | 2015-04-15 09:45:42 -0700 | [diff] [blame] | 8065 | * Shows the user the system defined message for telling the user how to exit |
| 8066 | * lock task mode. The task containing this activity must be in lock task mode at the time |
| 8067 | * of this call for the message to be displayed. |
| 8068 | */ |
| 8069 | public void showLockTaskEscapeMessage() { |
| 8070 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 8071 | ActivityTaskManager.getService().showLockTaskEscapeMessage(mToken); |
Craig Mautner | c21ae9e | 2015-04-15 09:45:42 -0700 | [diff] [blame] | 8072 | } catch (RemoteException e) { |
| 8073 | } |
| 8074 | } |
| 8075 | |
| 8076 | /** |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 8077 | * Check whether the caption on freeform windows is displayed directly on the content. |
| 8078 | * |
| 8079 | * @return True if caption is displayed on content, false if it pushes the content down. |
| 8080 | * |
Elliot Waite | d5ed3bc | 2017-01-25 15:22:55 -0800 | [diff] [blame] | 8081 | * @see #setOverlayWithDecorCaptionEnabled(boolean) |
Wale Ogunwale | 724ca14 | 2017-04-24 13:40:34 -0700 | [diff] [blame] | 8082 | * @hide |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 8083 | */ |
| 8084 | public boolean isOverlayWithDecorCaptionEnabled() { |
| 8085 | return mWindow.isOverlayWithDecorCaptionEnabled(); |
| 8086 | } |
| 8087 | |
| 8088 | /** |
Filip Gruszczynski | 6325065 | 2015-11-18 14:43:01 -0800 | [diff] [blame] | 8089 | * Set whether the caption should displayed directly on the content rather than push it down. |
| 8090 | * |
| 8091 | * This affects only freeform windows since they display the caption and only the main |
| 8092 | * window of the activity. The caption is used to drag the window around and also shows |
| 8093 | * maximize and close action buttons. |
Wale Ogunwale | 724ca14 | 2017-04-24 13:40:34 -0700 | [diff] [blame] | 8094 | * @hide |
Filip Gruszczynski | 6325065 | 2015-11-18 14:43:01 -0800 | [diff] [blame] | 8095 | */ |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 8096 | public void setOverlayWithDecorCaptionEnabled(boolean enabled) { |
| 8097 | mWindow.setOverlayWithDecorCaptionEnabled(enabled); |
Filip Gruszczynski | 6325065 | 2015-11-18 14:43:01 -0800 | [diff] [blame] | 8098 | } |
| 8099 | |
| 8100 | /** |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 8101 | * Interface for informing a translucent {@link Activity} once all visible activities below it |
| 8102 | * have completed drawing. This is necessary only after an {@link Activity} has been made |
| 8103 | * opaque using {@link Activity#convertFromTranslucent()} and before it has been drawn |
| 8104 | * translucent again following a call to {@link |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 8105 | * Activity#convertToTranslucent(android.app.Activity.TranslucentConversionListener, |
| 8106 | * ActivityOptions)} |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 8107 | * |
| 8108 | * @hide |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 8109 | */ |
Jose Lima | 1491485 | 2014-08-14 09:14:12 -0700 | [diff] [blame] | 8110 | @SystemApi |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 8111 | public interface TranslucentConversionListener { |
| 8112 | /** |
| 8113 | * Callback made following {@link Activity#convertToTranslucent} once all visible Activities |
| 8114 | * below the top one have been redrawn. Following this callback it is safe to make the top |
| 8115 | * Activity translucent because the underlying Activity has been drawn. |
| 8116 | * |
| 8117 | * @param drawComplete True if the background Activity has drawn itself. False if a timeout |
| 8118 | * occurred waiting for the Activity to complete drawing. |
| 8119 | * |
| 8120 | * @see Activity#convertFromTranslucent() |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 8121 | * @see Activity#convertToTranslucent(TranslucentConversionListener, ActivityOptions) |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 8122 | */ |
| 8123 | public void onTranslucentConversionComplete(boolean drawComplete); |
| 8124 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 8125 | |
| 8126 | private void dispatchRequestPermissionsResult(int requestCode, Intent data) { |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 8127 | mHasCurrentPermissionsRequest = false; |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 8128 | // If the package installer crashed we may have not data - best effort. |
| 8129 | String[] permissions = (data != null) ? data.getStringArrayExtra( |
| 8130 | PackageManager.EXTRA_REQUEST_PERMISSIONS_NAMES) : new String[0]; |
| 8131 | final int[] grantResults = (data != null) ? data.getIntArrayExtra( |
| 8132 | PackageManager.EXTRA_REQUEST_PERMISSIONS_RESULTS) : new int[0]; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 8133 | onRequestPermissionsResult(requestCode, permissions, grantResults); |
| 8134 | } |
| 8135 | |
| 8136 | private void dispatchRequestPermissionsResultToFragment(int requestCode, Intent data, |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 8137 | Fragment fragment) { |
| 8138 | // If the package installer crashed we may have not data - best effort. |
| 8139 | String[] permissions = (data != null) ? data.getStringArrayExtra( |
| 8140 | PackageManager.EXTRA_REQUEST_PERMISSIONS_NAMES) : new String[0]; |
| 8141 | final int[] grantResults = (data != null) ? data.getIntArrayExtra( |
| 8142 | PackageManager.EXTRA_REQUEST_PERMISSIONS_RESULTS) : new int[0]; |
| 8143 | fragment.onRequestPermissionsResult(requestCode, permissions, grantResults); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 8144 | } |
| 8145 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 8146 | /** @hide */ |
| 8147 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8148 | public final void autofillClientAuthenticate(int authenticationId, IntentSender intent, |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 8149 | Intent fillInIntent) { |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 8150 | try { |
| 8151 | startIntentSenderForResultInner(intent, AUTO_FILL_AUTH_WHO_PREFIX, |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 8152 | authenticationId, fillInIntent, 0, 0, null); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 8153 | } catch (IntentSender.SendIntentException e) { |
| 8154 | Log.e(TAG, "authenticate() failed for intent:" + intent, e); |
| 8155 | } |
| 8156 | } |
| 8157 | |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 8158 | /** @hide */ |
| 8159 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8160 | public final void autofillClientResetableStateAvailable() { |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 8161 | mAutoFillResetNeeded = true; |
| 8162 | } |
| 8163 | |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 8164 | /** @hide */ |
| 8165 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8166 | public final boolean autofillClientRequestShowFillUi(@NonNull View anchor, int width, |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 8167 | int height, @Nullable Rect anchorBounds, IAutofillWindowPresenter presenter) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 8168 | final boolean wasShowing; |
| 8169 | |
| 8170 | if (mAutofillPopupWindow == null) { |
| 8171 | wasShowing = false; |
| 8172 | mAutofillPopupWindow = new AutofillPopupWindow(presenter); |
| 8173 | } else { |
| 8174 | wasShowing = mAutofillPopupWindow.isShowing(); |
| 8175 | } |
Svet Ganov | 374cae1 | 2017-05-10 13:42:33 -0700 | [diff] [blame] | 8176 | mAutofillPopupWindow.update(anchor, 0, 0, width, height, anchorBounds); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 8177 | |
| 8178 | return !wasShowing && mAutofillPopupWindow.isShowing(); |
| 8179 | } |
| 8180 | |
| 8181 | /** @hide */ |
| 8182 | @Override |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 8183 | public final void autofillClientDispatchUnhandledKey(@NonNull View anchor, |
| 8184 | @NonNull KeyEvent keyEvent) { |
| 8185 | ViewRootImpl rootImpl = anchor.getViewRootImpl(); |
| 8186 | if (rootImpl != null) { |
| 8187 | // dont care if anchorView is current focus, for example a custom view may only receive |
| 8188 | // touchEvent, not focusable but can still trigger autofill window. The Key handling |
| 8189 | // might be inside parent of the custom view. |
| 8190 | rootImpl.dispatchKeyFromAutofill(keyEvent); |
| 8191 | } |
| 8192 | } |
| 8193 | |
| 8194 | /** @hide */ |
| 8195 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8196 | public final boolean autofillClientRequestHideFillUi() { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 8197 | if (mAutofillPopupWindow == null) { |
| 8198 | return false; |
| 8199 | } |
| 8200 | mAutofillPopupWindow.dismiss(); |
| 8201 | mAutofillPopupWindow = null; |
| 8202 | return true; |
| 8203 | } |
| 8204 | |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 8205 | /** @hide */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 8206 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8207 | public final boolean autofillClientIsFillUiShowing() { |
| 8208 | return mAutofillPopupWindow != null && mAutofillPopupWindow.isShowing(); |
| 8209 | } |
| 8210 | |
| 8211 | /** @hide */ |
| 8212 | @Override |
| 8213 | @NonNull |
| 8214 | public final View[] autofillClientFindViewsByAutofillIdTraversal( |
| 8215 | @NonNull AutofillId[] autofillId) { |
| 8216 | final View[] views = new View[autofillId.length]; |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 8217 | final ArrayList<ViewRootImpl> roots = |
| 8218 | WindowManagerGlobal.getInstance().getRootViews(getActivityToken()); |
| 8219 | |
| 8220 | for (int rootNum = 0; rootNum < roots.size(); rootNum++) { |
| 8221 | final View rootView = roots.get(rootNum).getView(); |
| 8222 | |
| 8223 | if (rootView != null) { |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8224 | final int viewCount = autofillId.length; |
| 8225 | for (int viewNum = 0; viewNum < viewCount; viewNum++) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 8226 | if (views[viewNum] == null) { |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 8227 | views[viewNum] = rootView.findViewByAutofillIdTraversal( |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8228 | autofillId[viewNum].getViewId()); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 8229 | } |
| 8230 | } |
| 8231 | } |
| 8232 | } |
| 8233 | |
| 8234 | return views; |
| 8235 | } |
| 8236 | |
| 8237 | /** @hide */ |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 8238 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8239 | @Nullable |
| 8240 | public final View autofillClientFindViewByAutofillIdTraversal(AutofillId autofillId) { |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 8241 | final ArrayList<ViewRootImpl> roots = |
| 8242 | WindowManagerGlobal.getInstance().getRootViews(getActivityToken()); |
| 8243 | for (int rootNum = 0; rootNum < roots.size(); rootNum++) { |
| 8244 | final View rootView = roots.get(rootNum).getView(); |
| 8245 | |
| 8246 | if (rootView != null) { |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8247 | final View view = rootView.findViewByAutofillIdTraversal(autofillId.getViewId()); |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 8248 | if (view != null) { |
| 8249 | return view; |
| 8250 | } |
| 8251 | } |
| 8252 | } |
| 8253 | |
| 8254 | return null; |
| 8255 | } |
| 8256 | |
| 8257 | /** @hide */ |
| 8258 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8259 | public final @NonNull boolean[] autofillClientGetViewVisibility( |
| 8260 | @NonNull AutofillId[] autofillIds) { |
| 8261 | final int autofillIdCount = autofillIds.length; |
| 8262 | final boolean[] visible = new boolean[autofillIdCount]; |
| 8263 | for (int i = 0; i < autofillIdCount; i++) { |
| 8264 | final AutofillId autofillId = autofillIds[i]; |
| 8265 | final View view = autofillClientFindViewByAutofillIdTraversal(autofillId); |
| 8266 | if (view != null) { |
Felipe Leme | a75333c | 2019-01-22 15:45:32 -0800 | [diff] [blame] | 8267 | if (!autofillId.isVirtualInt()) { |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8268 | visible[i] = view.isVisibleToUser(); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 8269 | } else { |
Felipe Leme | a75333c | 2019-01-22 15:45:32 -0800 | [diff] [blame] | 8270 | visible[i] = view.isVisibleToUserForAutofill(autofillId.getVirtualChildIntId()); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 8271 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 8272 | } |
| 8273 | } |
Felipe Leme | 5b32ebe | 2018-02-15 12:52:19 -0800 | [diff] [blame] | 8274 | if (android.view.autofill.Helper.sVerbose) { |
| 8275 | Log.v(TAG, "autofillClientGetViewVisibility(): " + Arrays.toString(visible)); |
| 8276 | } |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8277 | return visible; |
| 8278 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 8279 | |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8280 | /** @hide */ |
| 8281 | public final @Nullable View autofillClientFindViewByAccessibilityIdTraversal(int viewId, |
| 8282 | int windowId) { |
| 8283 | final ArrayList<ViewRootImpl> roots = WindowManagerGlobal.getInstance() |
| 8284 | .getRootViews(getActivityToken()); |
| 8285 | for (int rootNum = 0; rootNum < roots.size(); rootNum++) { |
| 8286 | final View rootView = roots.get(rootNum).getView(); |
| 8287 | if (rootView != null && rootView.getAccessibilityWindowId() == windowId) { |
| 8288 | final View view = rootView.findViewByAccessibilityIdTraversal(viewId); |
| 8289 | if (view != null) { |
| 8290 | return view; |
| 8291 | } |
| 8292 | } |
| 8293 | } |
| 8294 | return null; |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 8295 | } |
| 8296 | |
| 8297 | /** @hide */ |
| 8298 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8299 | public final @Nullable IBinder autofillClientGetActivityToken() { |
| 8300 | return getActivityToken(); |
| 8301 | } |
| 8302 | |
| 8303 | /** @hide */ |
| 8304 | @Override |
| 8305 | public final boolean autofillClientIsVisibleForAutofill() { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 8306 | return !mStopped; |
| 8307 | } |
| 8308 | |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 8309 | /** @hide */ |
| 8310 | @Override |
Felipe Leme | 42b9793 | 2018-02-20 13:04:31 -0800 | [diff] [blame] | 8311 | public final boolean autofillClientIsCompatibilityModeEnabled() { |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 8312 | return isAutofillCompatibilityEnabled(); |
| 8313 | } |
| 8314 | |
| 8315 | /** @hide */ |
| 8316 | @Override |
| 8317 | public final boolean isDisablingEnterExitEventForAutofill() { |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 8318 | return mAutoFillIgnoreFirstResumePause || !mResumed; |
| 8319 | } |
| 8320 | |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 8321 | /** |
| 8322 | * If set to true, this indicates to the system that it should never take a |
| 8323 | * screenshot of the activity to be used as a representation while it is not in a started state. |
| 8324 | * <p> |
| 8325 | * Note that the system may use the window background of the theme instead to represent |
| 8326 | * the window when it is not running. |
| 8327 | * <p> |
| 8328 | * Also note that in comparison to {@link android.view.WindowManager.LayoutParams#FLAG_SECURE}, |
| 8329 | * this only affects the behavior when the activity's screenshot would be used as a |
| 8330 | * representation when the activity is not in a started state, i.e. in Overview. The system may |
| 8331 | * still take screenshots of the activity in other contexts; for example, when the user takes a |
| 8332 | * screenshot of the entire screen, or when the active |
| 8333 | * {@link android.service.voice.VoiceInteractionService} requests a screenshot via |
| 8334 | * {@link android.service.voice.VoiceInteractionSession#SHOW_WITH_SCREENSHOT}. |
| 8335 | * |
| 8336 | * @param disable {@code true} to disable preview screenshots; {@code false} otherwise. |
| 8337 | * @hide |
| 8338 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 8339 | @UnsupportedAppUsage |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 8340 | public void setDisablePreviewScreenshots(boolean disable) { |
| 8341 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 8342 | ActivityTaskManager.getService().setDisablePreviewScreenshots(mToken, disable); |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 8343 | } catch (RemoteException e) { |
| 8344 | Log.e(TAG, "Failed to call setDisablePreviewScreenshots", e); |
| 8345 | } |
| 8346 | } |
| 8347 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 8348 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 8349 | * 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] | 8350 | * the lockscreen is up and the activity is resumed. Normally an activity will be transitioned |
| 8351 | * to the stopped state if it is started while the lockscreen is up, but with this flag set the |
| 8352 | * activity will remain in the resumed state visible on-top of the lock screen. This value can |
| 8353 | * be set as a manifest attribute using {@link android.R.attr#showWhenLocked}. |
| 8354 | * |
| 8355 | * @param showWhenLocked {@code true} to show the {@link Activity} on top of the lock screen; |
| 8356 | * {@code false} otherwise. |
| 8357 | * @see #setTurnScreenOn(boolean) |
| 8358 | * @see android.R.attr#turnScreenOn |
| 8359 | * @see android.R.attr#showWhenLocked |
| 8360 | */ |
| 8361 | public void setShowWhenLocked(boolean showWhenLocked) { |
| 8362 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 8363 | ActivityTaskManager.getService().setShowWhenLocked(mToken, showWhenLocked); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 8364 | } catch (RemoteException e) { |
| 8365 | Log.e(TAG, "Failed to call setShowWhenLocked", e); |
| 8366 | } |
| 8367 | } |
| 8368 | |
| 8369 | /** |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 8370 | * Specifies whether this {@link Activity} should be shown on top of the lock screen whenever |
| 8371 | * the lockscreen is up and this activity has another activity behind it with the showWhenLock |
| 8372 | * attribute set. That is, this activity is only visible on the lock screen if there is another |
| 8373 | * activity with the showWhenLock attribute visible at the same time on the lock screen. A use |
| 8374 | * case for this is permission dialogs, that should only be visible on the lock screen if their |
| 8375 | * requesting activity is also visible. This value can be set as a manifest attribute using |
| 8376 | * android.R.attr#inheritShowWhenLocked. |
| 8377 | * |
| 8378 | * @param inheritShowWhenLocked {@code true} to show the {@link Activity} on top of the lock |
| 8379 | * screen when this activity has another activity behind it with |
| 8380 | * the showWhenLock attribute set; {@code false} otherwise. |
| 8381 | * @see #setShowWhenLocked(boolean) |
Issei Suzuki | 7c09f0b | 2019-02-28 14:45:50 +0100 | [diff] [blame] | 8382 | * @see android.R.attr#inheritShowWhenLocked |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 8383 | */ |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 8384 | public void setInheritShowWhenLocked(boolean inheritShowWhenLocked) { |
| 8385 | try { |
| 8386 | ActivityTaskManager.getService().setInheritShowWhenLocked( |
| 8387 | mToken, inheritShowWhenLocked); |
| 8388 | } catch (RemoteException e) { |
| 8389 | Log.e(TAG, "Failed to call setInheritShowWhenLocked", e); |
| 8390 | } |
| 8391 | } |
| 8392 | |
| 8393 | /** |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 8394 | * Specifies whether the screen should be turned on when the {@link Activity} is resumed. |
| 8395 | * Normally an activity will be transitioned to the stopped state if it is started while the |
| 8396 | * screen if off, but with this flag set the activity will cause the screen to turn on if the |
| 8397 | * activity will be visible and resumed due to the screen coming on. The screen will not be |
| 8398 | * turned on if the activity won't be visible after the screen is turned on. This flag is |
| 8399 | * normally used in conjunction with the {@link android.R.attr#showWhenLocked} flag to make sure |
| 8400 | * the activity is visible after the screen is turned on when the lockscreen is up. In addition, |
| 8401 | * if this flag is set and the activity calls {@link |
| 8402 | * KeyguardManager#requestDismissKeyguard(Activity, KeyguardManager.KeyguardDismissCallback)} |
| 8403 | * the screen will turn on. |
| 8404 | * |
| 8405 | * @param turnScreenOn {@code true} to turn on the screen; {@code false} otherwise. |
| 8406 | * |
| 8407 | * @see #setShowWhenLocked(boolean) |
| 8408 | * @see android.R.attr#turnScreenOn |
| 8409 | * @see android.R.attr#showWhenLocked |
| 8410 | */ |
| 8411 | public void setTurnScreenOn(boolean turnScreenOn) { |
| 8412 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 8413 | ActivityTaskManager.getService().setTurnScreenOn(mToken, turnScreenOn); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 8414 | } catch (RemoteException e) { |
| 8415 | Log.e(TAG, "Failed to call setTurnScreenOn", e); |
| 8416 | } |
| 8417 | } |
| 8418 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 8419 | /** |
| 8420 | * Registers remote animations per transition type for this activity. |
| 8421 | * |
| 8422 | * @param definition The remote animation definition that defines which transition whould run |
| 8423 | * which remote animation. |
| 8424 | * @hide |
| 8425 | */ |
| 8426 | @RequiresPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS) |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 8427 | @UnsupportedAppUsage |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 8428 | public void registerRemoteAnimations(RemoteAnimationDefinition definition) { |
| 8429 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 8430 | ActivityTaskManager.getService().registerRemoteAnimations(mToken, definition); |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 8431 | } catch (RemoteException e) { |
| 8432 | Log.e(TAG, "Failed to call registerRemoteAnimations", e); |
| 8433 | } |
| 8434 | } |
| 8435 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 8436 | /** Log a lifecycle event for current user id and component class. */ |
| 8437 | private void writeEventLog(int event, String reason) { |
| 8438 | EventLog.writeEvent(event, UserHandle.myUserId(), getComponentName().getClassName(), |
| 8439 | reason); |
| 8440 | } |
| 8441 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 8442 | class HostCallbacks extends FragmentHostCallback<Activity> { |
| 8443 | public HostCallbacks() { |
| 8444 | super(Activity.this /*activity*/); |
| 8445 | } |
| 8446 | |
| 8447 | @Override |
| 8448 | public void onDump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 8449 | Activity.this.dump(prefix, fd, writer, args); |
| 8450 | } |
| 8451 | |
| 8452 | @Override |
| 8453 | public boolean onShouldSaveFragmentState(Fragment fragment) { |
| 8454 | return !isFinishing(); |
| 8455 | } |
| 8456 | |
| 8457 | @Override |
| 8458 | public LayoutInflater onGetLayoutInflater() { |
| 8459 | final LayoutInflater result = Activity.this.getLayoutInflater(); |
| 8460 | if (onUseFragmentManagerInflaterFactory()) { |
| 8461 | return result.cloneInContext(Activity.this); |
| 8462 | } |
| 8463 | return result; |
| 8464 | } |
| 8465 | |
| 8466 | @Override |
| 8467 | public boolean onUseFragmentManagerInflaterFactory() { |
| 8468 | // Newer platform versions use the child fragment manager's LayoutInflaterFactory. |
| 8469 | return getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP; |
| 8470 | } |
| 8471 | |
| 8472 | @Override |
| 8473 | public Activity onGetHost() { |
| 8474 | return Activity.this; |
| 8475 | } |
| 8476 | |
| 8477 | @Override |
| 8478 | public void onInvalidateOptionsMenu() { |
| 8479 | Activity.this.invalidateOptionsMenu(); |
| 8480 | } |
| 8481 | |
| 8482 | @Override |
| 8483 | public void onStartActivityFromFragment(Fragment fragment, Intent intent, int requestCode, |
| 8484 | Bundle options) { |
| 8485 | Activity.this.startActivityFromFragment(fragment, intent, requestCode, options); |
| 8486 | } |
| 8487 | |
| 8488 | @Override |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 8489 | public void onStartActivityAsUserFromFragment( |
| 8490 | Fragment fragment, Intent intent, int requestCode, Bundle options, |
| 8491 | UserHandle user) { |
| 8492 | Activity.this.startActivityAsUserFromFragment( |
| 8493 | fragment, intent, requestCode, options, user); |
| 8494 | } |
| 8495 | |
| 8496 | @Override |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 8497 | public void onStartIntentSenderFromFragment(Fragment fragment, IntentSender intent, |
| 8498 | int requestCode, @Nullable Intent fillInIntent, int flagsMask, int flagsValues, |
| 8499 | int extraFlags, Bundle options) throws IntentSender.SendIntentException { |
| 8500 | if (mParent == null) { |
| 8501 | startIntentSenderForResultInner(intent, fragment.mWho, requestCode, fillInIntent, |
| 8502 | flagsMask, flagsValues, options); |
| 8503 | } else if (options != null) { |
| 8504 | mParent.startIntentSenderFromChildFragment(fragment, intent, requestCode, |
| 8505 | fillInIntent, flagsMask, flagsValues, extraFlags, options); |
| 8506 | } |
| 8507 | } |
| 8508 | |
| 8509 | @Override |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 8510 | public void onRequestPermissionsFromFragment(Fragment fragment, String[] permissions, |
| 8511 | int requestCode) { |
| 8512 | String who = REQUEST_PERMISSIONS_WHO_PREFIX + fragment.mWho; |
| 8513 | Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions); |
| 8514 | startActivityForResult(who, intent, requestCode, null); |
| 8515 | } |
| 8516 | |
| 8517 | @Override |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 8518 | public boolean onHasWindowAnimations() { |
| 8519 | return getWindow() != null; |
| 8520 | } |
| 8521 | |
| 8522 | @Override |
| 8523 | public int onGetWindowAnimations() { |
| 8524 | final Window w = getWindow(); |
| 8525 | return (w == null) ? 0 : w.getAttributes().windowAnimations; |
| 8526 | } |
| 8527 | |
Todd Kennedy | 434bd65 | 2015-05-04 12:29:50 -0700 | [diff] [blame] | 8528 | @Override |
| 8529 | public void onAttachFragment(Fragment fragment) { |
| 8530 | Activity.this.onAttachFragment(fragment); |
| 8531 | } |
| 8532 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 8533 | @Nullable |
| 8534 | @Override |
Alan Viverette | 04fd470 | 2017-04-13 16:37:06 -0400 | [diff] [blame] | 8535 | public <T extends View> T onFindViewById(int id) { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 8536 | return Activity.this.findViewById(id); |
| 8537 | } |
| 8538 | |
| 8539 | @Override |
| 8540 | public boolean onHasView() { |
| 8541 | final Window w = getWindow(); |
| 8542 | return (w != null && w.peekDecorView() != null); |
| 8543 | } |
| 8544 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8545 | } |