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 | 5b32ebe | 2018-02-15 12:52:19 -0800 | [diff] [blame] | 20 | |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 21 | import static java.lang.Character.MIN_VALUE; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 22 | |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 23 | import android.annotation.CallSuper; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 24 | import android.annotation.DrawableRes; |
| 25 | import android.annotation.IdRes; |
| 26 | import android.annotation.IntDef; |
| 27 | import android.annotation.LayoutRes; |
Tor Norbye | 83c6896 | 2015-03-10 20:55:31 -0700 | [diff] [blame] | 28 | import android.annotation.MainThread; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 29 | import android.annotation.NonNull; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 30 | import android.annotation.Nullable; |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 31 | import android.annotation.RequiresPermission; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 32 | import android.annotation.StyleRes; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 33 | import android.annotation.SystemApi; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 34 | import android.annotation.UnsupportedAppUsage; |
Amith Yamasani | eeed06c | 2016-05-03 15:07:03 -0700 | [diff] [blame] | 35 | import android.app.VoiceInteractor.Request; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 36 | import android.app.admin.DevicePolicyManager; |
Dianne Hackborn | 69c6adc | 2015-06-02 10:52:59 -0700 | [diff] [blame] | 37 | import android.app.assist.AssistContent; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 38 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.content.ComponentName; |
| 40 | import android.content.ContentResolver; |
| 41 | import android.content.Context; |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 42 | import android.content.CursorLoader; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 43 | import android.content.IIntentSender; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 44 | import android.content.Intent; |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 45 | import android.content.IntentSender; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.content.SharedPreferences; |
| 47 | import android.content.pm.ActivityInfo; |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 48 | import android.content.pm.ApplicationInfo; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 49 | import android.content.pm.PackageManager; |
| 50 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.content.res.Configuration; |
| 52 | import android.content.res.Resources; |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 53 | import android.content.res.TypedArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.database.Cursor; |
| 55 | import android.graphics.Bitmap; |
| 56 | import android.graphics.Canvas; |
Winson | 2d47683 | 2016-02-17 14:53:46 -0800 | [diff] [blame] | 57 | import android.graphics.Color; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 58 | import android.graphics.Rect; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.graphics.drawable.Drawable; |
| 60 | import android.media.AudioManager; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 61 | import android.media.session.MediaController; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.net.Uri; |
Adam Powell | d3c63a6 | 2016-06-09 12:36:16 -0700 | [diff] [blame] | 63 | import android.os.BadParcelableException; |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 64 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.os.Handler; |
| 67 | import android.os.IBinder; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 68 | import android.os.Looper; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 69 | import android.os.Parcelable; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 70 | import android.os.PersistableBundle; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 71 | import android.os.RemoteException; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 72 | import android.os.ServiceManager.ServiceNotFoundException; |
Brad Fitzpatrick | 7580357 | 2011-01-13 14:21:03 -0800 | [diff] [blame] | 73 | import android.os.StrictMode; |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 74 | import android.os.SystemProperties; |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 75 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | import android.text.Selection; |
| 77 | import android.text.SpannableStringBuilder; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 78 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | import android.text.method.TextKeyListener; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 80 | import android.transition.Scene; |
| 81 | import android.transition.TransitionManager; |
| 82 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import android.util.AttributeSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import android.util.EventLog; |
| 85 | import android.util.Log; |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 86 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 87 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | import android.util.SparseArray; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 89 | import android.util.SuperNotCalledException; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 90 | import android.view.ActionMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | import android.view.ContextMenu; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 92 | import android.view.ContextMenu.ContextMenuInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | import android.view.ContextThemeWrapper; |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 94 | import android.view.DragAndDropPermissions; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 95 | import android.view.DragEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.view.KeyEvent; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 97 | import android.view.KeyboardShortcutGroup; |
| 98 | import android.view.KeyboardShortcutInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | import android.view.LayoutInflater; |
| 100 | import android.view.Menu; |
| 101 | import android.view.MenuInflater; |
| 102 | import android.view.MenuItem; |
| 103 | import android.view.MotionEvent; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 104 | import android.view.RemoteAnimationDefinition; |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 105 | import android.view.SearchEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import android.view.View; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 107 | import android.view.View.OnCreateContextMenuListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | import android.view.ViewGroup; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 109 | import android.view.ViewGroup.LayoutParams; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.view.ViewManager; |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 111 | import android.view.ViewRootImpl; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 112 | import android.view.ViewRootImpl.ActivityConfigCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.Window; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 114 | import android.view.Window.WindowControllerCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 116 | import android.view.WindowManagerGlobal; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 117 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 118 | import android.view.autofill.AutofillId; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 119 | import android.view.autofill.AutofillManager; |
Felipe Leme | bb567ae | 2017-10-04 09:56:21 -0700 | [diff] [blame] | 120 | import android.view.autofill.AutofillManager.AutofillClient; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 121 | import android.view.autofill.AutofillPopupWindow; |
| 122 | import android.view.autofill.IAutofillWindowPresenter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | import android.widget.AdapterView; |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 124 | import android.widget.Toast; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 125 | import android.widget.Toolbar; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 126 | |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 127 | import com.android.internal.annotations.GuardedBy; |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 128 | import com.android.internal.annotations.VisibleForTesting; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 129 | import com.android.internal.app.IVoiceInteractor; |
| 130 | import com.android.internal.app.ToolbarActionBar; |
| 131 | import com.android.internal.app.WindowDecorActionBar; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 132 | import com.android.internal.policy.PhoneWindow; |
| 133 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 134 | import java.io.FileDescriptor; |
| 135 | import java.io.PrintWriter; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 136 | import java.lang.annotation.Retention; |
| 137 | import java.lang.annotation.RetentionPolicy; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 138 | import java.util.ArrayList; |
Felipe Leme | 5b32ebe | 2018-02-15 12:52:19 -0800 | [diff] [blame] | 139 | import java.util.Arrays; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 140 | import java.util.HashMap; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 141 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | |
Bryce Lee | e83f34cd | 2017-10-31 19:50:54 -0700 | [diff] [blame] | 143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | /** |
| 145 | * An activity is a single, focused thing that the user can do. Almost all |
| 146 | * activities interact with the user, so the Activity class takes care of |
| 147 | * creating a window for you in which you can place your UI with |
| 148 | * {@link #setContentView}. While activities are often presented to the user |
| 149 | * as full-screen windows, they can also be used in other ways: as floating |
| 150 | * windows (via a theme with {@link android.R.attr#windowIsFloating} set) |
| 151 | * or embedded inside of another activity (using {@link ActivityGroup}). |
| 152 | * |
| 153 | * There are two methods almost all subclasses of Activity will implement: |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 154 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | * <ul> |
| 156 | * <li> {@link #onCreate} is where you initialize your activity. Most |
| 157 | * importantly, here you will usually call {@link #setContentView(int)} |
| 158 | * with a layout resource defining your UI, and using {@link #findViewById} |
| 159 | * to retrieve the widgets in that UI that you need to interact with |
| 160 | * programmatically. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 161 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | * <li> {@link #onPause} is where you deal with the user leaving your |
| 163 | * activity. Most importantly, any changes made by the user should at this |
| 164 | * point be committed (usually to the |
| 165 | * {@link android.content.ContentProvider} holding the data). |
| 166 | * </ul> |
| 167 | * |
| 168 | * <p>To be of use with {@link android.content.Context#startActivity Context.startActivity()}, all |
| 169 | * activity classes must have a corresponding |
| 170 | * {@link android.R.styleable#AndroidManifestActivity <activity>} |
| 171 | * declaration in their package's <code>AndroidManifest.xml</code>.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 172 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | * <p>Topics covered here: |
| 174 | * <ol> |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 175 | * <li><a href="#Fragments">Fragments</a> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | * <li><a href="#ActivityLifecycle">Activity Lifecycle</a> |
| 177 | * <li><a href="#ConfigurationChanges">Configuration Changes</a> |
| 178 | * <li><a href="#StartingActivities">Starting Activities and Getting Results</a> |
| 179 | * <li><a href="#SavingPersistentState">Saving Persistent State</a> |
| 180 | * <li><a href="#Permissions">Permissions</a> |
| 181 | * <li><a href="#ProcessLifecycle">Process Lifecycle</a> |
| 182 | * </ol> |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 183 | * |
| 184 | * <div class="special reference"> |
| 185 | * <h3>Developer Guides</h3> |
| 186 | * <p>The Activity class is an important part of an application's overall lifecycle, |
| 187 | * and the way activities are launched and put together is a fundamental |
| 188 | * part of the platform's application model. For a detailed perspective on the structure of an |
| 189 | * Android application and how activities behave, please read the |
| 190 | * <a href="{@docRoot}guide/topics/fundamentals.html">Application Fundamentals</a> and |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 191 | * <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] | 192 | * developer guides.</p> |
| 193 | * |
| 194 | * <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] | 195 | * <a href="{@docRoot}guide/components/activities.html">Activities</a> |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 196 | * developer guide.</p> |
| 197 | * </div> |
| 198 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 199 | * <a name="Fragments"></a> |
| 200 | * <h3>Fragments</h3> |
| 201 | * |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 202 | * <p>The {@link android.support.v4.app.FragmentActivity} subclass |
| 203 | * 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] | 204 | * modularize their code, build more sophisticated user interfaces for larger |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 205 | * screens, and help scale their application between small and large screens.</p> |
| 206 | * |
| 207 | * <p>For more information about using fragments, read the |
| 208 | * <a href="{@docRoot}guide/components/fragments.html">Fragments</a> developer guide.</p> |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 209 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | * <a name="ActivityLifecycle"></a> |
| 211 | * <h3>Activity Lifecycle</h3> |
| 212 | * |
| 213 | * <p>Activities in the system are managed as an <em>activity stack</em>. |
| 214 | * When a new activity is started, it is placed on the top of the stack |
| 215 | * and becomes the running activity -- the previous activity always remains |
| 216 | * below it in the stack, and will not come to the foreground again until |
| 217 | * the new activity exits.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 218 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | * <p>An activity has essentially four states:</p> |
| 220 | * <ul> |
Trevor Johns | 682c24e | 2016-04-12 10:13:47 -0700 | [diff] [blame] | 221 | * <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] | 222 | * the stack), |
| 223 | * it is <em>active</em> or <em>running</em>. </li> |
| 224 | * <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] | 225 | * 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] | 226 | * is <em>paused</em>. A paused activity is completely alive (it |
| 227 | * maintains all state and member information and remains attached to |
| 228 | * the window manager), but can be killed by the system in extreme |
| 229 | * low memory situations. |
| 230 | * <li>If an activity is completely obscured by another activity, |
| 231 | * it is <em>stopped</em>. It still retains all state and member information, |
| 232 | * however, it is no longer visible to the user so its window is hidden |
| 233 | * and it will often be killed by the system when memory is needed |
| 234 | * elsewhere.</li> |
| 235 | * <li>If an activity is paused or stopped, the system can drop the activity |
| 236 | * from memory by either asking it to finish, or simply killing its |
| 237 | * process. When it is displayed again to the user, it must be |
| 238 | * completely restarted and restored to its previous state.</li> |
| 239 | * </ul> |
| 240 | * |
| 241 | * <p>The following diagram shows the important state paths of an Activity. |
| 242 | * The square rectangles represent callback methods you can implement to |
| 243 | * perform operations when the Activity moves between states. The colored |
| 244 | * ovals are major states the Activity can be in.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 245 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | * <p><img src="../../../images/activity_lifecycle.png" |
| 247 | * alt="State diagram for an Android Activity Lifecycle." border="0" /></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 248 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | * <p>There are three key loops you may be interested in monitoring within your |
| 250 | * activity: |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 251 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | * <ul> |
| 253 | * <li>The <b>entire lifetime</b> of an activity happens between the first call |
| 254 | * to {@link android.app.Activity#onCreate} through to a single final call |
| 255 | * to {@link android.app.Activity#onDestroy}. An activity will do all setup |
| 256 | * of "global" state in onCreate(), and release all remaining resources in |
| 257 | * onDestroy(). For example, if it has a thread running in the background |
| 258 | * to download data from the network, it may create that thread in onCreate() |
| 259 | * and then stop the thread in onDestroy(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 260 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | * <li>The <b>visible lifetime</b> of an activity happens between a call to |
| 262 | * {@link android.app.Activity#onStart} until a corresponding call to |
| 263 | * {@link android.app.Activity#onStop}. During this time the user can see the |
| 264 | * activity on-screen, though it may not be in the foreground and interacting |
| 265 | * with the user. Between these two methods you can maintain resources that |
| 266 | * are needed to show the activity to the user. For example, you can register |
| 267 | * a {@link android.content.BroadcastReceiver} in onStart() to monitor for changes |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 268 | * that impact your UI, and unregister it in onStop() when the user no |
| 269 | * 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] | 270 | * can be called multiple times, as the activity becomes visible and hidden |
| 271 | * to the user. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 272 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | * <li>The <b>foreground lifetime</b> of an activity happens between a call to |
| 274 | * {@link android.app.Activity#onResume} until a corresponding call to |
| 275 | * {@link android.app.Activity#onPause}. During this time the activity is |
| 276 | * in front of all other activities and interacting with the user. An activity |
| 277 | * can frequently go between the resumed and paused states -- for example when |
| 278 | * the device goes to sleep, when an activity result is delivered, when a new |
| 279 | * intent is delivered -- so the code in these methods should be fairly |
| 280 | * lightweight. |
| 281 | * </ul> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 282 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | * <p>The entire lifecycle of an activity is defined by the following |
| 284 | * Activity methods. All of these are hooks that you can override |
| 285 | * to do appropriate work when the activity changes state. All |
| 286 | * activities will implement {@link android.app.Activity#onCreate} |
| 287 | * to do their initial setup; many will also implement |
| 288 | * {@link android.app.Activity#onPause} to commit changes to data and |
| 289 | * otherwise prepare to stop interacting with the user. You should always |
| 290 | * call up to your superclass when implementing these methods.</p> |
| 291 | * |
| 292 | * </p> |
| 293 | * <pre class="prettyprint"> |
| 294 | * public class Activity extends ApplicationContext { |
| 295 | * protected void onCreate(Bundle savedInstanceState); |
| 296 | * |
| 297 | * protected void onStart(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 298 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | * protected void onRestart(); |
| 300 | * |
| 301 | * protected void onResume(); |
| 302 | * |
| 303 | * protected void onPause(); |
| 304 | * |
| 305 | * protected void onStop(); |
| 306 | * |
| 307 | * protected void onDestroy(); |
| 308 | * } |
| 309 | * </pre> |
| 310 | * |
| 311 | * <p>In general the movement through an activity's lifecycle looks like |
| 312 | * this:</p> |
| 313 | * |
| 314 | * <table border="2" width="85%" align="center" frame="hsides" rules="rows"> |
| 315 | * <colgroup align="left" span="3" /> |
| 316 | * <colgroup align="left" /> |
| 317 | * <colgroup align="center" /> |
| 318 | * <colgroup align="center" /> |
| 319 | * |
| 320 | * <thead> |
| 321 | * <tr><th colspan="3">Method</th> <th>Description</th> <th>Killable?</th> <th>Next</th></tr> |
| 322 | * </thead> |
| 323 | * |
| 324 | * <tbody> |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 325 | * <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] | 326 | * <td>Called when the activity is first created. |
| 327 | * This is where you should do all of your normal static set up: |
| 328 | * create views, bind data to lists, etc. This method also |
| 329 | * provides you with a Bundle containing the activity's previously |
| 330 | * frozen state, if there was one. |
| 331 | * <p>Always followed by <code>onStart()</code>.</td> |
| 332 | * <td align="center">No</td> |
| 333 | * <td align="center"><code>onStart()</code></td> |
| 334 | * </tr> |
| 335 | * |
| 336 | * <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] | 337 | * <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] | 338 | * <td>Called after your activity has been stopped, prior to it being |
| 339 | * started again. |
| 340 | * <p>Always followed by <code>onStart()</code></td> |
| 341 | * <td align="center">No</td> |
| 342 | * <td align="center"><code>onStart()</code></td> |
| 343 | * </tr> |
| 344 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 345 | * <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] | 346 | * <td>Called when the activity is becoming visible to the user. |
| 347 | * <p>Followed by <code>onResume()</code> if the activity comes |
| 348 | * to the foreground, or <code>onStop()</code> if it becomes hidden.</td> |
| 349 | * <td align="center">No</td> |
| 350 | * <td align="center"><code>onResume()</code> or <code>onStop()</code></td> |
| 351 | * </tr> |
| 352 | * |
| 353 | * <tr><td rowspan="2" style="border-left: none;"> </td> |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 354 | * <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] | 355 | * <td>Called when the activity will start |
| 356 | * interacting with the user. At this point your activity is at |
| 357 | * the top of the activity stack, with user input going to it. |
| 358 | * <p>Always followed by <code>onPause()</code>.</td> |
| 359 | * <td align="center">No</td> |
| 360 | * <td align="center"><code>onPause()</code></td> |
| 361 | * </tr> |
| 362 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 363 | * <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] | 364 | * <td>Called when the system is about to start resuming a previous |
| 365 | * activity. This is typically used to commit unsaved changes to |
| 366 | * persistent data, stop animations and other things that may be consuming |
| 367 | * CPU, etc. Implementations of this method must be very quick because |
| 368 | * the next activity will not be resumed until this method returns. |
| 369 | * <p>Followed by either <code>onResume()</code> if the activity |
| 370 | * returns back to the front, or <code>onStop()</code> if it becomes |
| 371 | * invisible to the user.</td> |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 372 | * <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] | 373 | * <td align="center"><code>onResume()</code> or<br> |
| 374 | * <code>onStop()</code></td> |
| 375 | * </tr> |
| 376 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 377 | * <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] | 378 | * <td>Called when the activity is no longer visible to the user, because |
| 379 | * another activity has been resumed and is covering this one. This |
| 380 | * may happen either because a new activity is being started, an existing |
| 381 | * one is being brought in front of this one, or this one is being |
| 382 | * destroyed. |
| 383 | * <p>Followed by either <code>onRestart()</code> if |
| 384 | * this activity is coming back to interact with the user, or |
| 385 | * <code>onDestroy()</code> if this activity is going away.</td> |
| 386 | * <td align="center"><font color="#800000"><strong>Yes</strong></font></td> |
| 387 | * <td align="center"><code>onRestart()</code> or<br> |
| 388 | * <code>onDestroy()</code></td> |
| 389 | * </tr> |
| 390 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 391 | * <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] | 392 | * <td>The final call you receive before your |
| 393 | * activity is destroyed. This can happen either because the |
| 394 | * activity is finishing (someone called {@link Activity#finish} on |
| 395 | * it, or because the system is temporarily destroying this |
| 396 | * instance of the activity to save space. You can distinguish |
| 397 | * between these two scenarios with the {@link |
| 398 | * Activity#isFinishing} method.</td> |
| 399 | * <td align="center"><font color="#800000"><strong>Yes</strong></font></td> |
| 400 | * <td align="center"><em>nothing</em></td> |
| 401 | * </tr> |
| 402 | * </tbody> |
| 403 | * </table> |
| 404 | * |
| 405 | * <p>Note the "Killable" column in the above table -- for those methods that |
| 406 | * 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] | 407 | * 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] | 408 | * of its code being executed. Because of this, you should use the |
| 409 | * {@link #onPause} method to write any persistent data (such as user edits) |
| 410 | * to storage. In addition, the method |
| 411 | * {@link #onSaveInstanceState(Bundle)} is called before placing the activity |
| 412 | * in such a background state, allowing you to save away any dynamic instance |
| 413 | * state in your activity into the given Bundle, to be later received in |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 414 | * {@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] | 415 | * See the <a href="#ProcessLifecycle">Process Lifecycle</a> |
| 416 | * section for more information on how the lifecycle of a process is tied |
| 417 | * to the activities it is hosting. Note that it is important to save |
| 418 | * persistent data in {@link #onPause} instead of {@link #onSaveInstanceState} |
Daisuke Miyakawa | 5c40f3f | 2011-02-15 13:24:36 -0800 | [diff] [blame] | 419 | * 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] | 420 | * be called in every situation as described in its documentation.</p> |
| 421 | * |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 422 | * <p class="note">Be aware that these semantics will change slightly between |
| 423 | * applications targeting platforms starting with {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 424 | * vs. those targeting prior platforms. Starting with Honeycomb, an application |
| 425 | * is not in the killable state until its {@link #onStop} has returned. This |
| 426 | * impacts when {@link #onSaveInstanceState(Bundle)} may be called (it may be |
Joshua Baxter | 9a841a6 | 2018-03-27 14:42:03 -0700 | [diff] [blame] | 427 | * safely called after {@link #onPause()}) and allows an application to safely |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 428 | * wait until {@link #onStop()} to save persistent state.</p> |
| 429 | * |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 430 | * <p class="note">For applications targeting platforms starting with |
| 431 | * {@link android.os.Build.VERSION_CODES#P} {@link #onSaveInstanceState(Bundle)} |
| 432 | * will always be called after {@link #onStop}, so an application may safely |
| 433 | * perform fragment transactions in {@link #onStop} and will be able to save |
| 434 | * persistent state later.</p> |
| 435 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | * <p>For those methods that are not marked as being killable, the activity's |
| 437 | * process will not be killed by the system starting from the time the method |
| 438 | * is called and continuing after it returns. Thus an activity is in the killable |
| 439 | * state, for example, between after <code>onPause()</code> to the start of |
| 440 | * <code>onResume()</code>.</p> |
| 441 | * |
| 442 | * <a name="ConfigurationChanges"></a> |
| 443 | * <h3>Configuration Changes</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 444 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | * <p>If the configuration of the device (as defined by the |
| 446 | * {@link Configuration Resources.Configuration} class) changes, |
| 447 | * then anything displaying a user interface will need to update to match that |
| 448 | * configuration. Because Activity is the primary mechanism for interacting |
| 449 | * with the user, it includes special support for handling configuration |
| 450 | * changes.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 451 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | * <p>Unless you specify otherwise, a configuration change (such as a change |
| 453 | * in screen orientation, language, input devices, etc) will cause your |
| 454 | * current activity to be <em>destroyed</em>, going through the normal activity |
| 455 | * lifecycle process of {@link #onPause}, |
| 456 | * {@link #onStop}, and {@link #onDestroy} as appropriate. If the activity |
| 457 | * had been in the foreground or visible to the user, once {@link #onDestroy} is |
| 458 | * called in that instance then a new instance of the activity will be |
| 459 | * created, with whatever savedInstanceState the previous instance had generated |
| 460 | * from {@link #onSaveInstanceState}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 461 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | * <p>This is done because any application resource, |
| 463 | * including layout files, can change based on any configuration value. Thus |
| 464 | * the only safe way to handle a configuration change is to re-retrieve all |
| 465 | * resources, including layouts, drawables, and strings. Because activities |
| 466 | * must already know how to save their state and re-create themselves from |
| 467 | * that state, this is a convenient way to have an activity restart itself |
| 468 | * with a new configuration.</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>In some special cases, you may want to bypass restarting of your |
| 471 | * activity based on one or more types of configuration changes. This is |
| 472 | * done with the {@link android.R.attr#configChanges android:configChanges} |
| 473 | * attribute in its manifest. For any types of configuration changes you say |
| 474 | * that you handle there, you will receive a call to your current activity's |
| 475 | * {@link #onConfigurationChanged} method instead of being restarted. If |
| 476 | * a configuration change involves any that you do not handle, however, the |
| 477 | * activity will still be restarted and {@link #onConfigurationChanged} |
| 478 | * will not be called.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 479 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | * <a name="StartingActivities"></a> |
| 481 | * <h3>Starting Activities and Getting Results</h3> |
| 482 | * |
| 483 | * <p>The {@link android.app.Activity#startActivity} |
| 484 | * method is used to start a |
| 485 | * new activity, which will be placed at the top of the activity stack. It |
| 486 | * takes a single argument, an {@link android.content.Intent Intent}, |
| 487 | * which describes the activity |
| 488 | * to be executed.</p> |
| 489 | * |
| 490 | * <p>Sometimes you want to get a result back from an activity when it |
| 491 | * ends. For example, you may start an activity that lets the user pick |
| 492 | * a person in a list of contacts; when it ends, it returns the person |
| 493 | * that was selected. To do this, you call the |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 494 | * {@link android.app.Activity#startActivityForResult(Intent, int)} |
| 495 | * 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] | 496 | * will come back through your {@link android.app.Activity#onActivityResult} |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 497 | * method.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | * |
| 499 | * <p>When an activity exits, it can call |
| 500 | * {@link android.app.Activity#setResult(int)} |
| 501 | * to return data back to its parent. It must always supply a result code, |
| 502 | * which can be the standard results RESULT_CANCELED, RESULT_OK, or any |
| 503 | * custom values starting at RESULT_FIRST_USER. In addition, it can optionally |
| 504 | * return back an Intent containing any additional data it wants. All of this |
| 505 | * information appears back on the |
| 506 | * parent's <code>Activity.onActivityResult()</code>, along with the integer |
| 507 | * identifier it originally supplied.</p> |
| 508 | * |
| 509 | * <p>If a child activity fails for any reason (such as crashing), the parent |
| 510 | * activity will receive a result with the code RESULT_CANCELED.</p> |
| 511 | * |
| 512 | * <pre class="prettyprint"> |
| 513 | * public class MyActivity extends Activity { |
| 514 | * ... |
| 515 | * |
| 516 | * static final int PICK_CONTACT_REQUEST = 0; |
| 517 | * |
Michael Wright | 5438e4e | 2014-07-25 14:05:42 -0700 | [diff] [blame] | 518 | * public boolean onKeyDown(int keyCode, KeyEvent event) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | * if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { |
| 520 | * // When the user center presses, let them pick a contact. |
| 521 | * startActivityForResult( |
| 522 | * new Intent(Intent.ACTION_PICK, |
| 523 | * new Uri("content://contacts")), |
| 524 | * PICK_CONTACT_REQUEST); |
| 525 | * return true; |
| 526 | * } |
| 527 | * return false; |
| 528 | * } |
| 529 | * |
| 530 | * protected void onActivityResult(int requestCode, int resultCode, |
| 531 | * Intent data) { |
| 532 | * if (requestCode == PICK_CONTACT_REQUEST) { |
| 533 | * if (resultCode == RESULT_OK) { |
| 534 | * // A contact was picked. Here we will just display it |
| 535 | * // to the user. |
| 536 | * startActivity(new Intent(Intent.ACTION_VIEW, data)); |
| 537 | * } |
| 538 | * } |
| 539 | * } |
| 540 | * } |
| 541 | * </pre> |
| 542 | * |
| 543 | * <a name="SavingPersistentState"></a> |
| 544 | * <h3>Saving Persistent State</h3> |
| 545 | * |
| 546 | * <p>There are generally two kinds of persistent state than an activity |
| 547 | * will deal with: shared document-like data (typically stored in a SQLite |
| 548 | * database using a {@linkplain android.content.ContentProvider content provider}) |
| 549 | * and internal state such as user preferences.</p> |
| 550 | * |
| 551 | * <p>For content provider data, we suggest that activities use a |
| 552 | * "edit in place" user model. That is, any edits a user makes are effectively |
| 553 | * made immediately without requiring an additional confirmation step. |
| 554 | * Supporting this model is generally a simple matter of following two rules:</p> |
| 555 | * |
| 556 | * <ul> |
| 557 | * <li> <p>When creating a new document, the backing database entry or file for |
| 558 | * it is created immediately. For example, if the user chooses to write |
Andrew Solovay | ab8ea9f | 2017-10-06 19:02:28 -0700 | [diff] [blame] | 559 | * 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] | 560 | * 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] | 561 | * 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] | 562 | * <li> <p>When an activity's <code>onPause()</code> method is called, it should |
| 563 | * commit to the backing content provider or file any changes the user |
| 564 | * has made. This ensures that those changes will be seen by any other |
| 565 | * activity that is about to run. You will probably want to commit |
| 566 | * your data even more aggressively at key times during your |
| 567 | * activity's lifecycle: for example before starting a new |
| 568 | * activity, before finishing your own activity, when the user |
| 569 | * switches between input fields, etc.</p> |
| 570 | * </ul> |
| 571 | * |
| 572 | * <p>This model is designed to prevent data loss when a user is navigating |
| 573 | * between activities, and allows the system to safely kill an activity (because |
| 574 | * system resources are needed somewhere else) at any time after it has been |
| 575 | * paused. Note this implies |
| 576 | * that the user pressing BACK from your activity does <em>not</em> |
| 577 | * mean "cancel" -- it means to leave the activity with its current contents |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 578 | * 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] | 579 | * some other mechanism, such as an explicit "revert" or "undo" option.</p> |
| 580 | * |
| 581 | * <p>See the {@linkplain android.content.ContentProvider content package} for |
| 582 | * more information about content providers. These are a key aspect of how |
| 583 | * different activities invoke and propagate data between themselves.</p> |
| 584 | * |
| 585 | * <p>The Activity class also provides an API for managing internal persistent state |
| 586 | * associated with an activity. This can be used, for example, to remember |
| 587 | * the user's preferred initial display in a calendar (day view or week view) |
| 588 | * or the user's default home page in a web browser.</p> |
| 589 | * |
| 590 | * <p>Activity persistent state is managed |
| 591 | * with the method {@link #getPreferences}, |
| 592 | * allowing you to retrieve and |
| 593 | * modify a set of name/value pairs associated with the activity. To use |
| 594 | * preferences that are shared across multiple application components |
| 595 | * (activities, receivers, services, providers), you can use the underlying |
| 596 | * {@link Context#getSharedPreferences Context.getSharedPreferences()} method |
| 597 | * to retrieve a preferences |
| 598 | * object stored under a specific name. |
| 599 | * (Note that it is not possible to share settings data across application |
| 600 | * packages -- for that you will need a content provider.)</p> |
| 601 | * |
| 602 | * <p>Here is an excerpt from a calendar activity that stores the user's |
| 603 | * preferred view mode in its persistent settings:</p> |
| 604 | * |
| 605 | * <pre class="prettyprint"> |
| 606 | * public class CalendarActivity extends Activity { |
| 607 | * ... |
| 608 | * |
| 609 | * static final int DAY_VIEW_MODE = 0; |
| 610 | * static final int WEEK_VIEW_MODE = 1; |
| 611 | * |
| 612 | * private SharedPreferences mPrefs; |
| 613 | * private int mCurViewMode; |
| 614 | * |
| 615 | * protected void onCreate(Bundle savedInstanceState) { |
| 616 | * super.onCreate(savedInstanceState); |
| 617 | * |
| 618 | * SharedPreferences mPrefs = getSharedPreferences(); |
Quddus Chong | 3fa98cb | 2012-04-13 11:17:24 -0700 | [diff] [blame] | 619 | * mCurViewMode = mPrefs.getInt("view_mode", DAY_VIEW_MODE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | * } |
| 621 | * |
| 622 | * protected void onPause() { |
| 623 | * super.onPause(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 624 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | * SharedPreferences.Editor ed = mPrefs.edit(); |
| 626 | * ed.putInt("view_mode", mCurViewMode); |
| 627 | * ed.commit(); |
| 628 | * } |
| 629 | * } |
| 630 | * </pre> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 631 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | * <a name="Permissions"></a> |
| 633 | * <h3>Permissions</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 634 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | * <p>The ability to start a particular Activity can be enforced when it is |
| 636 | * declared in its |
| 637 | * manifest's {@link android.R.styleable#AndroidManifestActivity <activity>} |
| 638 | * tag. By doing so, other applications will need to declare a corresponding |
| 639 | * {@link android.R.styleable#AndroidManifestUsesPermission <uses-permission>} |
| 640 | * element in their own manifest to be able to start that activity. |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 641 | * |
| 642 | * <p>When starting an Activity you can set {@link Intent#FLAG_GRANT_READ_URI_PERMISSION |
| 643 | * Intent.FLAG_GRANT_READ_URI_PERMISSION} and/or {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 644 | * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} on the Intent. This will grant the |
| 645 | * Activity access to the specific URIs in the Intent. Access will remain |
| 646 | * until the Activity has finished (it will remain across the hosting |
| 647 | * process being killed and other temporary destruction). As of |
| 648 | * {@link android.os.Build.VERSION_CODES#GINGERBREAD}, if the Activity |
| 649 | * was already created and a new Intent is being delivered to |
| 650 | * {@link #onNewIntent(Intent)}, any newly granted URI permissions will be added |
| 651 | * to the existing ones it holds. |
| 652 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 653 | * <p>See the <a href="{@docRoot}guide/topics/security/security.html">Security and Permissions</a> |
| 654 | * document for more information on permissions and security in general. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 655 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 656 | * <a name="ProcessLifecycle"></a> |
| 657 | * <h3>Process Lifecycle</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 658 | * |
kopriva | 4dddc63 | 2018-03-19 14:13:08 -0700 | [diff] [blame] | 659 | * <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] | 660 | * long as possible, but eventually will need to remove old processes when |
kopriva | 4dddc63 | 2018-03-19 14:13:08 -0700 | [diff] [blame] | 661 | * 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] | 662 | * Lifecycle</a>, the decision about which process to remove is intimately |
kopriva | 4dddc63 | 2018-03-19 14:13:08 -0700 | [diff] [blame] | 663 | * 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] | 664 | * 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] | 665 | * 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] | 666 | * processes (the last ones) before it resorts to killing more important |
| 667 | * processes (the first ones). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 668 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | * <ol> |
| 670 | * <li> <p>The <b>foreground activity</b> (the activity at the top of the screen |
| 671 | * that the user is currently interacting with) is considered the most important. |
| 672 | * Its process will only be killed as a last resort, if it uses more memory |
| 673 | * than is available on the device. Generally at this point the device has |
| 674 | * reached a memory paging state, so this is required in order to keep the user |
| 675 | * interface responsive. |
| 676 | * <li> <p>A <b>visible activity</b> (an activity that is visible to the user |
| 677 | * but not in the foreground, such as one sitting behind a foreground dialog) |
| 678 | * is considered extremely important and will not be killed unless that is |
| 679 | * required to keep the foreground activity running. |
| 680 | * <li> <p>A <b>background activity</b> (an activity that is not visible to |
| 681 | * the user and has been paused) is no longer critical, so the system may |
| 682 | * safely kill its process to reclaim memory for other foreground or |
| 683 | * visible processes. If its process needs to be killed, when the user navigates |
| 684 | * back to the activity (making it visible on the screen again), its |
| 685 | * {@link #onCreate} method will be called with the savedInstanceState it had previously |
| 686 | * supplied in {@link #onSaveInstanceState} so that it can restart itself in the same |
| 687 | * state as the user last left it. |
| 688 | * <li> <p>An <b>empty process</b> is one hosting no activities or other |
| 689 | * application components (such as {@link Service} or |
| 690 | * {@link android.content.BroadcastReceiver} classes). These are killed very |
| 691 | * quickly by the system as memory becomes low. For this reason, any |
| 692 | * background operation you do outside of an activity must be executed in the |
| 693 | * context of an activity BroadcastReceiver or Service to ensure that the system |
| 694 | * knows it needs to keep your process around. |
| 695 | * </ol> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 696 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 | * <p>Sometimes an Activity may need to do a long-running operation that exists |
| 698 | * independently of the activity lifecycle itself. An example may be a camera |
| 699 | * application that allows you to upload a picture to a web site. The upload |
| 700 | * 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] | 701 | * 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] | 702 | * should start a {@link Service} in which the upload takes place. This allows |
| 703 | * the system to properly prioritize your process (considering it to be more |
| 704 | * important than other non-visible applications) for the duration of the |
| 705 | * upload, independent of whether the original activity is paused, stopped, |
| 706 | * or finished. |
| 707 | */ |
| 708 | public class Activity extends ContextThemeWrapper |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 709 | implements LayoutInflater.Factory2, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | Window.Callback, KeyEvent.Callback, |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 711 | OnCreateContextMenuListener, ComponentCallbacks2, |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 712 | Window.OnWindowDismissedCallback, WindowControllerCallback, |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 713 | AutofillManager.AutofillClient { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 714 | private static final String TAG = "Activity"; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 715 | private static final boolean DEBUG_LIFECYCLE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 716 | |
| 717 | /** Standard activity result: operation canceled. */ |
| 718 | public static final int RESULT_CANCELED = 0; |
| 719 | /** Standard activity result: operation succeeded. */ |
| 720 | public static final int RESULT_OK = -1; |
| 721 | /** Start of user-defined activity results. */ |
| 722 | public static final int RESULT_FIRST_USER = 1; |
| 723 | |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 724 | /** @hide Task isn't finished when activity is finished */ |
| 725 | public static final int DONT_FINISH_TASK_WITH_ACTIVITY = 0; |
Filip Gruszczynski | c29ecc8 | 2015-10-08 11:08:44 -0700 | [diff] [blame] | 726 | /** |
| 727 | * @hide Task is finished if the finishing activity is the root of the task. To preserve the |
| 728 | * past behavior the task is also removed from recents. |
| 729 | */ |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 730 | public static final int FINISH_TASK_WITH_ROOT_ACTIVITY = 1; |
Filip Gruszczynski | c29ecc8 | 2015-10-08 11:08:44 -0700 | [diff] [blame] | 731 | /** |
| 732 | * @hide Task is finished along with the finishing activity, but it is not removed from |
| 733 | * recents. |
| 734 | */ |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 735 | public static final int FINISH_TASK_WITH_ACTIVITY = 2; |
| 736 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 737 | @UnsupportedAppUsage |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 738 | static final String FRAGMENTS_TAG = "android:fragments"; |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 739 | private static final String LAST_AUTOFILL_ID = "android:lastAutofillId"; |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 740 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 741 | private static final String AUTOFILL_RESET_NEEDED = "@android:autofillResetNeeded"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 742 | private static final String WINDOW_HIERARCHY_TAG = "android:viewHierarchyState"; |
| 743 | private static final String SAVED_DIALOG_IDS_KEY = "android:savedDialogIds"; |
| 744 | private static final String SAVED_DIALOGS_TAG = "android:savedDialogs"; |
| 745 | private static final String SAVED_DIALOG_KEY_PREFIX = "android:dialog_"; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 746 | private static final String SAVED_DIALOG_ARGS_KEY_PREFIX = "android:dialog_args_"; |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 747 | private static final String HAS_CURENT_PERMISSIONS_REQUEST_KEY = |
| 748 | "android:hasCurrentPermissionsRequest"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 750 | private static final String REQUEST_PERMISSIONS_WHO_PREFIX = "@android:requestPermissions:"; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 751 | private static final String AUTO_FILL_AUTH_WHO_PREFIX = "@android:autoFillAuth:"; |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 752 | |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 753 | private static final String KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME = "com.android.systemui"; |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 754 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 755 | private static final int LOG_AM_ON_CREATE_CALLED = 30057; |
| 756 | private static final int LOG_AM_ON_START_CALLED = 30059; |
| 757 | private static final int LOG_AM_ON_RESUME_CALLED = 30022; |
| 758 | private static final int LOG_AM_ON_PAUSE_CALLED = 30021; |
| 759 | private static final int LOG_AM_ON_STOP_CALLED = 30049; |
| 760 | private static final int LOG_AM_ON_RESTART_CALLED = 30058; |
| 761 | private static final int LOG_AM_ON_DESTROY_CALLED = 30060; |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 762 | private static final int LOG_AM_ON_ACTIVITY_RESULT_CALLED = 30062; |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 763 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 764 | private static class ManagedDialog { |
| 765 | Dialog mDialog; |
| 766 | Bundle mArgs; |
| 767 | } |
| 768 | private SparseArray<ManagedDialog> mManagedDialogs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | |
| 770 | // set by the thread after the constructor and before onCreate(Bundle savedInstanceState) is called. |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 771 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | private Instrumentation mInstrumentation; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 773 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | private IBinder mToken; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 775 | @UnsupportedAppUsage |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 776 | private int mIdent; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 777 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | /*package*/ String mEmbeddedID; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 779 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 780 | private Application mApplication; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 781 | @UnsupportedAppUsage |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 782 | /*package*/ Intent mIntent; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 783 | @UnsupportedAppUsage |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 784 | /*package*/ String mReferrer; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 785 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | private ComponentName mComponent; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 787 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | /*package*/ ActivityInfo mActivityInfo; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 789 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 790 | /*package*/ ActivityThread mMainThread; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 791 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 792 | Activity mParent; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 793 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | boolean mCalled; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 795 | @UnsupportedAppUsage |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 796 | /*package*/ boolean mResumed; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 797 | @UnsupportedAppUsage |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 798 | /*package*/ boolean mStopped; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 799 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | boolean mFinished; |
| 801 | boolean mStartedActivity; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 802 | @UnsupportedAppUsage |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 803 | private boolean mDestroyed; |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 804 | private boolean mDoReportFullyDrawn = true; |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 805 | private boolean mRestoredFromBundle; |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 806 | |
| 807 | /** {@code true} if the activity lifecycle is in a state which supports picture-in-picture. |
| 808 | * This only affects the client-side exception, the actual state check still happens in AMS. */ |
| 809 | private boolean mCanEnterPictureInPicture = false; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 810 | /** true if the activity is going through a transient pause */ |
| 811 | /*package*/ boolean mTemporaryPause = false; |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 812 | /** true if the activity is being destroyed in order to recreate it with a new configuration */ |
| 813 | /*package*/ boolean mChangingConfigurations = false; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 814 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 815 | /*package*/ int mConfigChangeFlags; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 816 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 | /*package*/ Configuration mCurrentConfig; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 818 | private SearchManager mSearchManager; |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 819 | private MenuInflater mMenuInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 821 | /** The autofill manager. Always access via {@link #getAutofillManager()}. */ |
| 822 | @Nullable private AutofillManager mAutofillManager; |
| 823 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 824 | static final class NonConfigurationInstances { |
| 825 | Object activity; |
| 826 | HashMap<String, Object> children; |
Adam Powell | 44ba79e | 2016-02-04 16:20:37 -0800 | [diff] [blame] | 827 | FragmentManagerNonConfig fragments; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 828 | ArrayMap<String, LoaderManager> loaders; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 829 | VoiceInteractor voiceInteractor; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 830 | } |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 831 | @UnsupportedAppUsage |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 832 | /* package */ NonConfigurationInstances mLastNonConfigurationInstances; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 833 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 834 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 835 | private Window mWindow; |
| 836 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 837 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | private WindowManager mWindowManager; |
| 839 | /*package*/ View mDecor = null; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 840 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | /*package*/ boolean mWindowAdded = false; |
| 842 | /*package*/ boolean mVisibleFromServer = false; |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 843 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | /*package*/ boolean mVisibleFromClient = true; |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 845 | /*package*/ ActionBar mActionBar = null; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 846 | private boolean mEnableDefaultActionBarUp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 847 | |
Mathew Inwood | 45d2c25 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 848 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 849 | private VoiceInteractor mVoiceInteractor; |
| 850 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 851 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | private CharSequence mTitle; |
| 853 | private int mTitleColor = 0; |
| 854 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 855 | // we must have a handler before the FragmentController is constructed |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 856 | @UnsupportedAppUsage |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 857 | final Handler mHandler = new Handler(); |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 858 | @UnsupportedAppUsage |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 859 | final FragmentController mFragments = FragmentController.createController(new HostCallbacks()); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 860 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | private static final class ManagedCursor { |
| 862 | ManagedCursor(Cursor cursor) { |
| 863 | mCursor = cursor; |
| 864 | mReleased = false; |
| 865 | mUpdated = false; |
| 866 | } |
| 867 | |
| 868 | private final Cursor mCursor; |
| 869 | private boolean mReleased; |
| 870 | private boolean mUpdated; |
| 871 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 872 | |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 873 | @GuardedBy("mManagedCursors") |
| 874 | private final ArrayList<ManagedCursor> mManagedCursors = new ArrayList<>(); |
| 875 | |
| 876 | @GuardedBy("this") |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 877 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 878 | int mResultCode = RESULT_CANCELED; |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 879 | @GuardedBy("this") |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 880 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 881 | Intent mResultData = null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 882 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 883 | private TranslucentConversionListener mTranslucentCallback; |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 884 | private boolean mChangeCanvasToTranslucent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 885 | |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 886 | private SearchEvent mSearchEvent; |
| 887 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 888 | private boolean mTitleReady = false; |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 889 | private int mActionModeTypeStarting = ActionMode.TYPE_PRIMARY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | |
| 891 | private int mDefaultKeyMode = DEFAULT_KEYS_DISABLE; |
| 892 | private SpannableStringBuilder mDefaultKeySsb = null; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 893 | |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 894 | private ActivityManager.TaskDescription mTaskDescription = |
| 895 | new ActivityManager.TaskDescription(); |
| 896 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 897 | protected static final int[] FOCUSED_STATE_SET = {com.android.internal.R.attr.state_focused}; |
| 898 | |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 899 | @SuppressWarnings("unused") |
Jeff Brown | 7e44283 | 2011-06-10 18:00:16 -0700 | [diff] [blame] | 900 | private final Object mInstanceTracker = StrictMode.trackActivity(this); |
| 901 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | private Thread mUiThread; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 903 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 904 | @UnsupportedAppUsage |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 905 | ActivityTransitionState mActivityTransitionState = new ActivityTransitionState(); |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 906 | SharedElementCallback mEnterTransitionListener = SharedElementCallback.NULL_CALLBACK; |
| 907 | SharedElementCallback mExitTransitionListener = SharedElementCallback.NULL_CALLBACK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 908 | |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 909 | private boolean mHasCurrentPermissionsRequest; |
| 910 | |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 911 | private boolean mAutoFillResetNeeded; |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 912 | private boolean mAutoFillIgnoreFirstResumePause; |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 913 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 914 | /** The last autofill id that was returned from {@link #getNextAutofillId()} */ |
| 915 | private int mLastAutofillId = View.LAST_APP_AUTOFILL_ID; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 916 | |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 917 | private AutofillPopupWindow mAutofillPopupWindow; |
| 918 | |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 919 | private static native String getDlWarning(); |
| 920 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | /** Return the intent that started this activity. */ |
| 922 | public Intent getIntent() { |
| 923 | return mIntent; |
| 924 | } |
| 925 | |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 926 | /** |
| 927 | * Change the intent returned by {@link #getIntent}. This holds a |
| 928 | * reference to the given intent; it does not copy it. Often used in |
| 929 | * conjunction with {@link #onNewIntent}. |
| 930 | * |
| 931 | * @param newIntent The new Intent object to return from getIntent |
| 932 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | * @see #getIntent |
| 934 | * @see #onNewIntent |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 935 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | public void setIntent(Intent newIntent) { |
| 937 | mIntent = newIntent; |
| 938 | } |
| 939 | |
| 940 | /** Return the application that owns this activity. */ |
| 941 | public final Application getApplication() { |
| 942 | return mApplication; |
| 943 | } |
| 944 | |
| 945 | /** Is this activity embedded inside of another activity? */ |
| 946 | public final boolean isChild() { |
| 947 | return mParent != null; |
| 948 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | /** Return the parent activity if this view is an embedded child. */ |
| 951 | public final Activity getParent() { |
| 952 | return mParent; |
| 953 | } |
| 954 | |
| 955 | /** Retrieve the window manager for showing custom windows. */ |
| 956 | public WindowManager getWindowManager() { |
| 957 | return mWindowManager; |
| 958 | } |
| 959 | |
| 960 | /** |
| 961 | * Retrieve the current {@link android.view.Window} for the activity. |
| 962 | * This can be used to directly access parts of the Window API that |
| 963 | * are not available through Activity/Screen. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 964 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | * @return Window The current window, or null if the activity is not |
| 966 | * visual. |
| 967 | */ |
| 968 | public Window getWindow() { |
| 969 | return mWindow; |
| 970 | } |
| 971 | |
| 972 | /** |
Mark Doliner | 9525f2a | 2014-01-02 11:17:47 -0800 | [diff] [blame] | 973 | * Return the LoaderManager for this activity, creating it if needed. |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 974 | * |
| 975 | * @deprecated Use {@link android.support.v4.app.FragmentActivity#getSupportLoaderManager()} |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 976 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 977 | @Deprecated |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 978 | public LoaderManager getLoaderManager() { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 979 | return mFragments.getLoaderManager(); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 980 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 981 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 982 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 983 | * Calls {@link android.view.Window#getCurrentFocus} on the |
| 984 | * Window of this Activity to return the currently focused view. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 985 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | * @return View The current View with focus or null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 987 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 988 | * @see #getWindow |
| 989 | * @see android.view.Window#getCurrentFocus |
| 990 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 991 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | public View getCurrentFocus() { |
| 993 | return mWindow != null ? mWindow.getCurrentFocus() : null; |
| 994 | } |
| 995 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | /** |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 997 | * (Create and) return the autofill manager |
| 998 | * |
| 999 | * @return The autofill manager |
| 1000 | */ |
| 1001 | @NonNull private AutofillManager getAutofillManager() { |
| 1002 | if (mAutofillManager == null) { |
| 1003 | mAutofillManager = getSystemService(AutofillManager.class); |
| 1004 | } |
| 1005 | |
| 1006 | return mAutofillManager; |
| 1007 | } |
| 1008 | |
Felipe Leme | bb567ae | 2017-10-04 09:56:21 -0700 | [diff] [blame] | 1009 | @Override |
| 1010 | protected void attachBaseContext(Context newBase) { |
| 1011 | super.attachBaseContext(newBase); |
Felipe Leme | d247de8 | 2018-05-14 17:51:58 -0700 | [diff] [blame] | 1012 | if (newBase != null) { |
| 1013 | newBase.setAutofillClient(this); |
| 1014 | } |
Felipe Leme | bb567ae | 2017-10-04 09:56:21 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | /** @hide */ |
| 1018 | @Override |
| 1019 | public final AutofillClient getAutofillClient() { |
| 1020 | return this; |
| 1021 | } |
| 1022 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1023 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1024 | * Called when the activity is starting. This is where most initialization |
| 1025 | * should go: calling {@link #setContentView(int)} to inflate the |
| 1026 | * activity's UI, using {@link #findViewById} to programmatically interact |
| 1027 | * with widgets in the UI, calling |
| 1028 | * {@link #managedQuery(android.net.Uri , String[], String, String[], String)} to retrieve |
| 1029 | * cursors for data being displayed, etc. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1030 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | * <p>You can call {@link #finish} from within this function, in |
Bryce Lee | 476edc8 | 2018-03-12 10:06:23 -0700 | [diff] [blame] | 1032 | * which case onDestroy() will be immediately called after {@link #onCreate} without any of the |
| 1033 | * rest of the activity lifecycle ({@link #onStart}, {@link #onResume}, {@link #onPause}, etc) |
| 1034 | * executing. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1035 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1036 | * <p><em>Derived classes must call through to the super class's |
| 1037 | * implementation of this method. If they do not, an exception will be |
| 1038 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1039 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | * @param savedInstanceState If the activity is being re-initialized after |
| 1041 | * previously being shut down then this Bundle contains the data it most |
| 1042 | * 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] | 1043 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | * @see #onStart |
| 1045 | * @see #onSaveInstanceState |
| 1046 | * @see #onRestoreInstanceState |
| 1047 | * @see #onPostCreate |
| 1048 | */ |
Tor Norbye | 83c6896 | 2015-03-10 20:55:31 -0700 | [diff] [blame] | 1049 | @MainThread |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1050 | @CallSuper |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1051 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1052 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState); |
Bryce Lee | 3979159 | 2017-04-26 09:29:12 -0700 | [diff] [blame] | 1053 | |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 1054 | if (mLastNonConfigurationInstances != null) { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 1055 | mFragments.restoreLoaderNonConfig(mLastNonConfigurationInstances.loaders); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 1056 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 1057 | if (mActivityInfo.parentActivityName != null) { |
| 1058 | if (mActionBar == null) { |
| 1059 | mEnableDefaultActionBarUp = true; |
| 1060 | } else { |
| 1061 | mActionBar.setDefaultDisplayHomeAsUpEnabled(true); |
| 1062 | } |
| 1063 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1064 | if (savedInstanceState != null) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1065 | mAutoFillResetNeeded = savedInstanceState.getBoolean(AUTOFILL_RESET_NEEDED, false); |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 1066 | mLastAutofillId = savedInstanceState.getInt(LAST_AUTOFILL_ID, |
| 1067 | View.LAST_APP_AUTOFILL_ID); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1068 | |
| 1069 | if (mAutoFillResetNeeded) { |
| 1070 | getAutofillManager().onCreate(savedInstanceState); |
| 1071 | } |
| 1072 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1073 | Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG); |
| 1074 | mFragments.restoreAllState(p, mLastNonConfigurationInstances != null |
| 1075 | ? mLastNonConfigurationInstances.fragments : null); |
| 1076 | } |
| 1077 | mFragments.dispatchCreate(); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1078 | getApplication().dispatchActivityCreated(this, savedInstanceState); |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 1079 | if (mVoiceInteractor != null) { |
| 1080 | mVoiceInteractor.attachActivity(this); |
| 1081 | } |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 1082 | mRestoredFromBundle = savedInstanceState != null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | mCalled = true; |
| 1084 | } |
| 1085 | |
| 1086 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1087 | * 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] | 1088 | * the attribute {@link android.R.attr#persistableMode} set to |
| 1089 | * <code>persistAcrossReboots</code>. |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1090 | * |
| 1091 | * @param savedInstanceState if the activity is being re-initialized after |
| 1092 | * previously being shut down then this Bundle contains the data it most |
| 1093 | * recently supplied in {@link #onSaveInstanceState}. |
| 1094 | * <b><i>Note: Otherwise it is null.</i></b> |
| 1095 | * @param persistentState if the activity is being re-initialized after |
| 1096 | * previously being shut down or powered off then this Bundle contains the data it most |
| 1097 | * recently supplied to outPersistentState in {@link #onSaveInstanceState}. |
| 1098 | * <b><i>Note: Otherwise it is null.</i></b> |
| 1099 | * |
| 1100 | * @see #onCreate(android.os.Bundle) |
| 1101 | * @see #onStart |
| 1102 | * @see #onSaveInstanceState |
| 1103 | * @see #onRestoreInstanceState |
| 1104 | * @see #onPostCreate |
| 1105 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1106 | public void onCreate(@Nullable Bundle savedInstanceState, |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1107 | @Nullable PersistableBundle persistentState) { |
| 1108 | onCreate(savedInstanceState); |
| 1109 | } |
| 1110 | |
| 1111 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | * The hook for {@link ActivityThread} to restore the state of this activity. |
| 1113 | * |
| 1114 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} and |
| 1115 | * {@link #restoreManagedDialogs(android.os.Bundle)}. |
| 1116 | * |
| 1117 | * @param savedInstanceState contains the saved state |
| 1118 | */ |
| 1119 | final void performRestoreInstanceState(Bundle savedInstanceState) { |
| 1120 | onRestoreInstanceState(savedInstanceState); |
| 1121 | restoreManagedDialogs(savedInstanceState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1125 | * The hook for {@link ActivityThread} to restore the state of this activity. |
| 1126 | * |
| 1127 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} and |
| 1128 | * {@link #restoreManagedDialogs(android.os.Bundle)}. |
| 1129 | * |
| 1130 | * @param savedInstanceState contains the saved state |
| 1131 | * @param persistentState contains the persistable saved state |
| 1132 | */ |
| 1133 | final void performRestoreInstanceState(Bundle savedInstanceState, |
| 1134 | PersistableBundle persistentState) { |
| 1135 | onRestoreInstanceState(savedInstanceState, persistentState); |
| 1136 | if (savedInstanceState != null) { |
| 1137 | restoreManagedDialogs(savedInstanceState); |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1142 | * This method is called after {@link #onStart} when the activity is |
| 1143 | * being re-initialized from a previously saved state, given here in |
Mike LeBeau | 305de9d | 2010-03-11 09:21:08 -0800 | [diff] [blame] | 1144 | * <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] | 1145 | * to restore their state, but it is sometimes convenient to do it here |
| 1146 | * after all of the initialization has been done or to allow subclasses to |
| 1147 | * decide whether to use your default implementation. The default |
| 1148 | * implementation of this method performs a restore of any view state that |
| 1149 | * had previously been frozen by {@link #onSaveInstanceState}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1150 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | * <p>This method is called between {@link #onStart} and |
| 1152 | * {@link #onPostCreate}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1153 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | * @param savedInstanceState the data most recently supplied in {@link #onSaveInstanceState}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1155 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1156 | * @see #onCreate |
| 1157 | * @see #onPostCreate |
| 1158 | * @see #onResume |
| 1159 | * @see #onSaveInstanceState |
| 1160 | */ |
| 1161 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 1162 | if (mWindow != null) { |
| 1163 | Bundle windowState = savedInstanceState.getBundle(WINDOW_HIERARCHY_TAG); |
| 1164 | if (windowState != null) { |
| 1165 | mWindow.restoreHierarchyState(windowState); |
| 1166 | } |
| 1167 | } |
| 1168 | } |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1169 | |
| 1170 | /** |
| 1171 | * 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] | 1172 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 1173 | * <code>persistAcrossReboots</code>. The {@link android.os.PersistableBundle} passed |
| 1174 | * came from the restored PersistableBundle first |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1175 | * saved in {@link #onSaveInstanceState(Bundle, PersistableBundle)}. |
| 1176 | * |
| 1177 | * <p>This method is called between {@link #onStart} and |
| 1178 | * {@link #onPostCreate}. |
| 1179 | * |
| 1180 | * <p>If this method is called {@link #onRestoreInstanceState(Bundle)} will not be called. |
| 1181 | * |
| 1182 | * @param savedInstanceState the data most recently supplied in {@link #onSaveInstanceState}. |
| 1183 | * @param persistentState the data most recently supplied in {@link #onSaveInstanceState}. |
| 1184 | * |
| 1185 | * @see #onRestoreInstanceState(Bundle) |
| 1186 | * @see #onCreate |
| 1187 | * @see #onPostCreate |
| 1188 | * @see #onResume |
| 1189 | * @see #onSaveInstanceState |
| 1190 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1191 | public void onRestoreInstanceState(Bundle savedInstanceState, |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1192 | PersistableBundle persistentState) { |
| 1193 | if (savedInstanceState != null) { |
| 1194 | onRestoreInstanceState(savedInstanceState); |
| 1195 | } |
| 1196 | } |
| 1197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1198 | /** |
| 1199 | * Restore the state of any saved managed dialogs. |
| 1200 | * |
| 1201 | * @param savedInstanceState The bundle to restore from. |
| 1202 | */ |
| 1203 | private void restoreManagedDialogs(Bundle savedInstanceState) { |
| 1204 | final Bundle b = savedInstanceState.getBundle(SAVED_DIALOGS_TAG); |
| 1205 | if (b == null) { |
| 1206 | return; |
| 1207 | } |
| 1208 | |
| 1209 | final int[] ids = b.getIntArray(SAVED_DIALOG_IDS_KEY); |
| 1210 | final int numDialogs = ids.length; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1211 | mManagedDialogs = new SparseArray<ManagedDialog>(numDialogs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1212 | for (int i = 0; i < numDialogs; i++) { |
| 1213 | final Integer dialogId = ids[i]; |
| 1214 | Bundle dialogState = b.getBundle(savedDialogKeyFor(dialogId)); |
| 1215 | if (dialogState != null) { |
Romain Guy | e35c235 | 2009-06-19 13:18:12 -0700 | [diff] [blame] | 1216 | // Calling onRestoreInstanceState() below will invoke dispatchOnCreate |
| 1217 | // so tell createDialog() not to do it, otherwise we get an exception |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1218 | final ManagedDialog md = new ManagedDialog(); |
| 1219 | md.mArgs = b.getBundle(savedDialogArgsKeyFor(dialogId)); |
| 1220 | md.mDialog = createDialog(dialogId, dialogState, md.mArgs); |
| 1221 | if (md.mDialog != null) { |
| 1222 | mManagedDialogs.put(dialogId, md); |
| 1223 | onPrepareDialog(dialogId, md.mDialog, md.mArgs); |
| 1224 | md.mDialog.onRestoreInstanceState(dialogState); |
| 1225 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1226 | } |
| 1227 | } |
| 1228 | } |
| 1229 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1230 | private Dialog createDialog(Integer dialogId, Bundle state, Bundle args) { |
| 1231 | final Dialog dialog = onCreateDialog(dialogId, args); |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1232 | if (dialog == null) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1233 | return null; |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1234 | } |
Romain Guy | 6de4aed | 2009-07-08 10:54:45 -0700 | [diff] [blame] | 1235 | dialog.dispatchOnCreate(state); |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1236 | return dialog; |
| 1237 | } |
| 1238 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1239 | private static String savedDialogKeyFor(int key) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | return SAVED_DIALOG_KEY_PREFIX + key; |
| 1241 | } |
| 1242 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1243 | private static String savedDialogArgsKeyFor(int key) { |
| 1244 | return SAVED_DIALOG_ARGS_KEY_PREFIX + key; |
| 1245 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | |
| 1247 | /** |
| 1248 | * Called when activity start-up is complete (after {@link #onStart} |
| 1249 | * and {@link #onRestoreInstanceState} have been called). Applications will |
| 1250 | * generally not implement this method; it is intended for system |
| 1251 | * classes to do final initialization after application code has run. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1252 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1253 | * <p><em>Derived classes must call through to the super class's |
| 1254 | * implementation of this method. If they do not, an exception will be |
| 1255 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1256 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1257 | * @param savedInstanceState If the activity is being re-initialized after |
| 1258 | * previously being shut down then this Bundle contains the data it most |
| 1259 | * recently supplied in {@link #onSaveInstanceState}. <b><i>Note: Otherwise it is null.</i></b> |
| 1260 | * @see #onCreate |
| 1261 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1262 | @CallSuper |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1263 | protected void onPostCreate(@Nullable Bundle savedInstanceState) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1264 | if (!isChild()) { |
| 1265 | mTitleReady = true; |
| 1266 | onTitleChanged(getTitle(), getTitleColor()); |
| 1267 | } |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 1268 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1269 | mCalled = true; |
| 1270 | } |
| 1271 | |
| 1272 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1273 | * 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] | 1274 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 1275 | * <code>persistAcrossReboots</code>. |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1276 | * |
| 1277 | * @param savedInstanceState The data most recently supplied in {@link #onSaveInstanceState} |
| 1278 | * @param persistentState The data caming from the PersistableBundle first |
| 1279 | * saved in {@link #onSaveInstanceState(Bundle, PersistableBundle)}. |
| 1280 | * |
| 1281 | * @see #onCreate |
| 1282 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1283 | public void onPostCreate(@Nullable Bundle savedInstanceState, |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1284 | @Nullable PersistableBundle persistentState) { |
| 1285 | onPostCreate(savedInstanceState); |
| 1286 | } |
| 1287 | |
| 1288 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1289 | * Called after {@link #onCreate} — or after {@link #onRestart} when |
| 1290 | * 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] | 1291 | * user. It will be followed by {@link #onResume}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1292 | * |
| 1293 | * <p><em>Derived classes must call through to the super class's |
| 1294 | * implementation of this method. If they do not, an exception will be |
| 1295 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1296 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | * @see #onCreate |
| 1298 | * @see #onStop |
| 1299 | * @see #onResume |
| 1300 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1301 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1302 | protected void onStart() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1303 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onStart " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1304 | mCalled = true; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1305 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 1306 | mFragments.doLoaderStart(); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1307 | |
| 1308 | getApplication().dispatchActivityStarted(this); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1309 | |
| 1310 | if (mAutoFillResetNeeded) { |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 1311 | getAutofillManager().onVisibleForAutofill(); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1312 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | /** |
| 1316 | * Called after {@link #onStop} when the current activity is being |
| 1317 | * re-displayed to the user (the user has navigated back to it). It will |
| 1318 | * be followed by {@link #onStart} and then {@link #onResume}. |
| 1319 | * |
| 1320 | * <p>For activities that are using raw {@link Cursor} objects (instead of |
| 1321 | * creating them through |
| 1322 | * {@link #managedQuery(android.net.Uri , String[], String, String[], String)}, |
| 1323 | * this is usually the place |
| 1324 | * where the cursor should be requeried (because you had deactivated it in |
| 1325 | * {@link #onStop}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1326 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1327 | * <p><em>Derived classes must call through to the super class's |
| 1328 | * implementation of this method. If they do not, an exception will be |
| 1329 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1330 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1331 | * @see #onStop |
| 1332 | * @see #onStart |
| 1333 | * @see #onResume |
| 1334 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1335 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1336 | protected void onRestart() { |
| 1337 | mCalled = true; |
| 1338 | } |
| 1339 | |
| 1340 | /** |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 1341 | * Called when an {@link #onResume} is coming up, prior to other pre-resume callbacks |
| 1342 | * such as {@link #onNewIntent} and {@link #onActivityResult}. This is primarily intended |
| 1343 | * to give the activity a hint that its state is no longer saved -- it will generally |
| 1344 | * be called after {@link #onSaveInstanceState} and prior to the activity being |
| 1345 | * resumed/started again. |
| 1346 | */ |
| 1347 | public void onStateNotSaved() { |
| 1348 | } |
| 1349 | |
| 1350 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1351 | * Called after {@link #onRestoreInstanceState}, {@link #onRestart}, or |
| 1352 | * {@link #onPause}, for your activity to start interacting with the user. |
| 1353 | * This is a good place to begin animations, open exclusive-access devices |
| 1354 | * (such as the camera), etc. |
| 1355 | * |
| 1356 | * <p>Keep in mind that onResume is not the best indicator that your activity |
| 1357 | * is visible to the user; a system window such as the keyguard may be in |
| 1358 | * front. Use {@link #onWindowFocusChanged} to know for certain that your |
| 1359 | * activity is visible to the user (for example, to resume a game). |
| 1360 | * |
| 1361 | * <p><em>Derived classes must call through to the super class's |
| 1362 | * implementation of this method. If they do not, an exception will be |
| 1363 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1364 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1365 | * @see #onRestoreInstanceState |
| 1366 | * @see #onRestart |
| 1367 | * @see #onPostResume |
| 1368 | * @see #onPause |
| 1369 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1370 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1371 | protected void onResume() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1372 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onResume " + this); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1373 | getApplication().dispatchActivityResumed(this); |
George Mount | bdc4d8d | 2016-03-23 13:10:13 -0700 | [diff] [blame] | 1374 | mActivityTransitionState.onResume(this, isTopOfTask()); |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 1375 | if (mAutoFillResetNeeded) { |
| 1376 | if (!mAutoFillIgnoreFirstResumePause) { |
| 1377 | View focus = getCurrentFocus(); |
| 1378 | if (focus != null && focus.canNotifyAutofillEnterExitEvent()) { |
| 1379 | // TODO: in Activity killed/recreated case, i.e. SessionLifecycleTest# |
| 1380 | // testDatasetVisibleWhileAutofilledAppIsLifecycled: the View's initial |
| 1381 | // window visibility after recreation is INVISIBLE in onResume() and next frame |
| 1382 | // ViewRootImpl.performTraversals() changes window visibility to VISIBLE. |
| 1383 | // So we cannot call View.notifyEnterOrExited() which will do nothing |
| 1384 | // when View.isVisibleToUser() is false. |
| 1385 | getAutofillManager().notifyViewEntered(focus); |
| 1386 | } |
| 1387 | } |
| 1388 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1389 | mCalled = true; |
| 1390 | } |
| 1391 | |
| 1392 | /** |
| 1393 | * Called when activity resume is complete (after {@link #onResume} has |
| 1394 | * been called). Applications will generally not implement this method; |
| 1395 | * it is intended for system classes to do final setup after application |
| 1396 | * resume code has run. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1397 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | * <p><em>Derived classes must call through to the super class's |
| 1399 | * implementation of this method. If they do not, an exception will be |
| 1400 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1401 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1402 | * @see #onResume |
| 1403 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1404 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1405 | protected void onPostResume() { |
| 1406 | final Window win = getWindow(); |
| 1407 | if (win != null) win.makeActive(); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 1408 | if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1409 | mCalled = true; |
| 1410 | } |
| 1411 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1412 | void setVoiceInteractor(IVoiceInteractor voiceInteractor) { |
Amith Yamasani | eeed06c | 2016-05-03 15:07:03 -0700 | [diff] [blame] | 1413 | if (mVoiceInteractor != null) { |
| 1414 | for (Request activeRequest: mVoiceInteractor.getActiveRequests()) { |
| 1415 | activeRequest.cancel(); |
| 1416 | activeRequest.clear(); |
| 1417 | } |
| 1418 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1419 | if (voiceInteractor == null) { |
| 1420 | mVoiceInteractor = null; |
| 1421 | } else { |
| 1422 | mVoiceInteractor = new VoiceInteractor(voiceInteractor, this, this, |
| 1423 | Looper.myLooper()); |
| 1424 | } |
| 1425 | } |
| 1426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | /** |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1428 | * Gets the next autofill ID. |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1429 | * |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1430 | * <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] | 1431 | * will be unique. |
| 1432 | * |
| 1433 | * @return A ID that is unique in the activity |
| 1434 | * |
| 1435 | * {@hide} |
| 1436 | */ |
Felipe Leme | 42b9793 | 2018-02-20 13:04:31 -0800 | [diff] [blame] | 1437 | @Override |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1438 | public int getNextAutofillId() { |
| 1439 | if (mLastAutofillId == Integer.MAX_VALUE - 1) { |
| 1440 | mLastAutofillId = View.LAST_APP_AUTOFILL_ID; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1441 | } |
| 1442 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1443 | mLastAutofillId++; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1444 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1445 | return mLastAutofillId; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | /** |
Felipe Leme | 42b9793 | 2018-02-20 13:04:31 -0800 | [diff] [blame] | 1449 | * @hide |
| 1450 | */ |
| 1451 | @Override |
| 1452 | public AutofillId autofillClientGetNextAutofillId() { |
| 1453 | return new AutofillId(getNextAutofillId()); |
| 1454 | } |
| 1455 | |
| 1456 | /** |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1457 | * Check whether this activity is running as part of a voice interaction with the user. |
| 1458 | * If true, it should perform its interaction with the user through the |
| 1459 | * {@link VoiceInteractor} returned by {@link #getVoiceInteractor}. |
| 1460 | */ |
| 1461 | public boolean isVoiceInteraction() { |
| 1462 | return mVoiceInteractor != null; |
| 1463 | } |
| 1464 | |
| 1465 | /** |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 1466 | * Like {@link #isVoiceInteraction}, but only returns true if this is also the root |
| 1467 | * of a voice interaction. That is, returns true if this activity was directly |
| 1468 | * started by the voice interaction service as the initiation of a voice interaction. |
| 1469 | * Otherwise, for example if it was started by another activity while under voice |
| 1470 | * interaction, returns false. |
| 1471 | */ |
| 1472 | public boolean isVoiceInteractionRoot() { |
| 1473 | try { |
| 1474 | return mVoiceInteractor != null |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1475 | && ActivityManager.getService().isRootVoiceInteraction(mToken); |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 1476 | } catch (RemoteException e) { |
| 1477 | } |
| 1478 | return false; |
| 1479 | } |
| 1480 | |
| 1481 | /** |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1482 | * Retrieve the active {@link VoiceInteractor} that the user is going through to |
| 1483 | * interact with this activity. |
| 1484 | */ |
| 1485 | public VoiceInteractor getVoiceInteractor() { |
| 1486 | return mVoiceInteractor; |
| 1487 | } |
| 1488 | |
| 1489 | /** |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1490 | * Queries whether the currently enabled voice interaction service supports returning |
| 1491 | * a voice interactor for use by the activity. This is valid only for the duration of the |
| 1492 | * activity. |
| 1493 | * |
| 1494 | * @return whether the current voice interaction service supports local voice interaction |
| 1495 | */ |
| 1496 | public boolean isLocalVoiceInteractionSupported() { |
| 1497 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1498 | return ActivityManager.getService().supportsLocalVoiceInteraction(); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1499 | } catch (RemoteException re) { |
| 1500 | } |
| 1501 | return false; |
| 1502 | } |
| 1503 | |
| 1504 | /** |
| 1505 | * Starts a local voice interaction session. When ready, |
| 1506 | * {@link #onLocalVoiceInteractionStarted()} is called. You can pass a bundle of private options |
| 1507 | * to the registered voice interaction service. |
| 1508 | * @param privateOptions a Bundle of private arguments to the current voice interaction service |
| 1509 | */ |
| 1510 | public void startLocalVoiceInteraction(Bundle privateOptions) { |
| 1511 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1512 | ActivityManager.getService().startLocalVoiceInteraction(mToken, privateOptions); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1513 | } catch (RemoteException re) { |
| 1514 | } |
| 1515 | } |
| 1516 | |
| 1517 | /** |
| 1518 | * Callback to indicate that {@link #startLocalVoiceInteraction(Bundle)} has resulted in a |
| 1519 | * voice interaction session being started. You can now retrieve a voice interactor using |
| 1520 | * {@link #getVoiceInteractor()}. |
| 1521 | */ |
| 1522 | public void onLocalVoiceInteractionStarted() { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | /** |
Amith Yamasani | d8d967e | 2016-04-08 09:57:01 -0700 | [diff] [blame] | 1526 | * Callback to indicate that the local voice interaction has stopped either |
| 1527 | * because it was requested through a call to {@link #stopLocalVoiceInteraction()} |
| 1528 | * or because it was canceled by the user. The previously acquired {@link VoiceInteractor} |
| 1529 | * is no longer valid after this. |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1530 | */ |
| 1531 | public void onLocalVoiceInteractionStopped() { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | /** |
| 1535 | * Request to terminate the current voice interaction that was previously started |
Amith Yamasani | d8d967e | 2016-04-08 09:57:01 -0700 | [diff] [blame] | 1536 | * using {@link #startLocalVoiceInteraction(Bundle)}. When the interaction is |
| 1537 | * terminated, {@link #onLocalVoiceInteractionStopped()} will be called. |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1538 | */ |
| 1539 | public void stopLocalVoiceInteraction() { |
| 1540 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1541 | ActivityManager.getService().stopLocalVoiceInteraction(mToken); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1542 | } catch (RemoteException re) { |
| 1543 | } |
| 1544 | } |
| 1545 | |
| 1546 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1547 | * This is called for activities that set launchMode to "singleTop" in |
| 1548 | * their package, or if a client used the {@link Intent#FLAG_ACTIVITY_SINGLE_TOP} |
| 1549 | * flag when calling {@link #startActivity}. In either case, when the |
| 1550 | * activity is re-launched while at the top of the activity stack instead |
| 1551 | * of a new instance of the activity being started, onNewIntent() will be |
| 1552 | * called on the existing instance with the Intent that was used to |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1553 | * re-launch it. |
| 1554 | * |
| 1555 | * <p>An activity will always be paused before receiving a new intent, so |
| 1556 | * you can count on {@link #onResume} being called after this method. |
| 1557 | * |
| 1558 | * <p>Note that {@link #getIntent} still returns the original Intent. You |
| 1559 | * can use {@link #setIntent} to update it to this new Intent. |
| 1560 | * |
| 1561 | * @param intent The new intent that was started for the activity. |
| 1562 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1563 | * @see #getIntent |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1564 | * @see #setIntent |
| 1565 | * @see #onResume |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | */ |
| 1567 | protected void onNewIntent(Intent intent) { |
| 1568 | } |
| 1569 | |
| 1570 | /** |
| 1571 | * The hook for {@link ActivityThread} to save the state of this activity. |
| 1572 | * |
| 1573 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} |
| 1574 | * and {@link #saveManagedDialogs(android.os.Bundle)}. |
| 1575 | * |
| 1576 | * @param outState The bundle to save the state to. |
| 1577 | */ |
| 1578 | final void performSaveInstanceState(Bundle outState) { |
| 1579 | onSaveInstanceState(outState); |
| 1580 | saveManagedDialogs(outState); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1581 | mActivityTransitionState.saveState(outState); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 1582 | storeHasCurrentPermissionRequest(outState); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1583 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onSaveInstanceState " + this + ": " + outState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1587 | * The hook for {@link ActivityThread} to save the state of this activity. |
| 1588 | * |
| 1589 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} |
| 1590 | * and {@link #saveManagedDialogs(android.os.Bundle)}. |
| 1591 | * |
| 1592 | * @param outState The bundle to save the state to. |
| 1593 | * @param outPersistentState The bundle to save persistent state to. |
| 1594 | */ |
| 1595 | final void performSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { |
| 1596 | onSaveInstanceState(outState, outPersistentState); |
| 1597 | saveManagedDialogs(outState); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 1598 | storeHasCurrentPermissionRequest(outState); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1599 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onSaveInstanceState " + this + ": " + outState + |
| 1600 | ", " + outPersistentState); |
| 1601 | } |
| 1602 | |
| 1603 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1604 | * Called to retrieve per-instance state from an activity before being killed |
| 1605 | * so that the state can be restored in {@link #onCreate} or |
| 1606 | * {@link #onRestoreInstanceState} (the {@link Bundle} populated by this method |
| 1607 | * will be passed to both). |
| 1608 | * |
| 1609 | * <p>This method is called before an activity may be killed so that when it |
| 1610 | * comes back some time in the future it can restore its state. For example, |
| 1611 | * if activity B is launched in front of activity A, and at some point activity |
| 1612 | * A is killed to reclaim resources, activity A will have a chance to save the |
| 1613 | * current state of its user interface via this method so that when the user |
| 1614 | * returns to activity A, the state of the user interface can be restored |
| 1615 | * via {@link #onCreate} or {@link #onRestoreInstanceState}. |
| 1616 | * |
| 1617 | * <p>Do not confuse this method with activity lifecycle callbacks such as |
| 1618 | * {@link #onPause}, which is always called when an activity is being placed |
| 1619 | * in the background or on its way to destruction, or {@link #onStop} which |
| 1620 | * is called before destruction. One example of when {@link #onPause} and |
| 1621 | * {@link #onStop} is called and not this method is when a user navigates back |
| 1622 | * from activity B to activity A: there is no need to call {@link #onSaveInstanceState} |
| 1623 | * on B because that particular instance will never be restored, so the |
| 1624 | * system avoids calling it. An example when {@link #onPause} is called and |
| 1625 | * not {@link #onSaveInstanceState} is when activity B is launched in front of activity A: |
| 1626 | * the system may avoid calling {@link #onSaveInstanceState} on activity A if it isn't |
| 1627 | * killed during the lifetime of B since the state of the user interface of |
| 1628 | * A will stay intact. |
| 1629 | * |
| 1630 | * <p>The default implementation takes care of most of the UI per-instance |
| 1631 | * state for you by calling {@link android.view.View#onSaveInstanceState()} on each |
| 1632 | * view in the hierarchy that has an id, and by saving the id of the currently |
| 1633 | * focused view (all of which is restored by the default implementation of |
| 1634 | * {@link #onRestoreInstanceState}). If you override this method to save additional |
| 1635 | * information not captured by each individual view, you will likely want to |
| 1636 | * call through to the default implementation, otherwise be prepared to save |
| 1637 | * all of the state of each view yourself. |
| 1638 | * |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 1639 | * <p>If called, this method will occur after {@link #onStop} for applications |
| 1640 | * targeting platforms starting with {@link android.os.Build.VERSION_CODES#P}. |
| 1641 | * For applications targeting earlier platform versions this method will occur |
| 1642 | * before {@link #onStop} and there are no guarantees about whether it will |
| 1643 | * occur before or after {@link #onPause}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1644 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1645 | * @param outState Bundle in which to place your saved state. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1646 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1647 | * @see #onCreate |
| 1648 | * @see #onRestoreInstanceState |
| 1649 | * @see #onPause |
| 1650 | */ |
| 1651 | protected void onSaveInstanceState(Bundle outState) { |
| 1652 | outState.putBundle(WINDOW_HIERARCHY_TAG, mWindow.saveHierarchyState()); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1653 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1654 | outState.putInt(LAST_AUTOFILL_ID, mLastAutofillId); |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1655 | Parcelable p = mFragments.saveAllState(); |
| 1656 | if (p != null) { |
| 1657 | outState.putParcelable(FRAGMENTS_TAG, p); |
| 1658 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1659 | if (mAutoFillResetNeeded) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1660 | outState.putBoolean(AUTOFILL_RESET_NEEDED, true); |
| 1661 | getAutofillManager().onSaveInstanceState(outState); |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1662 | } |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1663 | getApplication().dispatchActivitySaveInstanceState(this, outState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1667 | * This is the same as {@link #onSaveInstanceState} but is called for activities |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 1668 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 1669 | * <code>persistAcrossReboots</code>. The {@link android.os.PersistableBundle} passed |
| 1670 | * in will be saved and presented in {@link #onCreate(Bundle, PersistableBundle)} |
| 1671 | * 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] | 1672 | * |
| 1673 | * @param outState Bundle in which to place your saved state. |
| 1674 | * @param outPersistentState State which will be saved across reboots. |
| 1675 | * |
| 1676 | * @see #onSaveInstanceState(Bundle) |
| 1677 | * @see #onCreate |
| 1678 | * @see #onRestoreInstanceState(Bundle, PersistableBundle) |
| 1679 | * @see #onPause |
| 1680 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1681 | public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1682 | onSaveInstanceState(outState); |
| 1683 | } |
| 1684 | |
| 1685 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1686 | * Save the state of any managed dialogs. |
| 1687 | * |
| 1688 | * @param outState place to store the saved state. |
| 1689 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1690 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1691 | private void saveManagedDialogs(Bundle outState) { |
| 1692 | if (mManagedDialogs == null) { |
| 1693 | return; |
| 1694 | } |
| 1695 | |
| 1696 | final int numDialogs = mManagedDialogs.size(); |
| 1697 | if (numDialogs == 0) { |
| 1698 | return; |
| 1699 | } |
| 1700 | |
| 1701 | Bundle dialogState = new Bundle(); |
| 1702 | |
| 1703 | int[] ids = new int[mManagedDialogs.size()]; |
| 1704 | |
| 1705 | // save each dialog's bundle, gather the ids |
| 1706 | for (int i = 0; i < numDialogs; i++) { |
| 1707 | final int key = mManagedDialogs.keyAt(i); |
| 1708 | ids[i] = key; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1709 | final ManagedDialog md = mManagedDialogs.valueAt(i); |
| 1710 | dialogState.putBundle(savedDialogKeyFor(key), md.mDialog.onSaveInstanceState()); |
| 1711 | if (md.mArgs != null) { |
| 1712 | dialogState.putBundle(savedDialogArgsKeyFor(key), md.mArgs); |
| 1713 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | dialogState.putIntArray(SAVED_DIALOG_IDS_KEY, ids); |
| 1717 | outState.putBundle(SAVED_DIALOGS_TAG, dialogState); |
| 1718 | } |
| 1719 | |
| 1720 | |
| 1721 | /** |
| 1722 | * Called as part of the activity lifecycle when an activity is going into |
| 1723 | * the background, but has not (yet) been killed. The counterpart to |
| 1724 | * {@link #onResume}. |
| 1725 | * |
| 1726 | * <p>When activity B is launched in front of activity A, this callback will |
| 1727 | * be invoked on A. B will not be created until A's {@link #onPause} returns, |
| 1728 | * so be sure to not do anything lengthy here. |
| 1729 | * |
| 1730 | * <p>This callback is mostly used for saving any persistent state the |
| 1731 | * activity is editing, to present a "edit in place" model to the user and |
| 1732 | * making sure nothing is lost if there are not enough resources to start |
| 1733 | * the new activity without first killing this one. This is also a good |
| 1734 | * 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] | 1735 | * 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] | 1736 | * as fast as possible, or to close resources that are exclusive access |
| 1737 | * such as the camera. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1738 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1739 | * <p>In situations where the system needs more memory it may kill paused |
| 1740 | * processes to reclaim resources. Because of this, you should be sure |
| 1741 | * that all of your state is saved by the time you return from |
| 1742 | * this function. In general {@link #onSaveInstanceState} is used to save |
| 1743 | * per-instance state in the activity and this method is used to store |
| 1744 | * global persistent data (in content providers, files, etc.) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1745 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1746 | * <p>After receiving this call you will usually receive a following call |
| 1747 | * to {@link #onStop} (after the next activity has been resumed and |
| 1748 | * displayed), however in some cases there will be a direct call back to |
| 1749 | * {@link #onResume} without going through the stopped state. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1750 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1751 | * <p><em>Derived classes must call through to the super class's |
| 1752 | * implementation of this method. If they do not, an exception will be |
| 1753 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1754 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1755 | * @see #onResume |
| 1756 | * @see #onSaveInstanceState |
| 1757 | * @see #onStop |
| 1758 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1759 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1760 | protected void onPause() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1761 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onPause " + this); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1762 | getApplication().dispatchActivityPaused(this); |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 1763 | if (mAutoFillResetNeeded) { |
| 1764 | if (!mAutoFillIgnoreFirstResumePause) { |
| 1765 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "autofill notifyViewExited " + this); |
| 1766 | View focus = getCurrentFocus(); |
| 1767 | if (focus != null && focus.canNotifyAutofillEnterExitEvent()) { |
| 1768 | getAutofillManager().notifyViewExited(focus); |
| 1769 | } |
| 1770 | } else { |
| 1771 | // reset after first pause() |
| 1772 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "autofill got first pause " + this); |
| 1773 | mAutoFillIgnoreFirstResumePause = false; |
| 1774 | } |
| 1775 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1776 | mCalled = true; |
| 1777 | } |
| 1778 | |
| 1779 | /** |
| 1780 | * Called as part of the activity lifecycle when an activity is about to go |
| 1781 | * into the background as the result of user choice. For example, when the |
| 1782 | * user presses the Home key, {@link #onUserLeaveHint} will be called, but |
| 1783 | * when an incoming phone call causes the in-call Activity to be automatically |
| 1784 | * brought to the foreground, {@link #onUserLeaveHint} will not be called on |
| 1785 | * the activity being interrupted. In cases when it is invoked, this method |
| 1786 | * is called right before the activity's {@link #onPause} callback. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1787 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1788 | * <p>This callback and {@link #onUserInteraction} are intended to help |
| 1789 | * activities manage status bar notifications intelligently; specifically, |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 1790 | * for helping activities determine the proper time to cancel a notification. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1791 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1792 | * @see #onUserInteraction() |
| 1793 | */ |
| 1794 | protected void onUserLeaveHint() { |
| 1795 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1796 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1797 | /** |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 1798 | * @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] | 1799 | */ |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 1800 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1801 | public boolean onCreateThumbnail(Bitmap outBitmap, Canvas canvas) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 1802 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | /** |
| 1806 | * Generate a new description for this activity. This method is called |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 1807 | * 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] | 1808 | * description of its current state to be displayed to the user. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1809 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1810 | * <p>The default implementation returns null, which will cause you to |
| 1811 | * inherit the description from the previous activity. If all activities |
| 1812 | * return null, generally the label of the top activity will be used as the |
| 1813 | * description. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1814 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1815 | * @return A description of what the user is doing. It should be short and |
| 1816 | * sweet (only a few words). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1817 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1818 | * @see #onSaveInstanceState |
Wale Ogunwale | 578b3bd | 2018-02-13 08:30:53 -0800 | [diff] [blame] | 1819 | * @see #onStop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1820 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1821 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1822 | public CharSequence onCreateDescription() { |
| 1823 | return null; |
| 1824 | } |
| 1825 | |
| 1826 | /** |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1827 | * This is called when the user is requesting an assist, to build a full |
| 1828 | * {@link Intent#ACTION_ASSIST} Intent with all of the context of the current |
| 1829 | * application. You can override this method to place into the bundle anything |
| 1830 | * 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] | 1831 | * of the assist Intent. |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1832 | * |
| 1833 | * <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] | 1834 | * been registered with {@link Application#registerOnProvideAssistDataListener |
| 1835 | * Application.registerOnProvideAssistDataListener}. |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1836 | */ |
| 1837 | public void onProvideAssistData(Bundle data) { |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | /** |
| 1841 | * This is called when the user is requesting an assist, to provide references |
| 1842 | * to content related to the current activity. Before being called, the |
| 1843 | * {@code outContent} Intent is filled with the base Intent of the activity (the Intent |
| 1844 | * returned by {@link #getIntent()}). The Intent's extras are stripped of any types |
| 1845 | * that are not valid for {@link PersistableBundle} or non-framework Parcelables, and |
| 1846 | * the flags {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION} and |
| 1847 | * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION} are cleared from the Intent. |
| 1848 | * |
| 1849 | * <p>Custom implementation may adjust the content intent to better reflect the top-level |
| 1850 | * context of the activity, and fill in its ClipData with additional content of |
| 1851 | * interest that the user is currently viewing. For example, an image gallery application |
| 1852 | * that has launched in to an activity allowing the user to swipe through pictures should |
| 1853 | * modify the intent to reference the current image they are looking it; such an |
| 1854 | * application when showing a list of pictures should add a ClipData that has |
| 1855 | * references to all of the pictures currently visible on screen.</p> |
| 1856 | * |
| 1857 | * @param outContent The assist content to return. |
| 1858 | */ |
| 1859 | public void onProvideAssistContent(AssistContent outContent) { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1860 | } |
| 1861 | |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 1862 | /** |
Clara Bayarri | ab591ba | 2016-05-16 17:48:16 +0100 | [diff] [blame] | 1863 | * Request the Keyboard Shortcuts screen to show up. This will trigger |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 1864 | * {@link #onProvideKeyboardShortcuts} to retrieve the shortcuts for the foreground activity. |
| 1865 | */ |
Clara Bayarri | ac6f034 | 2016-05-16 14:15:14 +0100 | [diff] [blame] | 1866 | public final void requestShowKeyboardShortcuts() { |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 1867 | Intent intent = new Intent(Intent.ACTION_SHOW_KEYBOARD_SHORTCUTS); |
Andrei Stingaceanu | a3d2693 | 2016-07-15 11:12:20 +0100 | [diff] [blame] | 1868 | intent.setPackage(KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME); |
| 1869 | sendBroadcastAsUser(intent, UserHandle.SYSTEM); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | /** |
| 1873 | * Dismiss the Keyboard Shortcuts screen. |
| 1874 | */ |
| 1875 | public final void dismissKeyboardShortcutsHelper() { |
| 1876 | Intent intent = new Intent(Intent.ACTION_DISMISS_KEYBOARD_SHORTCUTS); |
Andrei Stingaceanu | a3d2693 | 2016-07-15 11:12:20 +0100 | [diff] [blame] | 1877 | intent.setPackage(KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME); |
| 1878 | sendBroadcastAsUser(intent, UserHandle.SYSTEM); |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 1879 | } |
| 1880 | |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 1881 | @Override |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 1882 | public void onProvideKeyboardShortcuts( |
| 1883 | List<KeyboardShortcutGroup> data, Menu menu, int deviceId) { |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 1884 | if (menu == null) { |
| 1885 | return; |
| 1886 | } |
| 1887 | KeyboardShortcutGroup group = null; |
| 1888 | int menuSize = menu.size(); |
| 1889 | for (int i = 0; i < menuSize; ++i) { |
| 1890 | final MenuItem item = menu.getItem(i); |
| 1891 | final CharSequence title = item.getTitle(); |
| 1892 | final char alphaShortcut = item.getAlphabeticShortcut(); |
Peeyush Agarwal | e631e32 | 2016-10-19 11:41:42 +0100 | [diff] [blame] | 1893 | final int alphaModifiers = item.getAlphabeticModifiers(); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 1894 | if (title != null && alphaShortcut != MIN_VALUE) { |
| 1895 | if (group == null) { |
Clara Bayarri | ada88b3 | 2016-02-02 18:08:01 +0000 | [diff] [blame] | 1896 | final int resource = mApplication.getApplicationInfo().labelRes; |
| 1897 | group = new KeyboardShortcutGroup(resource != 0 ? getString(resource) : null); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 1898 | } |
| 1899 | group.addItem(new KeyboardShortcutInfo( |
Peeyush Agarwal | e631e32 | 2016-10-19 11:41:42 +0100 | [diff] [blame] | 1900 | title, alphaShortcut, alphaModifiers)); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 1901 | } |
| 1902 | } |
| 1903 | if (group != null) { |
| 1904 | data.add(group); |
| 1905 | } |
| 1906 | } |
| 1907 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1908 | /** |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 1909 | * Ask to have the current assistant shown to the user. This only works if the calling |
| 1910 | * activity is the current foreground activity. It is the same as calling |
| 1911 | * {@link android.service.voice.VoiceInteractionService#showSession |
| 1912 | * VoiceInteractionService.showSession} and requesting all of the possible context. |
| 1913 | * The receiver will always see |
| 1914 | * {@link android.service.voice.VoiceInteractionSession#SHOW_SOURCE_APPLICATION} set. |
| 1915 | * @return Returns true if the assistant was successfully invoked, else false. For example |
| 1916 | * false will be returned if the caller is not the current top activity. |
| 1917 | */ |
| 1918 | public boolean showAssist(Bundle args) { |
| 1919 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1920 | return ActivityManager.getService().showAssistFromActivity(mToken, args); |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 1921 | } catch (RemoteException e) { |
| 1922 | } |
| 1923 | return false; |
| 1924 | } |
| 1925 | |
| 1926 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1927 | * Called when you are no longer visible to the user. You will next |
| 1928 | * receive either {@link #onRestart}, {@link #onDestroy}, or nothing, |
| 1929 | * depending on later user activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1930 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1931 | * <p><em>Derived classes must call through to the super class's |
| 1932 | * implementation of this method. If they do not, an exception will be |
| 1933 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1934 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1935 | * @see #onRestart |
| 1936 | * @see #onResume |
| 1937 | * @see #onSaveInstanceState |
| 1938 | * @see #onDestroy |
| 1939 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1940 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1941 | protected void onStop() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1942 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onStop " + this); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 1943 | if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(false); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1944 | mActivityTransitionState.onStop(); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1945 | getApplication().dispatchActivityStopped(this); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1946 | mTranslucentCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1947 | mCalled = true; |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1948 | |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 1949 | if (mAutoFillResetNeeded) { |
| 1950 | getAutofillManager().onInvisibleForAutofill(); |
| 1951 | } |
| 1952 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1953 | if (isFinishing()) { |
| 1954 | if (mAutoFillResetNeeded) { |
Felipe Leme | 5b32ebe | 2018-02-15 12:52:19 -0800 | [diff] [blame] | 1955 | getAutofillManager().onActivityFinishing(); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1956 | } else if (mIntent != null |
| 1957 | && mIntent.hasExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN)) { |
| 1958 | // Activity was launched when user tapped a link in the Autofill Save UI - since |
| 1959 | // user launched another activity, the Save UI should not be restored when this |
| 1960 | // activity is finished. |
| 1961 | getAutofillManager().onPendingSaveUi(AutofillManager.PENDING_UI_OPERATION_CANCEL, |
| 1962 | mIntent.getIBinderExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN)); |
| 1963 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 1964 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * Perform any final cleanup before an activity is destroyed. This can |
| 1969 | * happen either because the activity is finishing (someone called |
| 1970 | * {@link #finish} on it, or because the system is temporarily destroying |
| 1971 | * this instance of the activity to save space. You can distinguish |
| 1972 | * between these two scenarios with the {@link #isFinishing} method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1973 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1974 | * <p><em>Note: do not count on this method being called as a place for |
| 1975 | * saving data! For example, if an activity is editing data in a content |
| 1976 | * provider, those edits should be committed in either {@link #onPause} or |
| 1977 | * {@link #onSaveInstanceState}, not here.</em> This method is usually implemented to |
| 1978 | * free resources like threads that are associated with an activity, so |
| 1979 | * that a destroyed activity does not leave such things around while the |
| 1980 | * rest of its application is still running. There are situations where |
| 1981 | * the system will simply kill the activity's hosting process without |
| 1982 | * calling this method (or any others) in it, so it should not be used to |
| 1983 | * do things that are intended to remain around after the process goes |
| 1984 | * away. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1985 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1986 | * <p><em>Derived classes must call through to the super class's |
| 1987 | * implementation of this method. If they do not, an exception will be |
| 1988 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1989 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1990 | * @see #onPause |
| 1991 | * @see #onStop |
| 1992 | * @see #finish |
| 1993 | * @see #isFinishing |
| 1994 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1995 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1996 | protected void onDestroy() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1997 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onDestroy " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1998 | mCalled = true; |
| 1999 | |
| 2000 | // dismiss any dialogs we are managing. |
| 2001 | if (mManagedDialogs != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2002 | final int numDialogs = mManagedDialogs.size(); |
| 2003 | for (int i = 0; i < numDialogs; i++) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2004 | final ManagedDialog md = mManagedDialogs.valueAt(i); |
| 2005 | if (md.mDialog.isShowing()) { |
| 2006 | md.mDialog.dismiss(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2007 | } |
| 2008 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2009 | mManagedDialogs = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2010 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2011 | |
| 2012 | // close any cursors we are managing. |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 2013 | synchronized (mManagedCursors) { |
| 2014 | int numCursors = mManagedCursors.size(); |
| 2015 | for (int i = 0; i < numCursors; i++) { |
| 2016 | ManagedCursor c = mManagedCursors.get(i); |
| 2017 | if (c != null) { |
| 2018 | c.mCursor.close(); |
| 2019 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2020 | } |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 2021 | mManagedCursors.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2022 | } |
Amith Yamasani | 4986044 | 2010-03-17 20:54:10 -0700 | [diff] [blame] | 2023 | |
| 2024 | // Close any open search dialog |
| 2025 | if (mSearchManager != null) { |
| 2026 | mSearchManager.stopSearch(); |
| 2027 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 2028 | |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 2029 | if (mActionBar != null) { |
| 2030 | mActionBar.onDestroy(); |
| 2031 | } |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 2032 | |
| 2033 | getApplication().dispatchActivityDestroyed(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | /** |
Dianne Hackborn | ebc15ef | 2013-10-09 17:36:57 -0700 | [diff] [blame] | 2037 | * Report to the system that your app is now fully drawn, purely for diagnostic |
| 2038 | * purposes (calling it does not impact the visible behavior of the activity). |
| 2039 | * This is only used to help instrument application launch times, so that the |
| 2040 | * app can report when it is fully in a usable state; without this, the only thing |
| 2041 | * the system itself can determine is the point at which the activity's window |
| 2042 | * 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] | 2043 | * measurement, you should always call this method after first launch (when |
Dianne Hackborn | ebc15ef | 2013-10-09 17:36:57 -0700 | [diff] [blame] | 2044 | * {@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] | 2045 | * entirely drawn your UI and populated with all of the significant data. You |
| 2046 | * can safely call this method any time after first launch as well, in which case |
| 2047 | * it will simply be ignored. |
| 2048 | */ |
| 2049 | public void reportFullyDrawn() { |
| 2050 | if (mDoReportFullyDrawn) { |
| 2051 | mDoReportFullyDrawn = false; |
| 2052 | try { |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 2053 | ActivityManager.getService().reportActivityFullyDrawn(mToken, mRestoredFromBundle); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 2054 | } catch (RemoteException e) { |
| 2055 | } |
| 2056 | } |
| 2057 | } |
| 2058 | |
| 2059 | /** |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2060 | * 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] | 2061 | * visa-versa. This method provides the same configuration that will be sent in the following |
| 2062 | * {@link #onConfigurationChanged(Configuration)} call after the activity enters this mode. |
| 2063 | * |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2064 | * @see android.R.attr#resizeableActivity |
| 2065 | * |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2066 | * @param isInMultiWindowMode True if the activity is in multi-window mode. |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2067 | * @param newConfig The new configuration of the activity with the state |
| 2068 | * {@param isInMultiWindowMode}. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2069 | */ |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2070 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) { |
| 2071 | // Left deliberately empty. There should be no side effects if a direct |
| 2072 | // subclass of Activity does not call super. |
| 2073 | onMultiWindowModeChanged(isInMultiWindowMode); |
| 2074 | } |
| 2075 | |
| 2076 | /** |
| 2077 | * Called by the system when the activity changes from fullscreen mode to multi-window mode and |
| 2078 | * visa-versa. |
| 2079 | * |
| 2080 | * @see android.R.attr#resizeableActivity |
| 2081 | * |
| 2082 | * @param isInMultiWindowMode True if the activity is in multi-window mode. |
| 2083 | * |
| 2084 | * @deprecated Use {@link #onMultiWindowModeChanged(boolean, Configuration)} instead. |
| 2085 | */ |
| 2086 | @Deprecated |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2087 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 2088 | // Left deliberately empty. There should be no side effects if a direct |
| 2089 | // subclass of Activity does not call super. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | /** |
| 2093 | * Returns true if the activity is currently in multi-window mode. |
| 2094 | * @see android.R.attr#resizeableActivity |
| 2095 | * |
| 2096 | * @return True if the activity is in multi-window mode. |
| 2097 | */ |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2098 | public boolean isInMultiWindowMode() { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2099 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2100 | return ActivityManager.getService().isInMultiWindowMode(mToken); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2101 | } catch (RemoteException e) { |
| 2102 | } |
| 2103 | return false; |
| 2104 | } |
| 2105 | |
| 2106 | /** |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2107 | * Called by the system when the activity changes to and from picture-in-picture mode. This |
| 2108 | * method provides the same configuration that will be sent in the following |
| 2109 | * {@link #onConfigurationChanged(Configuration)} call after the activity enters this mode. |
| 2110 | * |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2111 | * @see android.R.attr#supportsPictureInPicture |
| 2112 | * |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2113 | * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode. |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2114 | * @param newConfig The new configuration of the activity with the state |
| 2115 | * {@param isInPictureInPictureMode}. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2116 | */ |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2117 | public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, |
| 2118 | Configuration newConfig) { |
| 2119 | // Left deliberately empty. There should be no side effects if a direct |
| 2120 | // subclass of Activity does not call super. |
| 2121 | onPictureInPictureModeChanged(isInPictureInPictureMode); |
| 2122 | } |
| 2123 | |
| 2124 | /** |
| 2125 | * Called by the system when the activity changes to and from picture-in-picture mode. |
| 2126 | * |
| 2127 | * @see android.R.attr#supportsPictureInPicture |
| 2128 | * |
| 2129 | * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode. |
| 2130 | * |
| 2131 | * @deprecated Use {@link #onPictureInPictureModeChanged(boolean, Configuration)} instead. |
| 2132 | */ |
| 2133 | @Deprecated |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2134 | public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 2135 | // Left deliberately empty. There should be no side effects if a direct |
| 2136 | // subclass of Activity does not call super. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | /** |
| 2140 | * Returns true if the activity is currently in picture-in-picture mode. |
| 2141 | * @see android.R.attr#supportsPictureInPicture |
| 2142 | * |
| 2143 | * @return True if the activity is in picture-in-picture mode. |
| 2144 | */ |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2145 | public boolean isInPictureInPictureMode() { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2146 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2147 | return ActivityManager.getService().isInPictureInPictureMode(mToken); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2148 | } catch (RemoteException e) { |
| 2149 | } |
| 2150 | return false; |
| 2151 | } |
| 2152 | |
| 2153 | /** |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2154 | * 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] | 2155 | * prior calls to {@link #setPictureInPictureParams(PictureInPictureParams)} will still apply |
| 2156 | * when entering picture-in-picture through this call. |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2157 | * |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2158 | * @see #enterPictureInPictureMode(PictureInPictureParams) |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 2159 | * @see android.R.attr#supportsPictureInPicture |
| 2160 | */ |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2161 | @Deprecated |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2162 | public void enterPictureInPictureMode() { |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2163 | enterPictureInPictureMode(new PictureInPictureParams.Builder().build()); |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 2164 | } |
| 2165 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2166 | /** @removed */ |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2167 | @Deprecated |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2168 | public boolean enterPictureInPictureMode(@NonNull PictureInPictureArgs args) { |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2169 | return enterPictureInPictureMode(PictureInPictureArgs.convert(args)); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | /** |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2173 | * Puts the activity in picture-in-picture mode if possible in the current system state. The |
| 2174 | * set parameters in {@param params} will be combined with the parameters from prior calls to |
| 2175 | * {@link #setPictureInPictureParams(PictureInPictureParams)}. |
| 2176 | * |
| 2177 | * The system may disallow entering picture-in-picture in various cases, including when the |
| 2178 | * activity is not visible, if the screen is locked or if the user has an activity pinned. |
| 2179 | * |
| 2180 | * @see android.R.attr#supportsPictureInPicture |
| 2181 | * @see PictureInPictureParams |
| 2182 | * |
| 2183 | * @param params non-null parameters to be combined with previously set parameters when entering |
| 2184 | * picture-in-picture. |
| 2185 | * |
Winson Chung | 80fa2d8 | 2018-01-25 13:58:20 -0800 | [diff] [blame] | 2186 | * @return true if the system successfully put this activity into picture-in-picture mode or was |
| 2187 | * already in picture-in-picture mode (@see {@link #isInPictureInPictureMode()). If the device |
| 2188 | * does not support picture-in-picture, return false. |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2189 | */ |
| 2190 | public boolean enterPictureInPictureMode(@NonNull PictureInPictureParams params) { |
| 2191 | try { |
Winson Chung | 80fa2d8 | 2018-01-25 13:58:20 -0800 | [diff] [blame] | 2192 | if (!deviceSupportsPictureInPictureMode()) { |
| 2193 | return false; |
| 2194 | } |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2195 | if (params == null) { |
| 2196 | throw new IllegalArgumentException("Expected non-null picture-in-picture params"); |
| 2197 | } |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 2198 | if (!mCanEnterPictureInPicture) { |
| 2199 | throw new IllegalStateException("Activity must be resumed to enter" |
| 2200 | + " picture-in-picture"); |
| 2201 | } |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2202 | return ActivityManagerNative.getDefault().enterPictureInPictureMode(mToken, params); |
| 2203 | } catch (RemoteException e) { |
| 2204 | return false; |
| 2205 | } |
| 2206 | } |
| 2207 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2208 | /** @removed */ |
| 2209 | @Deprecated |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2210 | public void setPictureInPictureArgs(@NonNull PictureInPictureArgs args) { |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2211 | setPictureInPictureParams(PictureInPictureArgs.convert(args)); |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | /** |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2215 | * Updates the properties of the picture-in-picture activity, or sets it to be used later when |
| 2216 | * {@link #enterPictureInPictureMode()} is called. |
| 2217 | * |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2218 | * @param params the new parameters for the picture-in-picture. |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2219 | */ |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2220 | public void setPictureInPictureParams(@NonNull PictureInPictureParams params) { |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2221 | try { |
Winson Chung | 80fa2d8 | 2018-01-25 13:58:20 -0800 | [diff] [blame] | 2222 | if (!deviceSupportsPictureInPictureMode()) { |
| 2223 | return; |
| 2224 | } |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2225 | if (params == null) { |
| 2226 | throw new IllegalArgumentException("Expected non-null picture-in-picture params"); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2227 | } |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2228 | ActivityManagerNative.getDefault().setPictureInPictureParams(mToken, params); |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2229 | } catch (RemoteException e) { |
| 2230 | } |
| 2231 | } |
| 2232 | |
Winson Chung | 8802eac | 2017-04-17 14:21:44 -0700 | [diff] [blame] | 2233 | /** |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2234 | * Return the number of actions that will be displayed in the picture-in-picture UI when the |
| 2235 | * user interacts with the activity currently in picture-in-picture mode. This number may change |
| 2236 | * if the global configuration changes (ie. if the device is plugged into an external display), |
| 2237 | * but will always be larger than three. |
| 2238 | */ |
| 2239 | public int getMaxNumPictureInPictureActions() { |
| 2240 | try { |
| 2241 | return ActivityManagerNative.getDefault().getMaxNumPictureInPictureActions(mToken); |
| 2242 | } catch (RemoteException e) { |
| 2243 | return 0; |
| 2244 | } |
| 2245 | } |
| 2246 | |
Winson Chung | 80fa2d8 | 2018-01-25 13:58:20 -0800 | [diff] [blame] | 2247 | /** |
| 2248 | * @return Whether this device supports picture-in-picture. |
| 2249 | */ |
| 2250 | private boolean deviceSupportsPictureInPictureMode() { |
| 2251 | return getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE); |
| 2252 | } |
| 2253 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2254 | void dispatchMovedToDisplay(int displayId, Configuration config) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2255 | updateDisplay(displayId); |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2256 | onMovedToDisplay(displayId, config); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | /** |
| 2260 | * Called by the system when the activity is moved from one display to another without |
| 2261 | * recreation. This means that this activity is declared to handle all changes to configuration |
| 2262 | * 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] | 2263 | * again. |
| 2264 | * |
| 2265 | * <p>This call will be followed by {@link #onConfigurationChanged(Configuration)} if the |
| 2266 | * applied configuration actually changed. It is up to app developer to choose whether to handle |
| 2267 | * the change in this method or in the following {@link #onConfigurationChanged(Configuration)} |
| 2268 | * call. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2269 | * |
| 2270 | * <p>Use this callback to track changes to the displays if some activity functionality relies |
| 2271 | * on an association with some display properties. |
| 2272 | * |
| 2273 | * @param displayId The id of the display to which activity was moved. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2274 | * @param config Configuration of the activity resources on new display after move. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2275 | * |
| 2276 | * @see #onConfigurationChanged(Configuration) |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2277 | * @see View#onMovedToDisplay(int, Configuration) |
Andrii Kulian | cadacce | 2017-04-26 18:09:54 -0700 | [diff] [blame] | 2278 | * @hide |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2279 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2280 | public void onMovedToDisplay(int displayId, Configuration config) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2281 | } |
| 2282 | |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2283 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2284 | * Called by the system when the device configuration changes while your |
| 2285 | * activity is running. Note that this will <em>only</em> be called if |
| 2286 | * you have selected configurations you would like to handle with the |
| 2287 | * {@link android.R.attr#configChanges} attribute in your manifest. If |
| 2288 | * any configuration change occurs that is not selected to be reported |
| 2289 | * by that attribute, then instead of reporting it the system will stop |
| 2290 | * and restart the activity (to have it launched with the new |
| 2291 | * configuration). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2292 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2293 | * <p>At the time that this function has been called, your Resources |
| 2294 | * object will have been updated to return resource values matching the |
| 2295 | * new configuration. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2296 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2297 | * @param newConfig The new device configuration. |
| 2298 | */ |
| 2299 | public void onConfigurationChanged(Configuration newConfig) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2300 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onConfigurationChanged " + this + ": " + newConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2301 | mCalled = true; |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 2302 | |
Dianne Hackborn | 9d07180 | 2010-12-08 14:49:15 -0800 | [diff] [blame] | 2303 | mFragments.dispatchConfigurationChanged(newConfig); |
| 2304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2305 | if (mWindow != null) { |
| 2306 | // Pass the configuration changed event to the window |
| 2307 | mWindow.onConfigurationChanged(newConfig); |
| 2308 | } |
Adam Powell | 45c0b19 | 2011-07-28 15:11:57 -0700 | [diff] [blame] | 2309 | |
| 2310 | if (mActionBar != null) { |
| 2311 | // Do this last; the action bar will need to access |
| 2312 | // view changes from above. |
| 2313 | mActionBar.onConfigurationChanged(newConfig); |
| 2314 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2315 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2317 | /** |
| 2318 | * If this activity is being destroyed because it can not handle a |
| 2319 | * configuration parameter being changed (and thus its |
| 2320 | * {@link #onConfigurationChanged(Configuration)} method is |
| 2321 | * <em>not</em> being called), then you can use this method to discover |
| 2322 | * the set of changes that have occurred while in the process of being |
| 2323 | * destroyed. Note that there is no guarantee that these will be |
| 2324 | * accurate (other changes could have happened at any time), so you should |
| 2325 | * only use this as an optimization hint. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2326 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2327 | * @return Returns a bit field of the configuration parameters that are |
| 2328 | * changing, as defined by the {@link android.content.res.Configuration} |
| 2329 | * class. |
| 2330 | */ |
| 2331 | public int getChangingConfigurations() { |
| 2332 | return mConfigChangeFlags; |
| 2333 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2335 | /** |
| 2336 | * Retrieve the non-configuration instance data that was previously |
| 2337 | * returned by {@link #onRetainNonConfigurationInstance()}. This will |
| 2338 | * be available from the initial {@link #onCreate} and |
| 2339 | * {@link #onStart} calls to the new instance, allowing you to extract |
| 2340 | * any useful dynamic state from the previous instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2341 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2342 | * <p>Note that the data you retrieve here should <em>only</em> be used |
| 2343 | * as an optimization for handling configuration changes. You should always |
| 2344 | * be able to handle getting a null pointer back, and an activity must |
| 2345 | * still be able to restore itself to its previous state (through the |
| 2346 | * normal {@link #onSaveInstanceState(Bundle)} mechanism) even if this |
| 2347 | * function returns null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2348 | * |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2349 | * <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] | 2350 | * {@link Fragment#setRetainInstance(boolean)} instead; this is also |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2351 | * available on older platforms through the Android support libraries. |
| 2352 | * |
| 2353 | * @return the object previously returned by {@link #onRetainNonConfigurationInstance()} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2354 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2355 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2356 | public Object getLastNonConfigurationInstance() { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2357 | return mLastNonConfigurationInstances != null |
| 2358 | ? mLastNonConfigurationInstances.activity : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2359 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2360 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2361 | /** |
| 2362 | * Called by the system, as part of destroying an |
| 2363 | * activity due to a configuration change, when it is known that a new |
| 2364 | * instance will immediately be created for the new configuration. You |
| 2365 | * can return any object you like here, including the activity instance |
| 2366 | * itself, which can later be retrieved by calling |
| 2367 | * {@link #getLastNonConfigurationInstance()} in the new activity |
| 2368 | * instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2369 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2370 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 2371 | * or later, consider instead using a {@link Fragment} with |
| 2372 | * {@link Fragment#setRetainInstance(boolean) |
| 2373 | * Fragment.setRetainInstance(boolean}.</em> |
| 2374 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2375 | * <p>This function is called purely as an optimization, and you must |
| 2376 | * not rely on it being called. When it is called, a number of guarantees |
| 2377 | * will be made to help optimize configuration switching: |
| 2378 | * <ul> |
| 2379 | * <li> The function will be called between {@link #onStop} and |
| 2380 | * {@link #onDestroy}. |
| 2381 | * <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] | 2382 | * created after this one's {@link #onDestroy()} is called. In particular, |
| 2383 | * <em>no</em> messages will be dispatched during this time (when the returned |
| 2384 | * 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] | 2385 | * <li> The object you return here will <em>always</em> be available from |
| 2386 | * the {@link #getLastNonConfigurationInstance()} method of the following |
| 2387 | * activity instance as described there. |
| 2388 | * </ul> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2389 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2390 | * <p>These guarantees are designed so that an activity can use this API |
| 2391 | * to propagate extensive state from the old to new activity instance, from |
| 2392 | * loaded bitmaps, to network connections, to evenly actively running |
| 2393 | * threads. Note that you should <em>not</em> propagate any data that |
| 2394 | * may change based on the configuration, including any data loaded from |
| 2395 | * resources such as strings, layouts, or drawables. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2396 | * |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 2397 | * <p>The guarantee of no message handling during the switch to the next |
| 2398 | * activity simplifies use with active objects. For example if your retained |
| 2399 | * state is an {@link android.os.AsyncTask} you are guaranteed that its |
| 2400 | * call back functions (like {@link android.os.AsyncTask#onPostExecute}) will |
| 2401 | * not be called from the call here until you execute the next instance's |
| 2402 | * {@link #onCreate(Bundle)}. (Note however that there is of course no such |
| 2403 | * guarantee for {@link android.os.AsyncTask#doInBackground} since that is |
| 2404 | * running in a separate thread.) |
| 2405 | * |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2406 | * <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] | 2407 | * {@link Fragment#setRetainInstance(boolean)} instead; this is also |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2408 | * available on older platforms through the Android support libraries. |
| 2409 | * |
| 2410 | * @return any Object holding the desired state to propagate to the |
| 2411 | * next activity instance |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2412 | */ |
| 2413 | public Object onRetainNonConfigurationInstance() { |
| 2414 | return null; |
| 2415 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2417 | /** |
| 2418 | * Retrieve the non-configuration instance data that was previously |
| 2419 | * returned by {@link #onRetainNonConfigurationChildInstances()}. This will |
| 2420 | * be available from the initial {@link #onCreate} and |
| 2421 | * {@link #onStart} calls to the new instance, allowing you to extract |
| 2422 | * any useful dynamic state from the previous instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2423 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2424 | * <p>Note that the data you retrieve here should <em>only</em> be used |
| 2425 | * as an optimization for handling configuration changes. You should always |
| 2426 | * be able to handle getting a null pointer back, and an activity must |
| 2427 | * still be able to restore itself to its previous state (through the |
| 2428 | * normal {@link #onSaveInstanceState(Bundle)} mechanism) even if this |
| 2429 | * function returns null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2430 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2431 | * @return Returns the object previously returned by |
| 2432 | * {@link #onRetainNonConfigurationChildInstances()} |
| 2433 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2434 | @Nullable |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2435 | HashMap<String, Object> getLastNonConfigurationChildInstances() { |
| 2436 | return mLastNonConfigurationInstances != null |
| 2437 | ? mLastNonConfigurationInstances.children : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2438 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | /** |
| 2441 | * This method is similar to {@link #onRetainNonConfigurationInstance()} except that |
| 2442 | * it should return either a mapping from child activity id strings to arbitrary objects, |
| 2443 | * or null. This method is intended to be used by Activity framework subclasses that control a |
| 2444 | * set of child activities, such as ActivityGroup. The same guarantees and restrictions apply |
| 2445 | * as for {@link #onRetainNonConfigurationInstance()}. The default implementation returns null. |
| 2446 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2447 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2448 | HashMap<String,Object> onRetainNonConfigurationChildInstances() { |
| 2449 | return null; |
| 2450 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2451 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2452 | NonConfigurationInstances retainNonConfigurationInstances() { |
| 2453 | Object activity = onRetainNonConfigurationInstance(); |
| 2454 | HashMap<String, Object> children = onRetainNonConfigurationChildInstances(); |
Adam Powell | 44ba79e | 2016-02-04 16:20:37 -0800 | [diff] [blame] | 2455 | FragmentManagerNonConfig fragments = mFragments.retainNestedNonConfig(); |
Adam Powell | cbade7f | 2016-04-15 11:14:37 -0700 | [diff] [blame] | 2456 | |
| 2457 | // We're already stopped but we've been asked to retain. |
| 2458 | // Our fragments are taken care of but we need to mark the loaders for retention. |
| 2459 | // In order to do this correctly we need to restart the loaders first before |
| 2460 | // handing them off to the next activity. |
| 2461 | mFragments.doLoaderStart(); |
| 2462 | mFragments.doLoaderStop(true); |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2463 | ArrayMap<String, LoaderManager> loaders = mFragments.retainLoaderNonConfig(); |
Adam Powell | cbade7f | 2016-04-15 11:14:37 -0700 | [diff] [blame] | 2464 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2465 | if (activity == null && children == null && fragments == null && loaders == null |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 2466 | && mVoiceInteractor == null) { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2467 | return null; |
| 2468 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2469 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2470 | NonConfigurationInstances nci = new NonConfigurationInstances(); |
| 2471 | nci.activity = activity; |
| 2472 | nci.children = children; |
| 2473 | nci.fragments = fragments; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2474 | nci.loaders = loaders; |
Dianne Hackborn | 57dd737 | 2015-07-27 18:11:14 -0700 | [diff] [blame] | 2475 | if (mVoiceInteractor != null) { |
| 2476 | mVoiceInteractor.retainInstance(); |
| 2477 | nci.voiceInteractor = mVoiceInteractor; |
| 2478 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2479 | return nci; |
| 2480 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 2481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2482 | public void onLowMemory() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2483 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onLowMemory " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2484 | mCalled = true; |
Dianne Hackborn | 9d07180 | 2010-12-08 14:49:15 -0800 | [diff] [blame] | 2485 | mFragments.dispatchLowMemory(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2486 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 2487 | |
| 2488 | public void onTrimMemory(int level) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2489 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onTrimMemory " + this + ": " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 2490 | mCalled = true; |
| 2491 | mFragments.dispatchTrimMemory(level); |
| 2492 | } |
| 2493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2494 | /** |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 2495 | * Return the FragmentManager for interacting with fragments associated |
| 2496 | * with this activity. |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 2497 | * |
| 2498 | * @deprecated Use {@link android.support.v4.app.FragmentActivity#getSupportFragmentManager()} |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 2499 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 2500 | @Deprecated |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 2501 | public FragmentManager getFragmentManager() { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2502 | return mFragments.getFragmentManager(); |
Dianne Hackborn | 9e14e9f3 | 2010-07-14 11:07:38 -0700 | [diff] [blame] | 2503 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2504 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 2505 | /** |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 2506 | * Called when a Fragment is being attached to this activity, immediately |
| 2507 | * after the call to its {@link Fragment#onAttach Fragment.onAttach()} |
| 2508 | * method and before {@link Fragment#onCreate Fragment.onCreate()}. |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 2509 | * |
| 2510 | * @deprecated Use {@link |
| 2511 | * android.support.v4.app.FragmentActivity#onAttachFragment(android.support.v4.app.Fragment)} |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 2512 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 2513 | @Deprecated |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 2514 | public void onAttachFragment(Fragment fragment) { |
| 2515 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2516 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 2517 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2518 | * Wrapper around |
| 2519 | * {@link ContentResolver#query(android.net.Uri , String[], String, String[], String)} |
| 2520 | * that gives the resulting {@link Cursor} to call |
| 2521 | * {@link #startManagingCursor} so that the activity will manage its |
| 2522 | * lifecycle for you. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2523 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2524 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 2525 | * or later, consider instead using {@link LoaderManager} instead, available |
| 2526 | * via {@link #getLoaderManager()}.</em> |
| 2527 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 2528 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on a cursor obtained using |
| 2529 | * this method, because the activity will do that for you at the appropriate time. However, if |
| 2530 | * you call {@link #stopManagingCursor} on a cursor from a managed query, the system <em>will |
| 2531 | * not</em> automatically close the cursor and, in that case, you must call |
| 2532 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2533 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2534 | * @param uri The URI of the content provider to query. |
| 2535 | * @param projection List of columns to return. |
| 2536 | * @param selection SQL WHERE clause. |
| 2537 | * @param sortOrder SQL ORDER BY clause. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2538 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2539 | * @return The Cursor that was returned by query(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2540 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2541 | * @see ContentResolver#query(android.net.Uri , String[], String, String[], String) |
| 2542 | * @see #startManagingCursor |
| 2543 | * @hide |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2544 | * |
| 2545 | * @deprecated Use {@link CursorLoader} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2546 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2547 | @Deprecated |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 2548 | @UnsupportedAppUsage |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2549 | public final Cursor managedQuery(Uri uri, String[] projection, String selection, |
| 2550 | String sortOrder) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2551 | Cursor c = getContentResolver().query(uri, projection, selection, null, sortOrder); |
| 2552 | if (c != null) { |
| 2553 | startManagingCursor(c); |
| 2554 | } |
| 2555 | return c; |
| 2556 | } |
| 2557 | |
| 2558 | /** |
| 2559 | * Wrapper around |
| 2560 | * {@link ContentResolver#query(android.net.Uri , String[], String, String[], String)} |
| 2561 | * that gives the resulting {@link Cursor} to call |
| 2562 | * {@link #startManagingCursor} so that the activity will manage its |
| 2563 | * lifecycle for you. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2564 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2565 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 2566 | * or later, consider instead using {@link LoaderManager} instead, available |
| 2567 | * via {@link #getLoaderManager()}.</em> |
| 2568 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 2569 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on a cursor obtained using |
| 2570 | * this method, because the activity will do that for you at the appropriate time. However, if |
| 2571 | * you call {@link #stopManagingCursor} on a cursor from a managed query, the system <em>will |
| 2572 | * not</em> automatically close the cursor and, in that case, you must call |
| 2573 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2574 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2575 | * @param uri The URI of the content provider to query. |
| 2576 | * @param projection List of columns to return. |
| 2577 | * @param selection SQL WHERE clause. |
| 2578 | * @param selectionArgs The arguments to selection, if any ?s are pesent |
| 2579 | * @param sortOrder SQL ORDER BY clause. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2580 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2581 | * @return The Cursor that was returned by query(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2582 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2583 | * @see ContentResolver#query(android.net.Uri , String[], String, String[], String) |
| 2584 | * @see #startManagingCursor |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2585 | * |
| 2586 | * @deprecated Use {@link CursorLoader} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2587 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2588 | @Deprecated |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2589 | public final Cursor managedQuery(Uri uri, String[] projection, String selection, |
| 2590 | String[] selectionArgs, String sortOrder) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2591 | Cursor c = getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder); |
| 2592 | if (c != null) { |
| 2593 | startManagingCursor(c); |
| 2594 | } |
| 2595 | return c; |
| 2596 | } |
| 2597 | |
| 2598 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2599 | * This method allows the activity to take care of managing the given |
| 2600 | * {@link Cursor}'s lifecycle for you based on the activity's lifecycle. |
| 2601 | * That is, when the activity is stopped it will automatically call |
| 2602 | * {@link Cursor#deactivate} on the given Cursor, and when it is later restarted |
| 2603 | * it will call {@link Cursor#requery} for you. When the activity is |
| 2604 | * destroyed, all managed Cursors will be closed automatically. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2605 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2606 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 2607 | * or later, consider instead using {@link LoaderManager} instead, available |
| 2608 | * via {@link #getLoaderManager()}.</em> |
| 2609 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 2610 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on cursor obtained from |
| 2611 | * {@link #managedQuery}, because the activity will do that for you at the appropriate time. |
| 2612 | * However, if you call {@link #stopManagingCursor} on a cursor from a managed query, the system |
| 2613 | * <em>will not</em> automatically close the cursor and, in that case, you must call |
| 2614 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2615 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2616 | * @param c The Cursor to be managed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2617 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2618 | * @see #managedQuery(android.net.Uri , String[], String, String[], String) |
| 2619 | * @see #stopManagingCursor |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 2620 | * |
| 2621 | * @deprecated Use the new {@link android.content.CursorLoader} class with |
| 2622 | * {@link LoaderManager} instead; this is also |
| 2623 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2624 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2625 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2626 | public void startManagingCursor(Cursor c) { |
| 2627 | synchronized (mManagedCursors) { |
| 2628 | mManagedCursors.add(new ManagedCursor(c)); |
| 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | /** |
| 2633 | * Given a Cursor that was previously given to |
| 2634 | * {@link #startManagingCursor}, stop the activity's management of that |
| 2635 | * cursor. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2636 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 2637 | * <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] | 2638 | * 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] | 2639 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2640 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2641 | * @param c The Cursor that was being managed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2642 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2643 | * @see #startManagingCursor |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 2644 | * |
| 2645 | * @deprecated Use the new {@link android.content.CursorLoader} class with |
| 2646 | * {@link LoaderManager} instead; this is also |
| 2647 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2648 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2649 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2650 | public void stopManagingCursor(Cursor c) { |
| 2651 | synchronized (mManagedCursors) { |
| 2652 | final int N = mManagedCursors.size(); |
| 2653 | for (int i=0; i<N; i++) { |
| 2654 | ManagedCursor mc = mManagedCursors.get(i); |
| 2655 | if (mc.mCursor == c) { |
| 2656 | mManagedCursors.remove(i); |
| 2657 | break; |
| 2658 | } |
| 2659 | } |
| 2660 | } |
| 2661 | } |
| 2662 | |
| 2663 | /** |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 2664 | * @deprecated As of {@link android.os.Build.VERSION_CODES#GINGERBREAD} |
| 2665 | * this is a no-op. |
Dianne Hackborn | 4f3867e | 2010-12-14 22:09:51 -0800 | [diff] [blame] | 2666 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2667 | */ |
Dianne Hackborn | d3efa39 | 2010-09-01 17:34:12 -0700 | [diff] [blame] | 2668 | @Deprecated |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 2669 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2670 | public void setPersistent(boolean isPersistent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | /** |
Alan Viverette | db7423c | 2017-03-31 13:13:58 -0400 | [diff] [blame] | 2674 | * Finds a view that was identified by the {@code android:id} XML attribute |
| 2675 | * that was processed in {@link #onCreate}. |
| 2676 | * <p> |
| 2677 | * <strong>Note:</strong> In most cases -- depending on compiler support -- |
| 2678 | * the resulting view is automatically cast to the target class type. If |
| 2679 | * the target class type is unconstrained, an explicit cast may be |
| 2680 | * necessary. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2681 | * |
Alan Viverette | db7423c | 2017-03-31 13:13:58 -0400 | [diff] [blame] | 2682 | * @param id the ID to search for |
| 2683 | * @return a view with given ID if found, or {@code null} otherwise |
| 2684 | * @see View#findViewById(int) |
Chris Craik | 6faa9e5 | 2018-01-11 10:46:10 -0800 | [diff] [blame] | 2685 | * @see Activity#requireViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2686 | */ |
Scott Kennedy | c051955 | 2015-02-11 15:33:10 -0800 | [diff] [blame] | 2687 | @Nullable |
Alan Viverette | db7423c | 2017-03-31 13:13:58 -0400 | [diff] [blame] | 2688 | public <T extends View> T findViewById(@IdRes int id) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2689 | return getWindow().findViewById(id); |
| 2690 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2691 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2692 | /** |
Chris Craik | 6faa9e5 | 2018-01-11 10:46:10 -0800 | [diff] [blame] | 2693 | * Finds a view that was identified by the {@code android:id} XML attribute that was processed |
| 2694 | * in {@link #onCreate}, or throws an IllegalArgumentException if the ID is invalid, or there is |
| 2695 | * no matching view in the hierarchy. |
| 2696 | * <p> |
| 2697 | * <strong>Note:</strong> In most cases -- depending on compiler support -- |
| 2698 | * the resulting view is automatically cast to the target class type. If |
| 2699 | * the target class type is unconstrained, an explicit cast may be |
| 2700 | * necessary. |
| 2701 | * |
| 2702 | * @param id the ID to search for |
| 2703 | * @return a view with given ID |
| 2704 | * @see View#requireViewById(int) |
| 2705 | * @see Activity#findViewById(int) |
| 2706 | */ |
| 2707 | @NonNull |
| 2708 | public final <T extends View> T requireViewById(@IdRes int id) { |
| 2709 | T view = findViewById(id); |
| 2710 | if (view == null) { |
| 2711 | throw new IllegalArgumentException("ID does not reference a View inside this Activity"); |
| 2712 | } |
| 2713 | return view; |
| 2714 | } |
| 2715 | |
| 2716 | /** |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2717 | * Retrieve a reference to this activity's ActionBar. |
Adam Powell | 42c0fe8 | 2010-08-10 16:36:56 -0700 | [diff] [blame] | 2718 | * |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2719 | * @return The Activity's ActionBar, or null if it does not have one. |
| 2720 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2721 | @Nullable |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2722 | public ActionBar getActionBar() { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2723 | initWindowDecorActionBar(); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2724 | return mActionBar; |
| 2725 | } |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2726 | |
| 2727 | /** |
| 2728 | * Set a {@link android.widget.Toolbar Toolbar} to act as the {@link ActionBar} for this |
| 2729 | * Activity window. |
| 2730 | * |
| 2731 | * <p>When set to a non-null value the {@link #getActionBar()} method will return |
| 2732 | * an {@link ActionBar} object that can be used to control the given toolbar as if it were |
| 2733 | * a traditional window decor action bar. The toolbar's menu will be populated with the |
| 2734 | * Activity's options menu and the navigation button will be wired through the standard |
| 2735 | * {@link android.R.id#home home} menu select action.</p> |
| 2736 | * |
| 2737 | * <p>In order to use a Toolbar within the Activity's window content the application |
| 2738 | * must not request the window feature {@link Window#FEATURE_ACTION_BAR FEATURE_ACTION_BAR}.</p> |
| 2739 | * |
Chris Banes | c7d6c32 | 2016-01-27 14:09:16 +0000 | [diff] [blame] | 2740 | * @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] | 2741 | */ |
Adam Powell | 3778014 | 2014-06-01 13:31:00 -0700 | [diff] [blame] | 2742 | public void setActionBar(@Nullable Toolbar toolbar) { |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 2743 | final ActionBar ab = getActionBar(); |
| 2744 | if (ab instanceof WindowDecorActionBar) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2745 | throw new IllegalStateException("This Activity already has an action bar supplied " + |
| 2746 | "by the window decor. Do not request Window.FEATURE_ACTION_BAR and set " + |
| 2747 | "android:windowActionBar to false in your theme to use a Toolbar instead."); |
| 2748 | } |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 2749 | |
| 2750 | // If we reach here then we're setting a new action bar |
| 2751 | // 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] | 2752 | mMenuInflater = null; |
| 2753 | |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 2754 | // If we have an action bar currently, destroy it |
| 2755 | if (ab != null) { |
| 2756 | ab.onDestroy(); |
| 2757 | } |
| 2758 | |
Chris Banes | c7d6c32 | 2016-01-27 14:09:16 +0000 | [diff] [blame] | 2759 | if (toolbar != null) { |
| 2760 | final ToolbarActionBar tbab = new ToolbarActionBar(toolbar, getTitle(), this); |
| 2761 | mActionBar = tbab; |
| 2762 | mWindow.setCallback(tbab.getWrappedWindowCallback()); |
| 2763 | } else { |
| 2764 | mActionBar = null; |
| 2765 | // Re-set the original window callback since we may have already set a Toolbar wrapper |
| 2766 | mWindow.setCallback(this); |
| 2767 | } |
| 2768 | |
| 2769 | invalidateOptionsMenu(); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2770 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2771 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2772 | /** |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2773 | * Creates a new ActionBar, locates the inflated ActionBarView, |
| 2774 | * initializes the ActionBar with the view, and sets mActionBar. |
| 2775 | */ |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2776 | private void initWindowDecorActionBar() { |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 2777 | Window window = getWindow(); |
Adam Powell | a593d98 | 2011-05-13 14:09:54 -0700 | [diff] [blame] | 2778 | |
| 2779 | // Initializing the window decor can change window feature flags. |
| 2780 | // Make sure that we have the correct set before performing the test below. |
| 2781 | window.getDecorView(); |
| 2782 | |
Adam Powell | 9b4c804 | 2010-08-10 15:36:44 -0700 | [diff] [blame] | 2783 | if (isChild() || !window.hasFeature(Window.FEATURE_ACTION_BAR) || mActionBar != null) { |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2784 | return; |
| 2785 | } |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2786 | |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2787 | mActionBar = new WindowDecorActionBar(this); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 2788 | mActionBar.setDefaultDisplayHomeAsUpEnabled(mEnableDefaultActionBarUp); |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2789 | |
| 2790 | mWindow.setDefaultIcon(mActivityInfo.getIconResource()); |
| 2791 | mWindow.setDefaultLogo(mActivityInfo.getLogoResource()); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2792 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2793 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2794 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2795 | * Set the activity content from a layout resource. The resource will be |
| 2796 | * inflated, adding all top-level views to the activity. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 2797 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2798 | * @param layoutResID Resource ID to be inflated. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2799 | * |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 2800 | * @see #setContentView(android.view.View) |
| 2801 | * @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2802 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 2803 | public void setContentView(@LayoutRes int layoutResID) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2804 | getWindow().setContentView(layoutResID); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2805 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | /** |
| 2809 | * Set the activity content to an explicit view. This view is placed |
| 2810 | * 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] | 2811 | * view hierarchy. When calling this method, the layout parameters of the |
| 2812 | * specified view are ignored. Both the width and the height of the view are |
| 2813 | * set by default to {@link ViewGroup.LayoutParams#MATCH_PARENT}. To use |
| 2814 | * your own layout parameters, invoke |
| 2815 | * {@link #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)} |
| 2816 | * instead. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2817 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2818 | * @param view The desired content to display. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 2819 | * |
| 2820 | * @see #setContentView(int) |
| 2821 | * @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2822 | */ |
| 2823 | public void setContentView(View view) { |
| 2824 | getWindow().setContentView(view); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2825 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2826 | } |
| 2827 | |
| 2828 | /** |
| 2829 | * Set the activity content to an explicit view. This view is placed |
| 2830 | * 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] | 2831 | * view hierarchy. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2832 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2833 | * @param view The desired content to display. |
| 2834 | * @param params Layout parameters for the view. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 2835 | * |
| 2836 | * @see #setContentView(android.view.View) |
| 2837 | * @see #setContentView(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2838 | */ |
| 2839 | public void setContentView(View view, ViewGroup.LayoutParams params) { |
| 2840 | getWindow().setContentView(view, params); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2841 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2842 | } |
| 2843 | |
| 2844 | /** |
| 2845 | * Add an additional content view to the activity. Added after any existing |
| 2846 | * ones in the activity -- existing views are NOT removed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2847 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2848 | * @param view The desired content to display. |
| 2849 | * @param params Layout parameters for the view. |
| 2850 | */ |
| 2851 | public void addContentView(View view, ViewGroup.LayoutParams params) { |
| 2852 | getWindow().addContentView(view, params); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2853 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | /** |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2857 | * Retrieve the {@link TransitionManager} responsible for default transitions in this window. |
| 2858 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 2859 | * |
| 2860 | * <p>This method will return non-null after content has been initialized (e.g. by using |
| 2861 | * {@link #setContentView}) if {@link Window#FEATURE_CONTENT_TRANSITIONS} has been granted.</p> |
| 2862 | * |
| 2863 | * @return This window's content TransitionManager or null if none is set. |
| 2864 | */ |
| 2865 | public TransitionManager getContentTransitionManager() { |
| 2866 | return getWindow().getTransitionManager(); |
| 2867 | } |
| 2868 | |
| 2869 | /** |
| 2870 | * Set the {@link TransitionManager} to use for default transitions in this window. |
| 2871 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 2872 | * |
| 2873 | * @param tm The TransitionManager to use for scene changes. |
| 2874 | */ |
| 2875 | public void setContentTransitionManager(TransitionManager tm) { |
| 2876 | getWindow().setTransitionManager(tm); |
| 2877 | } |
| 2878 | |
| 2879 | /** |
| 2880 | * Retrieve the {@link Scene} representing this window's current content. |
| 2881 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 2882 | * |
| 2883 | * <p>This method will return null if the current content is not represented by a Scene.</p> |
| 2884 | * |
| 2885 | * @return Current Scene being shown or null |
| 2886 | */ |
| 2887 | public Scene getContentScene() { |
| 2888 | return getWindow().getContentScene(); |
| 2889 | } |
| 2890 | |
| 2891 | /** |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 2892 | * Sets whether this activity is finished when touched outside its window's |
| 2893 | * bounds. |
| 2894 | */ |
| 2895 | public void setFinishOnTouchOutside(boolean finish) { |
| 2896 | mWindow.setCloseOnTouchOutside(finish); |
| 2897 | } |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2898 | |
| 2899 | /** @hide */ |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 2900 | @IntDef(prefix = { "DEFAULT_KEYS_" }, value = { |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2901 | DEFAULT_KEYS_DISABLE, |
| 2902 | DEFAULT_KEYS_DIALER, |
| 2903 | DEFAULT_KEYS_SHORTCUT, |
| 2904 | DEFAULT_KEYS_SEARCH_LOCAL, |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 2905 | DEFAULT_KEYS_SEARCH_GLOBAL |
| 2906 | }) |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2907 | @Retention(RetentionPolicy.SOURCE) |
| 2908 | @interface DefaultKeyMode {} |
| 2909 | |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 2910 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2911 | * Use with {@link #setDefaultKeyMode} to turn off default handling of |
| 2912 | * keys. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2913 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2914 | * @see #setDefaultKeyMode |
| 2915 | */ |
| 2916 | static public final int DEFAULT_KEYS_DISABLE = 0; |
| 2917 | /** |
| 2918 | * Use with {@link #setDefaultKeyMode} to launch the dialer during default |
| 2919 | * key handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2920 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2921 | * @see #setDefaultKeyMode |
| 2922 | */ |
| 2923 | static public final int DEFAULT_KEYS_DIALER = 1; |
| 2924 | /** |
| 2925 | * Use with {@link #setDefaultKeyMode} to execute a menu shortcut in |
| 2926 | * default key handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2927 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2928 | * <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] | 2929 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2930 | * @see #setDefaultKeyMode |
| 2931 | */ |
| 2932 | static public final int DEFAULT_KEYS_SHORTCUT = 2; |
| 2933 | /** |
| 2934 | * Use with {@link #setDefaultKeyMode} to specify that unhandled keystrokes |
| 2935 | * will start an application-defined search. (If the application or activity does not |
| 2936 | * actually define a search, the the keys will be ignored.) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2937 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2938 | * <p>See {@link android.app.SearchManager android.app.SearchManager} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2939 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2940 | * @see #setDefaultKeyMode |
| 2941 | */ |
| 2942 | static public final int DEFAULT_KEYS_SEARCH_LOCAL = 3; |
| 2943 | |
| 2944 | /** |
| 2945 | * Use with {@link #setDefaultKeyMode} to specify that unhandled keystrokes |
| 2946 | * will start a global search (typically web search, but some platforms may define alternate |
| 2947 | * methods for global search) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2948 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2949 | * <p>See {@link android.app.SearchManager android.app.SearchManager} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2950 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2951 | * @see #setDefaultKeyMode |
| 2952 | */ |
| 2953 | static public final int DEFAULT_KEYS_SEARCH_GLOBAL = 4; |
| 2954 | |
| 2955 | /** |
| 2956 | * Select the default key handling for this activity. This controls what |
| 2957 | * will happen to key events that are not otherwise handled. The default |
| 2958 | * mode ({@link #DEFAULT_KEYS_DISABLE}) will simply drop them on the |
| 2959 | * floor. Other modes allow you to launch the dialer |
| 2960 | * ({@link #DEFAULT_KEYS_DIALER}), execute a shortcut in your options |
| 2961 | * menu without requiring the menu key be held down |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2962 | * ({@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] | 2963 | * and {@link #DEFAULT_KEYS_SEARCH_GLOBAL}). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2964 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | * <p>Note that the mode selected here does not impact the default |
| 2966 | * handling of system keys, such as the "back" and "menu" keys, and your |
| 2967 | * activity and its views always get a first chance to receive and handle |
| 2968 | * all application keys. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2969 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2970 | * @param mode The desired default key mode constant. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2971 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2972 | * @see #onKeyDown |
| 2973 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2974 | public final void setDefaultKeyMode(@DefaultKeyMode int mode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | mDefaultKeyMode = mode; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2977 | // Some modes use a SpannableStringBuilder to track & dispatch input events |
| 2978 | // This list must remain in sync with the switch in onKeyDown() |
| 2979 | switch (mode) { |
| 2980 | case DEFAULT_KEYS_DISABLE: |
| 2981 | case DEFAULT_KEYS_SHORTCUT: |
| 2982 | mDefaultKeySsb = null; // not used in these modes |
| 2983 | break; |
| 2984 | case DEFAULT_KEYS_DIALER: |
| 2985 | case DEFAULT_KEYS_SEARCH_LOCAL: |
| 2986 | case DEFAULT_KEYS_SEARCH_GLOBAL: |
| 2987 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 2988 | Selection.setSelection(mDefaultKeySsb,0); |
| 2989 | break; |
| 2990 | default: |
| 2991 | throw new IllegalArgumentException(); |
| 2992 | } |
| 2993 | } |
| 2994 | |
| 2995 | /** |
| 2996 | * 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] | 2997 | * 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] | 2998 | * is inside a TextView will not trigger the event (unless it is a navigation |
| 2999 | * to another object) because TextView handles its own key presses. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3000 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3001 | * <p>If the focused view didn't want this event, this method is called. |
| 3002 | * |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3003 | * <p>The default implementation takes care of {@link KeyEvent#KEYCODE_BACK} |
| 3004 | * by calling {@link #onBackPressed()}, though the behavior varies based |
| 3005 | * on the application compatibility mode: for |
| 3006 | * {@link android.os.Build.VERSION_CODES#ECLAIR} or later applications, |
| 3007 | * it will set up the dispatch to call {@link #onKeyUp} where the action |
| 3008 | * will be performed; for earlier applications, it will perform the |
| 3009 | * action immediately in on-down, as those versions of the platform |
| 3010 | * behaved. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3011 | * |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3012 | * <p>Other additional default key handling may be performed |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3013 | * if configured with {@link #setDefaultKeyMode}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3014 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3015 | * @return Return <code>true</code> to prevent this event from being propagated |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3016 | * 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] | 3017 | * this event and it should continue to be propagated. |
| 3018 | * @see #onKeyUp |
| 3019 | * @see android.view.KeyEvent |
| 3020 | */ |
| 3021 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3022 | if (keyCode == KeyEvent.KEYCODE_BACK) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3023 | if (getApplicationInfo().targetSdkVersion |
| 3024 | >= Build.VERSION_CODES.ECLAIR) { |
| 3025 | event.startTracking(); |
| 3026 | } else { |
| 3027 | onBackPressed(); |
| 3028 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3029 | return true; |
| 3030 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3031 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3032 | if (mDefaultKeyMode == DEFAULT_KEYS_DISABLE) { |
| 3033 | return false; |
| 3034 | } else if (mDefaultKeyMode == DEFAULT_KEYS_SHORTCUT) { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 3035 | Window w = getWindow(); |
| 3036 | if (w.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 3037 | w.performPanelShortcut(Window.FEATURE_OPTIONS_PANEL, keyCode, event, |
| 3038 | Menu.FLAG_ALWAYS_PERFORM_CLOSE)) { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3039 | return true; |
| 3040 | } |
| 3041 | return false; |
Evan Rosky | c4620378 | 2017-02-17 13:11:53 -0800 | [diff] [blame] | 3042 | } else if (keyCode == KeyEvent.KEYCODE_TAB) { |
| 3043 | // Don't consume TAB here since it's used for navigation. Arrow keys |
| 3044 | // aren't considered "typing keys" so they already won't get consumed. |
| 3045 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3046 | } else { |
| 3047 | // Common code for DEFAULT_KEYS_DIALER & DEFAULT_KEYS_SEARCH_* |
| 3048 | boolean clearSpannable = false; |
| 3049 | boolean handled; |
| 3050 | if ((event.getRepeatCount() != 0) || event.isSystem()) { |
| 3051 | clearSpannable = true; |
| 3052 | handled = false; |
| 3053 | } else { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3054 | handled = TextKeyListener.getInstance().onKeyDown( |
| 3055 | null, mDefaultKeySsb, keyCode, event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3056 | if (handled && mDefaultKeySsb.length() > 0) { |
| 3057 | // something useable has been typed - dispatch it now. |
| 3058 | |
| 3059 | final String str = mDefaultKeySsb.toString(); |
| 3060 | clearSpannable = true; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3062 | switch (mDefaultKeyMode) { |
| 3063 | case DEFAULT_KEYS_DIALER: |
| 3064 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + str)); |
| 3065 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3066 | startActivity(intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3067 | break; |
| 3068 | case DEFAULT_KEYS_SEARCH_LOCAL: |
| 3069 | startSearch(str, false, null, false); |
| 3070 | break; |
| 3071 | case DEFAULT_KEYS_SEARCH_GLOBAL: |
| 3072 | startSearch(str, false, null, true); |
| 3073 | break; |
| 3074 | } |
| 3075 | } |
| 3076 | } |
| 3077 | if (clearSpannable) { |
| 3078 | mDefaultKeySsb.clear(); |
| 3079 | mDefaultKeySsb.clearSpans(); |
| 3080 | Selection.setSelection(mDefaultKeySsb,0); |
| 3081 | } |
| 3082 | return handled; |
| 3083 | } |
| 3084 | } |
| 3085 | |
| 3086 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3087 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 3088 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 3089 | * the event). |
| 3090 | */ |
| 3091 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 3092 | return false; |
| 3093 | } |
| 3094 | |
| 3095 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3096 | * 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] | 3097 | * 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] | 3098 | * is inside a TextView will not trigger the event (unless it is a navigation |
| 3099 | * to another object) because TextView handles its own key presses. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3100 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3101 | * <p>The default implementation handles KEYCODE_BACK to stop the activity |
| 3102 | * and go back. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3103 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3104 | * @return Return <code>true</code> to prevent this event from being propagated |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3105 | * further, or <code>false</code> to indicate that you have not handled |
| 3106 | * this event and it should continue to be propagated. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3107 | * @see #onKeyDown |
| 3108 | * @see KeyEvent |
| 3109 | */ |
| 3110 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3111 | if (getApplicationInfo().targetSdkVersion |
| 3112 | >= Build.VERSION_CODES.ECLAIR) { |
| 3113 | if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() |
| 3114 | && !event.isCanceled()) { |
| 3115 | onBackPressed(); |
| 3116 | return true; |
| 3117 | } |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3118 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3119 | return false; |
| 3120 | } |
| 3121 | |
| 3122 | /** |
| 3123 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 3124 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 3125 | * the event). |
| 3126 | */ |
| 3127 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 3128 | return false; |
| 3129 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3131 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3132 | * Called when the activity has detected the user's press of the back |
| 3133 | * key. The default implementation simply finishes the current activity, |
| 3134 | * but you can override this to do whatever you want. |
| 3135 | */ |
| 3136 | public void onBackPressed() { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3137 | if (mActionBar != null && mActionBar.collapseActionView()) { |
| 3138 | return; |
| 3139 | } |
| 3140 | |
George Mount | 27b0dc0 | 2017-02-21 10:24:09 -0800 | [diff] [blame] | 3141 | FragmentManager fragmentManager = mFragments.getFragmentManager(); |
| 3142 | |
| 3143 | if (fragmentManager.isStateSaved() || !fragmentManager.popBackStackImmediate()) { |
Craig Mautner | 73f843d | 2014-05-19 09:42:28 -0700 | [diff] [blame] | 3144 | finishAfterTransition(); |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 3145 | } |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3146 | } |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 3147 | |
| 3148 | /** |
| 3149 | * Called when a key shortcut event is not handled by any of the views in the Activity. |
| 3150 | * Override this method to implement global key shortcuts for the Activity. |
| 3151 | * Key shortcuts can also be implemented by setting the |
| 3152 | * {@link MenuItem#setShortcut(char, char) shortcut} property of menu items. |
| 3153 | * |
| 3154 | * @param keyCode The value in event.getKeyCode(). |
| 3155 | * @param event Description of the key event. |
| 3156 | * @return True if the key shortcut was handled. |
| 3157 | */ |
| 3158 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
Abodunrinwa Toki | a04b7ad | 2015-06-30 17:44:04 -0700 | [diff] [blame] | 3159 | // Let the Action Bar have a chance at handling the shortcut. |
| 3160 | ActionBar actionBar = getActionBar(); |
| 3161 | return (actionBar != null && actionBar.onKeyShortcut(keyCode, event)); |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 3162 | } |
| 3163 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3164 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3165 | * Called when a touch screen event was not handled by any of the views |
| 3166 | * under it. This is most useful to process touch events that happen |
| 3167 | * outside of your window bounds, where there is no view to receive it. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3168 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3169 | * @param event The touch screen event being processed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3170 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3171 | * @return Return true if you have consumed the event, false if you haven't. |
| 3172 | * The default implementation always returns false. |
| 3173 | */ |
| 3174 | public boolean onTouchEvent(MotionEvent event) { |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 3175 | if (mWindow.shouldCloseOnTouch(this, event)) { |
| 3176 | finish(); |
| 3177 | return true; |
| 3178 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3180 | return false; |
| 3181 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3183 | /** |
| 3184 | * Called when the trackball was moved and not handled by any of the |
| 3185 | * views inside of the activity. So, for example, if the trackball moves |
| 3186 | * while focus is on a button, you will receive a call here because |
| 3187 | * buttons do not normally do anything with trackball events. The call |
| 3188 | * here happens <em>before</em> trackball movements are converted to |
| 3189 | * DPAD key events, which then get sent back to the view hierarchy, and |
| 3190 | * will be processed at the point for things like focus navigation. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3191 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3192 | * @param event The trackball event being processed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3193 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3194 | * @return Return true if you have consumed the event, false if you haven't. |
| 3195 | * The default implementation always returns false. |
| 3196 | */ |
| 3197 | public boolean onTrackballEvent(MotionEvent event) { |
| 3198 | return false; |
| 3199 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3200 | |
| 3201 | /** |
| 3202 | * Called when a generic motion event was not handled by any of the |
| 3203 | * views inside of the activity. |
| 3204 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3205 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 3206 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3207 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 3208 | * the class of input that was received. Implementations of this method |
| 3209 | * must examine the bits in the source before processing the event. |
| 3210 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3211 | * </p><p> |
| 3212 | * Generic motion events with source class |
| 3213 | * {@link android.view.InputDevice#SOURCE_CLASS_POINTER} |
| 3214 | * are delivered to the view under the pointer. All other generic motion events are |
| 3215 | * delivered to the focused view. |
| 3216 | * </p><p> |
| 3217 | * See {@link View#onGenericMotionEvent(MotionEvent)} for an example of how to |
| 3218 | * handle this event. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3219 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3220 | * |
| 3221 | * @param event The generic motion event being processed. |
| 3222 | * |
| 3223 | * @return Return true if you have consumed the event, false if you haven't. |
| 3224 | * The default implementation always returns false. |
| 3225 | */ |
| 3226 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 3227 | return false; |
| 3228 | } |
| 3229 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3230 | /** |
| 3231 | * Called whenever a key, touch, or trackball event is dispatched to the |
| 3232 | * activity. Implement this method if you wish to know that the user has |
| 3233 | * interacted with the device in some way while your activity is running. |
| 3234 | * This callback and {@link #onUserLeaveHint} are intended to help |
| 3235 | * activities manage status bar notifications intelligently; specifically, |
| 3236 | * for helping activities determine the proper time to cancel a notfication. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3237 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3238 | * <p>All calls to your activity's {@link #onUserLeaveHint} callback will |
| 3239 | * be accompanied by calls to {@link #onUserInteraction}. This |
| 3240 | * ensures that your activity will be told of relevant user activity such |
| 3241 | * as pulling down the notification pane and touching an item there. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3242 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3243 | * <p>Note that this callback will be invoked for the touch down action |
| 3244 | * that begins a touch gesture, but may not be invoked for the touch-moved |
| 3245 | * and touch-up actions that follow. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3246 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3247 | * @see #onUserLeaveHint() |
| 3248 | */ |
| 3249 | public void onUserInteraction() { |
| 3250 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3251 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3252 | public void onWindowAttributesChanged(WindowManager.LayoutParams params) { |
| 3253 | // Update window manager if: we have a view, that view is |
| 3254 | // attached to its parent (which will be a RootView), and |
| 3255 | // this activity is not embedded. |
| 3256 | if (mParent == null) { |
| 3257 | View decor = mDecor; |
| 3258 | if (decor != null && decor.getParent() != null) { |
| 3259 | getWindowManager().updateViewLayout(decor, params); |
| 3260 | } |
| 3261 | } |
| 3262 | } |
| 3263 | |
| 3264 | public void onContentChanged() { |
| 3265 | } |
| 3266 | |
| 3267 | /** |
| 3268 | * Called when the current {@link Window} of the activity gains or loses |
| 3269 | * focus. This is the best indicator of whether this activity is visible |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3270 | * to the user. The default implementation clears the key tracking |
| 3271 | * state, so should always be called. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3272 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3273 | * <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] | 3274 | * is managed independently of activity lifecycles. As such, while focus |
| 3275 | * changes will generally have some relation to lifecycle changes (an |
| 3276 | * activity that is stopped will not generally get window focus), you |
| 3277 | * should not rely on any particular order between the callbacks here and |
| 3278 | * those in the other lifecycle methods such as {@link #onResume}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3279 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3280 | * <p>As a general rule, however, a resumed activity will have window |
| 3281 | * focus... unless it has displayed other dialogs or popups that take |
| 3282 | * input focus, in which case the activity itself will not have focus |
| 3283 | * when the other windows have it. Likewise, the system may display |
| 3284 | * system-level windows (such as the status bar notification panel or |
| 3285 | * a system alert) which will temporarily take window input focus without |
| 3286 | * pausing the foreground activity. |
| 3287 | * |
| 3288 | * @param hasFocus Whether the window of this activity has focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3289 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3290 | * @see #hasWindowFocus() |
| 3291 | * @see #onResume |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3292 | * @see View#onWindowFocusChanged(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3293 | */ |
| 3294 | public void onWindowFocusChanged(boolean hasFocus) { |
| 3295 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3296 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3297 | /** |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3298 | * Called when the main window associated with the activity has been |
| 3299 | * attached to the window manager. |
| 3300 | * See {@link View#onAttachedToWindow() View.onAttachedToWindow()} |
| 3301 | * for more information. |
| 3302 | * @see View#onAttachedToWindow |
| 3303 | */ |
| 3304 | public void onAttachedToWindow() { |
| 3305 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3306 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3307 | /** |
| 3308 | * Called when the main window associated with the activity has been |
| 3309 | * detached from the window manager. |
| 3310 | * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()} |
| 3311 | * for more information. |
| 3312 | * @see View#onDetachedFromWindow |
| 3313 | */ |
| 3314 | public void onDetachedFromWindow() { |
| 3315 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3316 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3317 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3318 | * Returns true if this activity's <em>main</em> window currently has window focus. |
| 3319 | * Note that this is not the same as the view itself having focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3320 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3321 | * @return True if this activity's main window currently has window focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3322 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3323 | * @see #onWindowAttributesChanged(android.view.WindowManager.LayoutParams) |
| 3324 | */ |
| 3325 | public boolean hasWindowFocus() { |
| 3326 | Window w = getWindow(); |
| 3327 | if (w != null) { |
| 3328 | View d = w.getDecorView(); |
| 3329 | if (d != null) { |
| 3330 | return d.hasWindowFocus(); |
| 3331 | } |
| 3332 | } |
| 3333 | return false; |
| 3334 | } |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3335 | |
| 3336 | /** |
| 3337 | * Called when the main window associated with the activity has been dismissed. |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 3338 | * @hide |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3339 | */ |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 3340 | @Override |
Ned Burns | 7d6cb91 | 2016-12-02 17:25:33 -0500 | [diff] [blame] | 3341 | public void onWindowDismissed(boolean finishTask, boolean suppressWindowTransition) { |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 3342 | finish(finishTask ? FINISH_TASK_WITH_ACTIVITY : DONT_FINISH_TASK_WITH_ACTIVITY); |
Ned Burns | 7d6cb91 | 2016-12-02 17:25:33 -0500 | [diff] [blame] | 3343 | if (suppressWindowTransition) { |
| 3344 | overridePendingTransition(0, 0); |
| 3345 | } |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3346 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3347 | |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3348 | |
Skuhne | ce2faa5 | 2015-08-11 10:36:38 -0700 | [diff] [blame] | 3349 | /** |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 3350 | * Moves the activity from {@link WindowConfiguration#WINDOWING_MODE_FREEFORM} windowing mode to |
| 3351 | * {@link WindowConfiguration#WINDOWING_MODE_FULLSCREEN}. |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3352 | * |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3353 | * @hide |
| 3354 | */ |
| 3355 | @Override |
Filip Gruszczynski | 411c06f | 2016-01-07 09:44:44 -0800 | [diff] [blame] | 3356 | public void exitFreeformMode() throws RemoteException { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3357 | ActivityManager.getService().exitFreeformMode(mToken); |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3358 | } |
| 3359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | /** |
Jaewan Kim | d98dcab | 2016-05-03 02:52:18 +0900 | [diff] [blame] | 3361 | * Puts the activity in picture-in-picture mode if the activity supports. |
| 3362 | * @see android.R.attr#supportsPictureInPicture |
| 3363 | * @hide |
| 3364 | */ |
| 3365 | @Override |
| 3366 | public void enterPictureInPictureModeIfPossible() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 3367 | if (mActivityInfo.supportsPictureInPicture()) { |
Jaewan Kim | d98dcab | 2016-05-03 02:52:18 +0900 | [diff] [blame] | 3368 | enterPictureInPictureMode(); |
| 3369 | } |
| 3370 | } |
| 3371 | |
| 3372 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3373 | * Called to process key events. You can override this to intercept all |
| 3374 | * 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] | 3375 | * this implementation for key events that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3376 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3377 | * @param event The key event. |
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 | * @return boolean Return true if this event was consumed. |
| 3380 | */ |
| 3381 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 3382 | onUserInteraction(); |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3383 | |
| 3384 | // Let action bars open menus in response to the menu key prioritized over |
| 3385 | // the window handling it |
George Mount | 5beb2617 | 2015-12-15 13:36:01 -0800 | [diff] [blame] | 3386 | final int keyCode = event.getKeyCode(); |
| 3387 | if (keyCode == KeyEvent.KEYCODE_MENU && |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3388 | mActionBar != null && mActionBar.onMenuKeyEvent(event)) { |
| 3389 | return true; |
| 3390 | } |
| 3391 | |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3392 | Window win = getWindow(); |
| 3393 | if (win.superDispatchKeyEvent(event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3394 | return true; |
| 3395 | } |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3396 | View decor = mDecor; |
| 3397 | if (decor == null) decor = win.getDecorView(); |
| 3398 | return event.dispatch(this, decor != null |
| 3399 | ? decor.getKeyDispatcherState() : null, this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 3403 | * Called to process a key shortcut event. |
| 3404 | * You can override this to intercept all key shortcut events before they are |
| 3405 | * dispatched to the window. Be sure to call this implementation for key shortcut |
| 3406 | * events that should be handled normally. |
| 3407 | * |
| 3408 | * @param event The key shortcut event. |
| 3409 | * @return True if this event was consumed. |
| 3410 | */ |
| 3411 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 3412 | onUserInteraction(); |
| 3413 | if (getWindow().superDispatchKeyShortcutEvent(event)) { |
| 3414 | return true; |
| 3415 | } |
| 3416 | return onKeyShortcut(event.getKeyCode(), event); |
| 3417 | } |
| 3418 | |
| 3419 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3420 | * Called to process touch screen events. You can override this to |
| 3421 | * intercept all touch screen events before they are dispatched to the |
| 3422 | * window. Be sure to call this implementation for touch screen events |
| 3423 | * that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3424 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3425 | * @param ev The touch screen event. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3426 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3427 | * @return boolean Return true if this event was consumed. |
| 3428 | */ |
| 3429 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 3430 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 3431 | onUserInteraction(); |
| 3432 | } |
| 3433 | if (getWindow().superDispatchTouchEvent(ev)) { |
| 3434 | return true; |
| 3435 | } |
| 3436 | return onTouchEvent(ev); |
| 3437 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3439 | /** |
| 3440 | * Called to process trackball events. You can override this to |
| 3441 | * intercept all trackball events before they are dispatched to the |
| 3442 | * window. Be sure to call this implementation for trackball events |
| 3443 | * that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3444 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3445 | * @param ev The trackball event. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3446 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3447 | * @return boolean Return true if this event was consumed. |
| 3448 | */ |
| 3449 | public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 3450 | onUserInteraction(); |
| 3451 | if (getWindow().superDispatchTrackballEvent(ev)) { |
| 3452 | return true; |
| 3453 | } |
| 3454 | return onTrackballEvent(ev); |
| 3455 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3456 | |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3457 | /** |
| 3458 | * Called to process generic motion events. You can override this to |
| 3459 | * intercept all generic motion events before they are dispatched to the |
| 3460 | * window. Be sure to call this implementation for generic motion events |
| 3461 | * that should be handled normally. |
| 3462 | * |
| 3463 | * @param ev The generic motion event. |
| 3464 | * |
| 3465 | * @return boolean Return true if this event was consumed. |
| 3466 | */ |
| 3467 | public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 3468 | onUserInteraction(); |
| 3469 | if (getWindow().superDispatchGenericMotionEvent(ev)) { |
| 3470 | return true; |
| 3471 | } |
| 3472 | return onGenericMotionEvent(ev); |
| 3473 | } |
| 3474 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3475 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 3476 | event.setClassName(getClass().getName()); |
| 3477 | event.setPackageName(getPackageName()); |
| 3478 | |
| 3479 | LayoutParams params = getWindow().getAttributes(); |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 3480 | boolean isFullScreen = (params.width == LayoutParams.MATCH_PARENT) && |
| 3481 | (params.height == LayoutParams.MATCH_PARENT); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3482 | event.setFullScreen(isFullScreen); |
| 3483 | |
| 3484 | CharSequence title = getTitle(); |
| 3485 | if (!TextUtils.isEmpty(title)) { |
| 3486 | event.getText().add(title); |
| 3487 | } |
| 3488 | |
| 3489 | return true; |
| 3490 | } |
| 3491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3492 | /** |
| 3493 | * Default implementation of |
| 3494 | * {@link android.view.Window.Callback#onCreatePanelView} |
| 3495 | * for activities. This |
| 3496 | * simply returns null so that all panel sub-windows will have the default |
| 3497 | * menu behavior. |
| 3498 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3499 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3500 | public View onCreatePanelView(int featureId) { |
| 3501 | return null; |
| 3502 | } |
| 3503 | |
| 3504 | /** |
| 3505 | * Default implementation of |
| 3506 | * {@link android.view.Window.Callback#onCreatePanelMenu} |
| 3507 | * for activities. This calls through to the new |
| 3508 | * {@link #onCreateOptionsMenu} method for the |
| 3509 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} panel, |
| 3510 | * so that subclasses of Activity don't need to deal with feature codes. |
| 3511 | */ |
| 3512 | public boolean onCreatePanelMenu(int featureId, Menu menu) { |
| 3513 | if (featureId == Window.FEATURE_OPTIONS_PANEL) { |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3514 | boolean show = onCreateOptionsMenu(menu); |
| 3515 | show |= mFragments.dispatchCreateOptionsMenu(menu, getMenuInflater()); |
| 3516 | return show; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3517 | } |
| 3518 | return false; |
| 3519 | } |
| 3520 | |
| 3521 | /** |
| 3522 | * Default implementation of |
| 3523 | * {@link android.view.Window.Callback#onPreparePanel} |
| 3524 | * for activities. This |
| 3525 | * calls through to the new {@link #onPrepareOptionsMenu} method for the |
| 3526 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} |
| 3527 | * panel, so that subclasses of |
| 3528 | * Activity don't need to deal with feature codes. |
| 3529 | */ |
| 3530 | public boolean onPreparePanel(int featureId, View view, Menu menu) { |
| 3531 | if (featureId == Window.FEATURE_OPTIONS_PANEL && menu != null) { |
| 3532 | boolean goforit = onPrepareOptionsMenu(menu); |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3533 | goforit |= mFragments.dispatchPrepareOptionsMenu(menu); |
Adam Powell | ef31e7c | 2012-05-08 09:59:40 -0700 | [diff] [blame] | 3534 | return goforit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3535 | } |
| 3536 | return true; |
| 3537 | } |
| 3538 | |
| 3539 | /** |
| 3540 | * {@inheritDoc} |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3541 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | * @return The default implementation returns true. |
| 3543 | */ |
| 3544 | public boolean onMenuOpened(int featureId, Menu menu) { |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 3545 | if (featureId == Window.FEATURE_ACTION_BAR) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3546 | initWindowDecorActionBar(); |
Adam Powell | 049dd3d | 2010-12-02 13:43:59 -0800 | [diff] [blame] | 3547 | if (mActionBar != null) { |
| 3548 | mActionBar.dispatchMenuVisibilityChanged(true); |
| 3549 | } else { |
| 3550 | Log.e(TAG, "Tried to open action bar menu with no action bar"); |
| 3551 | } |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 3552 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3553 | return true; |
| 3554 | } |
| 3555 | |
| 3556 | /** |
| 3557 | * Default implementation of |
| 3558 | * {@link android.view.Window.Callback#onMenuItemSelected} |
| 3559 | * for activities. This calls through to the new |
| 3560 | * {@link #onOptionsItemSelected} method for the |
| 3561 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} |
| 3562 | * panel, so that subclasses of |
| 3563 | * Activity don't need to deal with feature codes. |
| 3564 | */ |
| 3565 | public boolean onMenuItemSelected(int featureId, MenuItem item) { |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 3566 | CharSequence titleCondensed = item.getTitleCondensed(); |
| 3567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | switch (featureId) { |
| 3569 | case Window.FEATURE_OPTIONS_PANEL: |
| 3570 | // Put event logging here so it gets called even if subclass |
| 3571 | // doesn't call through to superclass's implmeentation of each |
| 3572 | // of these methods below |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 3573 | if(titleCondensed != null) { |
| 3574 | EventLog.writeEvent(50000, 0, titleCondensed.toString()); |
| 3575 | } |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3576 | if (onOptionsItemSelected(item)) { |
| 3577 | return true; |
| 3578 | } |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 3579 | if (mFragments.dispatchOptionsItemSelected(item)) { |
| 3580 | return true; |
| 3581 | } |
| 3582 | if (item.getItemId() == android.R.id.home && mActionBar != null && |
| 3583 | (mActionBar.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) != 0) { |
| 3584 | if (mParent == null) { |
Adam Powell | 07304f529 | 2012-05-07 17:32:44 -0700 | [diff] [blame] | 3585 | return onNavigateUp(); |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 3586 | } else { |
Adam Powell | 07304f529 | 2012-05-07 17:32:44 -0700 | [diff] [blame] | 3587 | return mParent.onNavigateUpFromChild(this); |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 3588 | } |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 3589 | } |
| 3590 | return false; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3591 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3592 | case Window.FEATURE_CONTEXT_MENU: |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 3593 | if(titleCondensed != null) { |
| 3594 | EventLog.writeEvent(50000, 1, titleCondensed.toString()); |
| 3595 | } |
Dianne Hackborn | 5ddd127 | 2010-06-12 10:15:28 -0700 | [diff] [blame] | 3596 | if (onContextItemSelected(item)) { |
| 3597 | return true; |
| 3598 | } |
| 3599 | return mFragments.dispatchContextItemSelected(item); |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 3600 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3601 | default: |
| 3602 | return false; |
| 3603 | } |
| 3604 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3606 | /** |
| 3607 | * Default implementation of |
| 3608 | * {@link android.view.Window.Callback#onPanelClosed(int, Menu)} for |
| 3609 | * activities. This calls through to {@link #onOptionsMenuClosed(Menu)} |
| 3610 | * method for the {@link android.view.Window#FEATURE_OPTIONS_PANEL} panel, |
| 3611 | * so that subclasses of Activity don't need to deal with feature codes. |
| 3612 | * For context menus ({@link Window#FEATURE_CONTEXT_MENU}), the |
| 3613 | * {@link #onContextMenuClosed(Menu)} will be called. |
| 3614 | */ |
| 3615 | public void onPanelClosed(int featureId, Menu menu) { |
| 3616 | switch (featureId) { |
| 3617 | case Window.FEATURE_OPTIONS_PANEL: |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3618 | mFragments.dispatchOptionsMenuClosed(menu); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3619 | onOptionsMenuClosed(menu); |
| 3620 | break; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3622 | case Window.FEATURE_CONTEXT_MENU: |
| 3623 | onContextMenuClosed(menu); |
| 3624 | break; |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 3625 | |
| 3626 | case Window.FEATURE_ACTION_BAR: |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3627 | initWindowDecorActionBar(); |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 3628 | mActionBar.dispatchMenuVisibilityChanged(false); |
| 3629 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3630 | } |
| 3631 | } |
| 3632 | |
| 3633 | /** |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3634 | * Declare that the options menu has changed, so should be recreated. |
| 3635 | * The {@link #onCreateOptionsMenu(Menu)} method will be called the next |
| 3636 | * time it needs to be displayed. |
| 3637 | */ |
| 3638 | public void invalidateOptionsMenu() { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 3639 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 3640 | (mActionBar == null || !mActionBar.invalidateOptionsMenu())) { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3641 | mWindow.invalidatePanelMenu(Window.FEATURE_OPTIONS_PANEL); |
| 3642 | } |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3643 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3644 | |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3645 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3646 | * Initialize the contents of the Activity's standard options menu. You |
| 3647 | * should place your menu items in to <var>menu</var>. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3648 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3649 | * <p>This is only called once, the first time the options menu is |
| 3650 | * displayed. To update the menu every time it is displayed, see |
| 3651 | * {@link #onPrepareOptionsMenu}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3652 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3653 | * <p>The default implementation populates the menu with standard system |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3654 | * menu items. These are placed in the {@link Menu#CATEGORY_SYSTEM} group so that |
| 3655 | * they will be correctly ordered with application-defined menu items. |
| 3656 | * Deriving classes should always call through to the base implementation. |
| 3657 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3658 | * <p>You can safely hold on to <var>menu</var> (and any items created |
| 3659 | * from it), making modifications to it as desired, until the next |
| 3660 | * time onCreateOptionsMenu() is called. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3661 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3662 | * <p>When you add items to the menu, you can implement the Activity's |
| 3663 | * {@link #onOptionsItemSelected} method to handle them there. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3664 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3665 | * @param menu The options menu in which you place your items. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3666 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3667 | * @return You must return true for the menu to be displayed; |
| 3668 | * if you return false it will not be shown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3669 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | * @see #onPrepareOptionsMenu |
| 3671 | * @see #onOptionsItemSelected |
| 3672 | */ |
| 3673 | public boolean onCreateOptionsMenu(Menu menu) { |
| 3674 | if (mParent != null) { |
| 3675 | return mParent.onCreateOptionsMenu(menu); |
| 3676 | } |
| 3677 | return true; |
| 3678 | } |
| 3679 | |
| 3680 | /** |
| 3681 | * Prepare the Screen's standard options menu to be displayed. This is |
| 3682 | * called right before the menu is shown, every time it is shown. You can |
| 3683 | * use this method to efficiently enable/disable items or otherwise |
| 3684 | * dynamically modify the contents. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3685 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3686 | * <p>The default implementation updates the system menu items based on the |
| 3687 | * activity's state. Deriving classes should always call through to the |
| 3688 | * base class implementation. |
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 | * @param menu The options menu as last shown or first initialized by |
| 3691 | * onCreateOptionsMenu(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3692 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3693 | * @return You must return true for the menu to be displayed; |
| 3694 | * if you return false it will not be shown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3695 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3696 | * @see #onCreateOptionsMenu |
| 3697 | */ |
| 3698 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 3699 | if (mParent != null) { |
| 3700 | return mParent.onPrepareOptionsMenu(menu); |
| 3701 | } |
| 3702 | return true; |
| 3703 | } |
| 3704 | |
| 3705 | /** |
| 3706 | * This hook is called whenever an item in your options menu is selected. |
| 3707 | * The default implementation simply returns false to have the normal |
| 3708 | * processing happen (calling the item's Runnable or sending a message to |
| 3709 | * its Handler as appropriate). You can use this method for any items |
| 3710 | * for which you would like to do processing without those other |
| 3711 | * facilities. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3712 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3713 | * <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] | 3714 | * perform the default menu handling.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3715 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3716 | * @param item The menu item that was selected. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3717 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3718 | * @return boolean Return false to allow normal menu processing to |
| 3719 | * proceed, true to consume it here. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3720 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3721 | * @see #onCreateOptionsMenu |
| 3722 | */ |
| 3723 | public boolean onOptionsItemSelected(MenuItem item) { |
| 3724 | if (mParent != null) { |
| 3725 | return mParent.onOptionsItemSelected(item); |
| 3726 | } |
| 3727 | return false; |
| 3728 | } |
| 3729 | |
| 3730 | /** |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3731 | * This method is called whenever the user chooses to navigate Up within your application's |
| 3732 | * activity hierarchy from the action bar. |
| 3733 | * |
| 3734 | * <p>If the attribute {@link android.R.attr#parentActivityName parentActivityName} |
| 3735 | * was specified in the manifest for this activity or an activity-alias to it, |
| 3736 | * default Up navigation will be handled automatically. If any activity |
| 3737 | * along the parent chain requires extra Intent arguments, the Activity subclass |
| 3738 | * should override the method {@link #onPrepareNavigateUpTaskStack(TaskStackBuilder)} |
| 3739 | * to supply those arguments.</p> |
| 3740 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 3741 | * <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] | 3742 | * from the developer guide and <a href="{@docRoot}design/patterns/navigation.html">Navigation</a> |
| 3743 | * from the design guide for more information about navigating within your app.</p> |
| 3744 | * |
| 3745 | * <p>See the {@link TaskStackBuilder} class and the Activity methods |
| 3746 | * {@link #getParentActivityIntent()}, {@link #shouldUpRecreateTask(Intent)}, and |
| 3747 | * {@link #navigateUpTo(Intent)} for help implementing custom Up navigation. |
| 3748 | * The AppNavigation sample application in the Android SDK is also available for reference.</p> |
| 3749 | * |
| 3750 | * @return true if Up navigation completed successfully and this Activity was finished, |
| 3751 | * false otherwise. |
| 3752 | */ |
| 3753 | public boolean onNavigateUp() { |
| 3754 | // Automatically handle hierarchical Up navigation if the proper |
| 3755 | // metadata is available. |
| 3756 | Intent upIntent = getParentActivityIntent(); |
| 3757 | if (upIntent != null) { |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 3758 | if (mActivityInfo.taskAffinity == null) { |
| 3759 | // Activities with a null affinity are special; they really shouldn't |
| 3760 | // specify a parent activity intent in the first place. Just finish |
| 3761 | // the current activity and call it a day. |
| 3762 | finish(); |
| 3763 | } else if (shouldUpRecreateTask(upIntent)) { |
Adam Powell | f78a844 | 2012-05-01 18:09:32 -0700 | [diff] [blame] | 3764 | TaskStackBuilder b = TaskStackBuilder.create(this); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3765 | onCreateNavigateUpTaskStack(b); |
| 3766 | onPrepareNavigateUpTaskStack(b); |
| 3767 | b.startActivities(); |
Adam Powell | 3d193d9 | 2012-05-15 16:51:55 -0700 | [diff] [blame] | 3768 | |
| 3769 | // We can't finishAffinity if we have a result. |
| 3770 | // Fall back and simply finish the current activity instead. |
| 3771 | if (mResultCode != RESULT_CANCELED || mResultData != null) { |
| 3772 | // Tell the developer what's going on to avoid hair-pulling. |
| 3773 | Log.i(TAG, "onNavigateUp only finishing topmost activity to return a result"); |
| 3774 | finish(); |
| 3775 | } else { |
| 3776 | finishAffinity(); |
| 3777 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3778 | } else { |
| 3779 | navigateUpTo(upIntent); |
| 3780 | } |
| 3781 | return true; |
| 3782 | } |
| 3783 | return false; |
| 3784 | } |
| 3785 | |
| 3786 | /** |
| 3787 | * This is called when a child activity of this one attempts to navigate up. |
| 3788 | * The default implementation simply calls onNavigateUp() on this activity (the parent). |
| 3789 | * |
| 3790 | * @param child The activity making the call. |
| 3791 | */ |
| 3792 | public boolean onNavigateUpFromChild(Activity child) { |
| 3793 | return onNavigateUp(); |
| 3794 | } |
| 3795 | |
| 3796 | /** |
| 3797 | * Define the synthetic task stack that will be generated during Up navigation from |
| 3798 | * a different task. |
| 3799 | * |
| 3800 | * <p>The default implementation of this method adds the parent chain of this activity |
| 3801 | * as specified in the manifest to the supplied {@link TaskStackBuilder}. Applications |
| 3802 | * may choose to override this method to construct the desired task stack in a different |
| 3803 | * way.</p> |
| 3804 | * |
Adam Powell | f019595 | 2012-05-02 21:38:54 -0700 | [diff] [blame] | 3805 | * <p>This method will be invoked by the default implementation of {@link #onNavigateUp()} |
| 3806 | * if {@link #shouldUpRecreateTask(Intent)} returns true when supplied with the intent |
| 3807 | * returned by {@link #getParentActivityIntent()}.</p> |
| 3808 | * |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3809 | * <p>Applications that wish to supply extra Intent parameters to the parent stack defined |
| 3810 | * by the manifest should override {@link #onPrepareNavigateUpTaskStack(TaskStackBuilder)}.</p> |
| 3811 | * |
| 3812 | * @param builder An empty TaskStackBuilder - the application should add intents representing |
| 3813 | * the desired task stack |
| 3814 | */ |
| 3815 | public void onCreateNavigateUpTaskStack(TaskStackBuilder builder) { |
| 3816 | builder.addParentStack(this); |
| 3817 | } |
| 3818 | |
| 3819 | /** |
| 3820 | * Prepare the synthetic task stack that will be generated during Up navigation |
| 3821 | * from a different task. |
| 3822 | * |
| 3823 | * <p>This method receives the {@link TaskStackBuilder} with the constructed series of |
| 3824 | * Intents as generated by {@link #onCreateNavigateUpTaskStack(TaskStackBuilder)}. |
| 3825 | * If any extra data should be added to these intents before launching the new task, |
| 3826 | * the application should override this method and add that data here.</p> |
| 3827 | * |
| 3828 | * @param builder A TaskStackBuilder that has been populated with Intents by |
| 3829 | * onCreateNavigateUpTaskStack. |
| 3830 | */ |
| 3831 | public void onPrepareNavigateUpTaskStack(TaskStackBuilder builder) { |
| 3832 | } |
| 3833 | |
| 3834 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3835 | * This hook is called whenever the options menu is being closed (either by the user canceling |
| 3836 | * the menu with the back/menu button, or when an item is selected). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3837 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3838 | * @param menu The options menu as last shown or first initialized by |
| 3839 | * onCreateOptionsMenu(). |
| 3840 | */ |
| 3841 | public void onOptionsMenuClosed(Menu menu) { |
| 3842 | if (mParent != null) { |
| 3843 | mParent.onOptionsMenuClosed(menu); |
| 3844 | } |
| 3845 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3847 | /** |
| 3848 | * Programmatically opens the options menu. If the options menu is already |
| 3849 | * open, this method does nothing. |
| 3850 | */ |
| 3851 | public void openOptionsMenu() { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 3852 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 3853 | (mActionBar == null || !mActionBar.openOptionsMenu())) { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3854 | mWindow.openPanel(Window.FEATURE_OPTIONS_PANEL, null); |
| 3855 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3856 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3857 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3858 | /** |
| 3859 | * Progammatically closes the options menu. If the options menu is already |
| 3860 | * closed, this method does nothing. |
| 3861 | */ |
| 3862 | public void closeOptionsMenu() { |
Evan Rosky | 41823d1 | 2017-03-21 14:42:35 -0700 | [diff] [blame] | 3863 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 3864 | (mActionBar == null || !mActionBar.closeOptionsMenu())) { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 3865 | mWindow.closePanel(Window.FEATURE_OPTIONS_PANEL); |
| 3866 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | /** |
| 3870 | * Called when a context menu for the {@code view} is about to be shown. |
| 3871 | * Unlike {@link #onCreateOptionsMenu(Menu)}, this will be called every |
| 3872 | * time the context menu is about to be shown and should be populated for |
| 3873 | * the view (or item inside the view for {@link AdapterView} subclasses, |
| 3874 | * this can be found in the {@code menuInfo})). |
| 3875 | * <p> |
| 3876 | * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an |
| 3877 | * item has been selected. |
| 3878 | * <p> |
| 3879 | * 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] | 3880 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3881 | */ |
| 3882 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { |
| 3883 | } |
| 3884 | |
| 3885 | /** |
| 3886 | * Registers a context menu to be shown for the given view (multiple views |
| 3887 | * can show the context menu). This method will set the |
| 3888 | * {@link OnCreateContextMenuListener} on the view to this activity, so |
| 3889 | * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be |
| 3890 | * called when it is time to show the context menu. |
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 | * @see #unregisterForContextMenu(View) |
| 3893 | * @param view The view that should show a context menu. |
| 3894 | */ |
| 3895 | public void registerForContextMenu(View view) { |
| 3896 | view.setOnCreateContextMenuListener(this); |
| 3897 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3899 | /** |
| 3900 | * Prevents a context menu to be shown for the given view. This method will remove the |
| 3901 | * {@link OnCreateContextMenuListener} on the view. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3902 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3903 | * @see #registerForContextMenu(View) |
| 3904 | * @param view The view that should stop showing a context menu. |
| 3905 | */ |
| 3906 | public void unregisterForContextMenu(View view) { |
| 3907 | view.setOnCreateContextMenuListener(null); |
| 3908 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3909 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3910 | /** |
| 3911 | * Programmatically opens the context menu for a particular {@code view}. |
| 3912 | * The {@code view} should have been added via |
| 3913 | * {@link #registerForContextMenu(View)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3914 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3915 | * @param view The view to show the context menu for. |
| 3916 | */ |
| 3917 | public void openContextMenu(View view) { |
| 3918 | view.showContextMenu(); |
| 3919 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3920 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3921 | /** |
| 3922 | * Programmatically closes the most recently opened context menu, if showing. |
| 3923 | */ |
| 3924 | public void closeContextMenu() { |
Jose Lima | bd769a1 | 2015-01-28 10:43:15 -0800 | [diff] [blame] | 3925 | if (mWindow.hasFeature(Window.FEATURE_CONTEXT_MENU)) { |
| 3926 | mWindow.closePanel(Window.FEATURE_CONTEXT_MENU); |
| 3927 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3928 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3930 | /** |
| 3931 | * This hook is called whenever an item in a context menu is selected. The |
| 3932 | * default implementation simply returns false to have the normal processing |
| 3933 | * happen (calling the item's Runnable or sending a message to its Handler |
| 3934 | * as appropriate). You can use this method for any items for which you |
| 3935 | * would like to do processing without those other facilities. |
| 3936 | * <p> |
| 3937 | * Use {@link MenuItem#getMenuInfo()} to get extra information set by the |
| 3938 | * View that added this menu item. |
| 3939 | * <p> |
| 3940 | * Derived classes should call through to the base class for it to perform |
| 3941 | * the default menu handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3942 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3943 | * @param item The context menu item that was selected. |
| 3944 | * @return boolean Return false to allow normal context menu processing to |
| 3945 | * proceed, true to consume it here. |
| 3946 | */ |
| 3947 | public boolean onContextItemSelected(MenuItem item) { |
| 3948 | if (mParent != null) { |
| 3949 | return mParent.onContextItemSelected(item); |
| 3950 | } |
| 3951 | return false; |
| 3952 | } |
| 3953 | |
| 3954 | /** |
| 3955 | * This hook is called whenever the context menu is being closed (either by |
| 3956 | * the user canceling the menu with the back/menu button, or when an item is |
| 3957 | * selected). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3958 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3959 | * @param menu The context menu that is being closed. |
| 3960 | */ |
| 3961 | public void onContextMenuClosed(Menu menu) { |
| 3962 | if (mParent != null) { |
| 3963 | mParent.onContextMenuClosed(menu); |
| 3964 | } |
| 3965 | } |
| 3966 | |
| 3967 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3968 | * @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] | 3969 | */ |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3970 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3971 | protected Dialog onCreateDialog(int id) { |
| 3972 | return null; |
| 3973 | } |
| 3974 | |
| 3975 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3976 | * Callback for creating dialogs that are managed (saved and restored) for you |
| 3977 | * by the activity. The default implementation calls through to |
| 3978 | * {@link #onCreateDialog(int)} for compatibility. |
| 3979 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 3980 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 3981 | * or later, consider instead using a {@link DialogFragment} instead.</em> |
| 3982 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3983 | * <p>If you use {@link #showDialog(int)}, the activity will call through to |
| 3984 | * this method the first time, and hang onto it thereafter. Any dialog |
| 3985 | * that is created by this method will automatically be saved and restored |
| 3986 | * for you, including whether it is showing. |
| 3987 | * |
| 3988 | * <p>If you would like the activity to manage saving and restoring dialogs |
| 3989 | * for you, you should override this method and handle any ids that are |
| 3990 | * passed to {@link #showDialog}. |
| 3991 | * |
| 3992 | * <p>If you would like an opportunity to prepare your dialog before it is shown, |
| 3993 | * override {@link #onPrepareDialog(int, Dialog, Bundle)}. |
| 3994 | * |
| 3995 | * @param id The id of the dialog. |
| 3996 | * @param args The dialog arguments provided to {@link #showDialog(int, Bundle)}. |
| 3997 | * @return The dialog. If you return null, the dialog will not be created. |
| 3998 | * |
| 3999 | * @see #onPrepareDialog(int, Dialog, Bundle) |
| 4000 | * @see #showDialog(int, Bundle) |
| 4001 | * @see #dismissDialog(int) |
| 4002 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4003 | * |
| 4004 | * @deprecated Use the new {@link DialogFragment} class with |
| 4005 | * {@link FragmentManager} instead; this is also |
| 4006 | * available on older platforms through the Android compatibility package. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4007 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4008 | @Nullable |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4009 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4010 | protected Dialog onCreateDialog(int id, Bundle args) { |
| 4011 | return onCreateDialog(id); |
| 4012 | } |
| 4013 | |
| 4014 | /** |
| 4015 | * @deprecated Old no-arguments version of |
| 4016 | * {@link #onPrepareDialog(int, Dialog, Bundle)}. |
| 4017 | */ |
| 4018 | @Deprecated |
| 4019 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 4020 | dialog.setOwnerActivity(this); |
| 4021 | } |
| 4022 | |
| 4023 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4024 | * Provides an opportunity to prepare a managed dialog before it is being |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4025 | * shown. The default implementation calls through to |
| 4026 | * {@link #onPrepareDialog(int, Dialog)} for compatibility. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4027 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4028 | * <p> |
| 4029 | * Override this if you need to update a managed dialog based on the state |
| 4030 | * of the application each time it is shown. For example, a time picker |
| 4031 | * dialog might want to be updated with the current time. You should call |
| 4032 | * through to the superclass's implementation. The default implementation |
| 4033 | * will set this Activity as the owner activity on the Dialog. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4034 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4035 | * @param id The id of the managed dialog. |
| 4036 | * @param dialog The dialog. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4037 | * @param args The dialog arguments provided to {@link #showDialog(int, Bundle)}. |
| 4038 | * @see #onCreateDialog(int, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4039 | * @see #showDialog(int) |
| 4040 | * @see #dismissDialog(int) |
| 4041 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4042 | * |
| 4043 | * @deprecated Use the new {@link DialogFragment} class with |
| 4044 | * {@link FragmentManager} instead; this is also |
| 4045 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4046 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4047 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4048 | protected void onPrepareDialog(int id, Dialog dialog, Bundle args) { |
| 4049 | onPrepareDialog(id, dialog); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4050 | } |
| 4051 | |
| 4052 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4053 | * Simple version of {@link #showDialog(int, Bundle)} that does not |
| 4054 | * take any arguments. Simply calls {@link #showDialog(int, Bundle)} |
| 4055 | * with null arguments. |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4056 | * |
| 4057 | * @deprecated Use the new {@link DialogFragment} class with |
| 4058 | * {@link FragmentManager} instead; this is also |
| 4059 | * available on older platforms through the Android compatibility package. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4060 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4061 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4062 | public final void showDialog(int id) { |
| 4063 | showDialog(id, null); |
| 4064 | } |
| 4065 | |
| 4066 | /** |
| 4067 | * 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] | 4068 | * will be made with the same id the first time this is called for a given |
| 4069 | * id. From thereafter, the dialog will be automatically saved and restored. |
| 4070 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 4071 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 4072 | * or later, consider instead using a {@link DialogFragment} instead.</em> |
| 4073 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4074 | * <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] | 4075 | * be made to provide an opportunity to do any timely preparation. |
| 4076 | * |
| 4077 | * @param id The id of the managed dialog. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4078 | * @param args Arguments to pass through to the dialog. These will be saved |
| 4079 | * and restored for you. Note that if the dialog is already created, |
| 4080 | * {@link #onCreateDialog(int, Bundle)} will not be called with the new |
| 4081 | * arguments but {@link #onPrepareDialog(int, Dialog, Bundle)} will be. |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 4082 | * If you need to rebuild the dialog, call {@link #removeDialog(int)} first. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4083 | * @return Returns true if the Dialog was created; false is returned if |
| 4084 | * it is not created because {@link #onCreateDialog(int, Bundle)} returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4085 | * |
Joe Onorato | 37296dc | 2009-07-31 17:58:55 -0700 | [diff] [blame] | 4086 | * @see Dialog |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4087 | * @see #onCreateDialog(int, Bundle) |
| 4088 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4089 | * @see #dismissDialog(int) |
| 4090 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4091 | * |
| 4092 | * @deprecated Use the new {@link DialogFragment} class with |
| 4093 | * {@link FragmentManager} instead; this is also |
| 4094 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4095 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4096 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4097 | public final boolean showDialog(int id, Bundle args) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4098 | if (mManagedDialogs == null) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4099 | mManagedDialogs = new SparseArray<ManagedDialog>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4100 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4101 | ManagedDialog md = mManagedDialogs.get(id); |
| 4102 | if (md == null) { |
| 4103 | md = new ManagedDialog(); |
| 4104 | md.mDialog = createDialog(id, null, args); |
| 4105 | if (md.mDialog == null) { |
| 4106 | return false; |
| 4107 | } |
| 4108 | mManagedDialogs.put(id, md); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4109 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4110 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4111 | md.mArgs = args; |
| 4112 | onPrepareDialog(id, md.mDialog, args); |
| 4113 | md.mDialog.show(); |
| 4114 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4115 | } |
| 4116 | |
| 4117 | /** |
| 4118 | * Dismiss a dialog that was previously shown via {@link #showDialog(int)}. |
| 4119 | * |
| 4120 | * @param id The id of the managed dialog. |
| 4121 | * |
| 4122 | * @throws IllegalArgumentException if the id was not previously shown via |
| 4123 | * {@link #showDialog(int)}. |
| 4124 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4125 | * @see #onCreateDialog(int, Bundle) |
| 4126 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4127 | * @see #showDialog(int) |
| 4128 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4129 | * |
| 4130 | * @deprecated Use the new {@link DialogFragment} class with |
| 4131 | * {@link FragmentManager} instead; this is also |
| 4132 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4133 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4134 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4135 | public final void dismissDialog(int id) { |
| 4136 | if (mManagedDialogs == null) { |
| 4137 | throw missingDialog(id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4138 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4139 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4140 | final ManagedDialog md = mManagedDialogs.get(id); |
| 4141 | if (md == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4142 | throw missingDialog(id); |
| 4143 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4144 | md.mDialog.dismiss(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4145 | } |
| 4146 | |
| 4147 | /** |
| 4148 | * Creates an exception to throw if a user passed in a dialog id that is |
| 4149 | * unexpected. |
| 4150 | */ |
| 4151 | private IllegalArgumentException missingDialog(int id) { |
| 4152 | return new IllegalArgumentException("no dialog with id " + id + " was ever " |
| 4153 | + "shown via Activity#showDialog"); |
| 4154 | } |
| 4155 | |
| 4156 | /** |
| 4157 | * Removes any internal references to a dialog managed by this Activity. |
| 4158 | * If the dialog is showing, it will dismiss it as part of the clean up. |
| 4159 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4160 | * <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] | 4161 | * want to avoid the overhead of saving and restoring it in the future. |
| 4162 | * |
Dianne Hackborn | d2ce8bbb | 2010-10-06 16:46:05 -0700 | [diff] [blame] | 4163 | * <p>As of {@link android.os.Build.VERSION_CODES#GINGERBREAD}, this function |
| 4164 | * will not throw an exception if you try to remove an ID that does not |
| 4165 | * currently have an associated dialog.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4166 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4167 | * @param id The id of the managed dialog. |
| 4168 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4169 | * @see #onCreateDialog(int, Bundle) |
| 4170 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4171 | * @see #showDialog(int) |
| 4172 | * @see #dismissDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4173 | * |
| 4174 | * @deprecated Use the new {@link DialogFragment} class with |
| 4175 | * {@link FragmentManager} instead; this is also |
| 4176 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4177 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4178 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4179 | public final void removeDialog(int id) { |
Dianne Hackborn | d2ce8bbb | 2010-10-06 16:46:05 -0700 | [diff] [blame] | 4180 | if (mManagedDialogs != null) { |
| 4181 | final ManagedDialog md = mManagedDialogs.get(id); |
| 4182 | if (md != null) { |
| 4183 | md.mDialog.dismiss(); |
| 4184 | mManagedDialogs.remove(id); |
| 4185 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4186 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4187 | } |
| 4188 | |
| 4189 | /** |
| 4190 | * 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] | 4191 | * |
Bjorn Bringert | 6266e40 | 2009-09-25 14:25:41 +0100 | [diff] [blame] | 4192 | * <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] | 4193 | * menu item, search button, or other widgets within your activity. Unless overidden, |
Bjorn Bringert | 6266e40 | 2009-09-25 14:25:41 +0100 | [diff] [blame] | 4194 | * calling this function is the same as calling |
| 4195 | * {@link #startSearch startSearch(null, false, null, false)}, which launches |
| 4196 | * search for the current activity as specified in its manifest, see {@link SearchManager}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4197 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4198 | * <p>You can override this function to force global search, e.g. in response to a dedicated |
| 4199 | * search key, or to block search entirely (by simply returning false). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4200 | * |
Erik Wolsheimer | ac5cecd | 2017-12-05 13:11:50 -0800 | [diff] [blame] | 4201 | * <p>Note: when running in a {@link Configuration#UI_MODE_TYPE_TELEVISION} or |
| 4202 | * {@link Configuration#UI_MODE_TYPE_WATCH}, the default implementation changes to simply |
| 4203 | * return false and you must supply your own custom implementation if you want to support |
| 4204 | * search. |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 4205 | * |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 4206 | * @param searchEvent The {@link SearchEvent} that signaled this search. |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 4207 | * @return Returns {@code true} if search launched, and {@code false} if the activity does |
| 4208 | * not respond to search. The default implementation always returns {@code true}, except |
| 4209 | * when in {@link Configuration#UI_MODE_TYPE_TELEVISION} mode where it returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4210 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4211 | * @see android.app.SearchManager |
| 4212 | */ |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 4213 | public boolean onSearchRequested(@Nullable SearchEvent searchEvent) { |
| 4214 | mSearchEvent = searchEvent; |
| 4215 | boolean result = onSearchRequested(); |
| 4216 | mSearchEvent = null; |
| 4217 | return result; |
| 4218 | } |
| 4219 | |
| 4220 | /** |
| 4221 | * @see #onSearchRequested(SearchEvent) |
| 4222 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4223 | public boolean onSearchRequested() { |
Erik Wolsheimer | ac5cecd | 2017-12-05 13:11:50 -0800 | [diff] [blame] | 4224 | final int uiMode = getResources().getConfiguration().uiMode |
| 4225 | & Configuration.UI_MODE_TYPE_MASK; |
| 4226 | if (uiMode != Configuration.UI_MODE_TYPE_TELEVISION |
| 4227 | && uiMode != Configuration.UI_MODE_TYPE_WATCH) { |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 4228 | startSearch(null, false, null, false); |
| 4229 | return true; |
| 4230 | } else { |
| 4231 | return false; |
| 4232 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4233 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4235 | /** |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 4236 | * During the onSearchRequested() callbacks, this function will return the |
| 4237 | * {@link SearchEvent} that triggered the callback, if it exists. |
| 4238 | * |
| 4239 | * @return SearchEvent The SearchEvent that triggered the {@link |
| 4240 | * #onSearchRequested} callback. |
| 4241 | */ |
| 4242 | public final SearchEvent getSearchEvent() { |
| 4243 | return mSearchEvent; |
| 4244 | } |
| 4245 | |
| 4246 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | * This hook is called to launch the search UI. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4248 | * |
| 4249 | * <p>It is typically called from onSearchRequested(), either directly from |
| 4250 | * 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] | 4251 | * 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] | 4252 | * 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] | 4253 | * is to inject specific data such as context data, it is preferred to <i>override</i> |
| 4254 | * onSearchRequested(), so that any callers to it will benefit from the override. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4255 | * |
Erik Wolsheimer | ac5cecd | 2017-12-05 13:11:50 -0800 | [diff] [blame] | 4256 | * <p>Note: when running in a {@link Configuration#UI_MODE_TYPE_WATCH}, use of this API is |
| 4257 | * not supported. |
| 4258 | * |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4259 | * @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] | 4260 | * pre-entered text in the search query box. |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4261 | * @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] | 4262 | * any further typing will replace it. This is useful for cases where an entire pre-formed |
| 4263 | * query is being inserted. If false, the selection point will be placed at the end of the |
| 4264 | * inserted query. This is useful when the inserted query is text that the user entered, |
| 4265 | * and the user would expect to be able to keep typing. <i>This parameter is only meaningful |
| 4266 | * if initialQuery is a non-empty string.</i> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4267 | * @param appSearchData An application can insert application-specific |
| 4268 | * 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] | 4269 | * searches. This data will be returned with SEARCH intent(s). Null if |
| 4270 | * no extra data is required. |
| 4271 | * @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] | 4272 | * 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] | 4273 | * 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] | 4274 | * 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] | 4275 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4276 | * @see android.app.SearchManager |
| 4277 | * @see #onSearchRequested |
| 4278 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4279 | public void startSearch(@Nullable String initialQuery, boolean selectInitialQuery, |
| 4280 | @Nullable Bundle appSearchData, boolean globalSearch) { |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 4281 | ensureSearchManager(); |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 4282 | mSearchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4283 | appSearchData, globalSearch); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | /** |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4287 | * Similar to {@link #startSearch}, but actually fires off the search query after invoking |
| 4288 | * the search dialog. Made available for testing purposes. |
| 4289 | * |
| 4290 | * @param query The query to trigger. If empty, the request will be ignored. |
| 4291 | * @param appSearchData An application can insert application-specific |
| 4292 | * context here, in order to improve quality or specificity of its own |
| 4293 | * searches. This data will be returned with SEARCH intent(s). Null if |
| 4294 | * no extra data is required. |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4295 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4296 | public void triggerSearch(String query, @Nullable Bundle appSearchData) { |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4297 | ensureSearchManager(); |
Bjorn Bringert | b782a2f | 2009-10-01 09:57:33 +0100 | [diff] [blame] | 4298 | mSearchManager.triggerSearch(query, getComponentName(), appSearchData); |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4299 | } |
| 4300 | |
| 4301 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4302 | * Request that key events come to this activity. Use this if your |
| 4303 | * activity has no views with focus, but the activity still wants |
| 4304 | * a chance to process key events. |
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 | * @see android.view.Window#takeKeyEvents |
| 4307 | */ |
| 4308 | public void takeKeyEvents(boolean get) { |
| 4309 | getWindow().takeKeyEvents(get); |
| 4310 | } |
| 4311 | |
| 4312 | /** |
| 4313 | * Enable extended window features. This is a convenience for calling |
| 4314 | * {@link android.view.Window#requestFeature getWindow().requestFeature()}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4315 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4316 | * @param featureId The desired feature as defined in |
| 4317 | * {@link android.view.Window}. |
| 4318 | * @return Returns true if the requested feature is supported and now |
| 4319 | * enabled. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4320 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4321 | * @see android.view.Window#requestFeature |
| 4322 | */ |
| 4323 | public final boolean requestWindowFeature(int featureId) { |
| 4324 | return getWindow().requestFeature(featureId); |
| 4325 | } |
| 4326 | |
| 4327 | /** |
| 4328 | * Convenience for calling |
| 4329 | * {@link android.view.Window#setFeatureDrawableResource}. |
| 4330 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 4331 | public final void setFeatureDrawableResource(int featureId, @DrawableRes int resId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4332 | getWindow().setFeatureDrawableResource(featureId, resId); |
| 4333 | } |
| 4334 | |
| 4335 | /** |
| 4336 | * Convenience for calling |
| 4337 | * {@link android.view.Window#setFeatureDrawableUri}. |
| 4338 | */ |
| 4339 | public final void setFeatureDrawableUri(int featureId, Uri uri) { |
| 4340 | getWindow().setFeatureDrawableUri(featureId, uri); |
| 4341 | } |
| 4342 | |
| 4343 | /** |
| 4344 | * Convenience for calling |
| 4345 | * {@link android.view.Window#setFeatureDrawable(int, Drawable)}. |
| 4346 | */ |
| 4347 | public final void setFeatureDrawable(int featureId, Drawable drawable) { |
| 4348 | getWindow().setFeatureDrawable(featureId, drawable); |
| 4349 | } |
| 4350 | |
| 4351 | /** |
| 4352 | * Convenience for calling |
| 4353 | * {@link android.view.Window#setFeatureDrawableAlpha}. |
| 4354 | */ |
| 4355 | public final void setFeatureDrawableAlpha(int featureId, int alpha) { |
| 4356 | getWindow().setFeatureDrawableAlpha(featureId, alpha); |
| 4357 | } |
| 4358 | |
| 4359 | /** |
| 4360 | * Convenience for calling |
| 4361 | * {@link android.view.Window#getLayoutInflater}. |
| 4362 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4363 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4364 | public LayoutInflater getLayoutInflater() { |
| 4365 | return getWindow().getLayoutInflater(); |
| 4366 | } |
| 4367 | |
| 4368 | /** |
| 4369 | * Returns a {@link MenuInflater} with this context. |
| 4370 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4371 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4372 | public MenuInflater getMenuInflater() { |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 4373 | // Make sure that action views can get an appropriate theme. |
| 4374 | if (mMenuInflater == null) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 4375 | initWindowDecorActionBar(); |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 4376 | if (mActionBar != null) { |
Dianne Hackborn | 9275197 | 2012-05-18 19:22:14 -0700 | [diff] [blame] | 4377 | mMenuInflater = new MenuInflater(mActionBar.getThemedContext(), this); |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 4378 | } else { |
| 4379 | mMenuInflater = new MenuInflater(this); |
| 4380 | } |
| 4381 | } |
| 4382 | return mMenuInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4383 | } |
| 4384 | |
| 4385 | @Override |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 4386 | public void setTheme(int resid) { |
| 4387 | super.setTheme(resid); |
| 4388 | mWindow.setTheme(resid); |
| 4389 | } |
| 4390 | |
| 4391 | @Override |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 4392 | protected void onApplyThemeResource(Resources.Theme theme, @StyleRes int resid, |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4393 | boolean first) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4394 | if (mParent == null) { |
| 4395 | super.onApplyThemeResource(theme, resid, first); |
| 4396 | } else { |
| 4397 | try { |
| 4398 | theme.setTo(mParent.getTheme()); |
| 4399 | } catch (Exception e) { |
| 4400 | // Empty |
| 4401 | } |
| 4402 | theme.applyStyle(resid, false); |
| 4403 | } |
Winson | 073a526 | 2016-02-29 16:04:40 -0800 | [diff] [blame] | 4404 | |
| 4405 | // Get the primary color and update the TaskDescription for this activity |
| 4406 | TypedArray a = theme.obtainStyledAttributes( |
| 4407 | com.android.internal.R.styleable.ActivityTaskDescription); |
| 4408 | if (mTaskDescription.getPrimaryColor() == 0) { |
| 4409 | int colorPrimary = a.getColor( |
| 4410 | com.android.internal.R.styleable.ActivityTaskDescription_colorPrimary, 0); |
| 4411 | if (colorPrimary != 0 && Color.alpha(colorPrimary) == 0xFF) { |
| 4412 | mTaskDescription.setPrimaryColor(colorPrimary); |
| 4413 | } |
| 4414 | } |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 4415 | |
| 4416 | int colorBackground = a.getColor( |
| 4417 | com.android.internal.R.styleable.ActivityTaskDescription_colorBackground, 0); |
| 4418 | if (colorBackground != 0 && Color.alpha(colorBackground) == 0xFF) { |
| 4419 | mTaskDescription.setBackgroundColor(colorBackground); |
Winson | 073a526 | 2016-02-29 16:04:40 -0800 | [diff] [blame] | 4420 | } |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 4421 | |
| 4422 | final int statusBarColor = a.getColor( |
| 4423 | com.android.internal.R.styleable.ActivityTaskDescription_statusBarColor, 0); |
| 4424 | if (statusBarColor != 0) { |
| 4425 | mTaskDescription.setStatusBarColor(statusBarColor); |
| 4426 | } |
| 4427 | |
| 4428 | final int navigationBarColor = a.getColor( |
| 4429 | com.android.internal.R.styleable.ActivityTaskDescription_navigationBarColor, 0); |
| 4430 | if (navigationBarColor != 0) { |
| 4431 | mTaskDescription.setNavigationBarColor(navigationBarColor); |
| 4432 | } |
| 4433 | |
Winson | 073a526 | 2016-02-29 16:04:40 -0800 | [diff] [blame] | 4434 | a.recycle(); |
| 4435 | setTaskDescription(mTaskDescription); |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 4436 | } |
| 4437 | |
| 4438 | /** |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4439 | * Requests permissions to be granted to this application. These permissions |
| 4440 | * must be requested in your manifest, they should not be granted to your app, |
| 4441 | * and they should have protection level {@link android.content.pm.PermissionInfo |
| 4442 | * #PROTECTION_DANGEROUS dangerous}, regardless whether they are declared by |
| 4443 | * the platform or a third-party app. |
| 4444 | * <p> |
| 4445 | * Normal permissions {@link android.content.pm.PermissionInfo#PROTECTION_NORMAL} |
| 4446 | * are granted at install time if requested in the manifest. Signature permissions |
| 4447 | * {@link android.content.pm.PermissionInfo#PROTECTION_SIGNATURE} are granted at |
| 4448 | * install time if requested in the manifest and the signature of your app matches |
| 4449 | * the signature of the app declaring the permissions. |
| 4450 | * </p> |
| 4451 | * <p> |
| 4452 | * If your app does not have the requested permissions the user will be presented |
| 4453 | * with UI for accepting them. After the user has accepted or rejected the |
| 4454 | * requested permissions you will receive a callback on {@link |
| 4455 | * #onRequestPermissionsResult(int, String[], int[])} reporting whether the |
| 4456 | * permissions were granted or not. |
| 4457 | * </p> |
| 4458 | * <p> |
| 4459 | * Note that requesting a permission does not guarantee it will be granted and |
| 4460 | * your app should be able to run without having this permission. |
| 4461 | * </p> |
| 4462 | * <p> |
| 4463 | * This method may start an activity allowing the user to choose which permissions |
| 4464 | * to grant and which to reject. Hence, you should be prepared that your activity |
| 4465 | * may be paused and resumed. Further, granting some permissions may require |
| 4466 | * a restart of you application. In such a case, the system will recreate the |
| 4467 | * activity stack before delivering the result to {@link |
| 4468 | * #onRequestPermissionsResult(int, String[], int[])}. |
| 4469 | * </p> |
| 4470 | * <p> |
| 4471 | * When checking whether you have a permission you should use {@link |
| 4472 | * #checkSelfPermission(String)}. |
| 4473 | * </p> |
| 4474 | * <p> |
Svet Ganov | d7ad54e | 2015-08-21 06:18:09 -0700 | [diff] [blame] | 4475 | * Calling this API for permissions already granted to your app would show UI |
| 4476 | * to the user to decide whether the app can still hold these permissions. This |
| 4477 | * can be useful if the way your app uses data guarded by the permissions |
| 4478 | * changes significantly. |
| 4479 | * </p> |
| 4480 | * <p> |
Svet Ganov | 255aece | 2015-07-03 16:03:53 -0700 | [diff] [blame] | 4481 | * You cannot request a permission if your activity sets {@link |
| 4482 | * android.R.styleable#AndroidManifestActivity_noHistory noHistory} to |
| 4483 | * <code>true</code> because in this case the activity would not receive |
| 4484 | * result callbacks including {@link #onRequestPermissionsResult(int, String[], int[])}. |
| 4485 | * </p> |
| 4486 | * <p> |
Trevor Johns | 682c24e | 2016-04-12 10:13:47 -0700 | [diff] [blame] | 4487 | * The <a href="http://developer.android.com/samples/RuntimePermissions/index.html"> |
| 4488 | * RuntimePermissions</a> sample app demonstrates how to use this method to |
| 4489 | * request permissions at run time. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4490 | * </p> |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4491 | * |
Svet Ganov | f66381c | 2016-02-18 20:02:36 -0800 | [diff] [blame] | 4492 | * @param permissions The requested permissions. Must me non-null and not empty. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4493 | * @param requestCode Application specific request code to match with a result |
| 4494 | * reported to {@link #onRequestPermissionsResult(int, String[], int[])}. |
Svet Ganov | 255aece | 2015-07-03 16:03:53 -0700 | [diff] [blame] | 4495 | * Should be >= 0. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4496 | * |
Paul Miller | 77a0e13 | 2016-02-11 13:46:49 -0800 | [diff] [blame] | 4497 | * @throws IllegalArgumentException if requestCode is negative. |
| 4498 | * |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4499 | * @see #onRequestPermissionsResult(int, String[], int[]) |
| 4500 | * @see #checkSelfPermission(String) |
Svetoslav | aa048b6 | 2015-06-02 15:08:48 -0700 | [diff] [blame] | 4501 | * @see #shouldShowRequestPermissionRationale(String) |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4502 | */ |
| 4503 | public final void requestPermissions(@NonNull String[] permissions, int requestCode) { |
Paul Miller | 77a0e13 | 2016-02-11 13:46:49 -0800 | [diff] [blame] | 4504 | if (requestCode < 0) { |
| 4505 | throw new IllegalArgumentException("requestCode should be >= 0"); |
| 4506 | } |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 4507 | if (mHasCurrentPermissionsRequest) { |
Ahmad Melegy | e2bfbf1 | 2017-11-14 21:27:28 +0000 | [diff] [blame] | 4508 | Log.w(TAG, "Can request only one set of permissions at a time"); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 4509 | // Dispatch the callback with empty arrays which means a cancellation. |
| 4510 | onRequestPermissionsResult(requestCode, new String[0], new int[0]); |
| 4511 | return; |
| 4512 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4513 | Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions); |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 4514 | startActivityForResult(REQUEST_PERMISSIONS_WHO_PREFIX, intent, requestCode, null); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 4515 | mHasCurrentPermissionsRequest = true; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4516 | } |
| 4517 | |
| 4518 | /** |
| 4519 | * Callback for the result from requesting permissions. This method |
| 4520 | * is invoked for every call on {@link #requestPermissions(String[], int)}. |
Svet Ganov | 0f45c7c | 2015-07-16 16:28:51 -0700 | [diff] [blame] | 4521 | * <p> |
| 4522 | * <strong>Note:</strong> It is possible that the permissions request interaction |
| 4523 | * with the user is interrupted. In this case you will receive empty permissions |
| 4524 | * and results arrays which should be treated as a cancellation. |
| 4525 | * </p> |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4526 | * |
| 4527 | * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}. |
| 4528 | * @param permissions The requested permissions. Never null. |
| 4529 | * @param grantResults The grant results for the corresponding permissions |
| 4530 | * which is either {@link android.content.pm.PackageManager#PERMISSION_GRANTED} |
| 4531 | * or {@link android.content.pm.PackageManager#PERMISSION_DENIED}. Never null. |
| 4532 | * |
| 4533 | * @see #requestPermissions(String[], int) |
| 4534 | */ |
| 4535 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, |
| 4536 | @NonNull int[] grantResults) { |
| 4537 | /* callback - no nothing */ |
| 4538 | } |
| 4539 | |
| 4540 | /** |
Svetoslav | 20770dd | 2015-05-29 15:43:04 -0700 | [diff] [blame] | 4541 | * Gets whether you should show UI with rationale for requesting a permission. |
| 4542 | * You should do this only if you do not have the permission and the context in |
| 4543 | * which the permission is requested does not clearly communicate to the user |
| 4544 | * what would be the benefit from granting this permission. |
| 4545 | * <p> |
| 4546 | * For example, if you write a camera app, requesting the camera permission |
| 4547 | * would be expected by the user and no rationale for why it is requested is |
| 4548 | * needed. If however, the app needs location for tagging photos then a non-tech |
| 4549 | * savvy user may wonder how location is related to taking photos. In this case |
| 4550 | * you may choose to show UI with rationale of requesting this permission. |
| 4551 | * </p> |
| 4552 | * |
| 4553 | * @param permission A permission your app wants to request. |
| 4554 | * @return Whether you can show permission rationale UI. |
| 4555 | * |
| 4556 | * @see #checkSelfPermission(String) |
| 4557 | * @see #requestPermissions(String[], int) |
| 4558 | * @see #onRequestPermissionsResult(int, String[], int[]) |
| 4559 | */ |
Svetoslav | 9ce9a15 | 2015-06-02 17:59:31 -0700 | [diff] [blame] | 4560 | public boolean shouldShowRequestPermissionRationale(@NonNull String permission) { |
Svetoslav | 20770dd | 2015-05-29 15:43:04 -0700 | [diff] [blame] | 4561 | return getPackageManager().shouldShowRequestPermissionRationale(permission); |
| 4562 | } |
| 4563 | |
| 4564 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4565 | * Same as calling {@link #startActivityForResult(Intent, int, Bundle)} |
| 4566 | * with no options. |
| 4567 | * |
| 4568 | * @param intent The intent to start. |
| 4569 | * @param requestCode If >= 0, this code will be returned in |
| 4570 | * onActivityResult() when the activity exits. |
| 4571 | * |
| 4572 | * @throws android.content.ActivityNotFoundException |
| 4573 | * |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 4574 | * @see #startActivity |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4575 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 4576 | public void startActivityForResult(@RequiresPermission Intent intent, int requestCode) { |
George Mount | abb63cb | 2014-06-23 11:17:58 -0700 | [diff] [blame] | 4577 | startActivityForResult(intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4578 | } |
| 4579 | |
| 4580 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4581 | * Launch an activity for which you would like a result when it finished. |
| 4582 | * When this activity exits, your |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 4583 | * onActivityResult() method will be called with the given requestCode. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4584 | * Using a negative requestCode is the same as calling |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4585 | * {@link #startActivity} (the activity is not launched as a sub-activity). |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4586 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4587 | * <p>Note that this method should only be used with Intent protocols |
| 4588 | * that are defined to return a result. In other protocols (such as |
| 4589 | * {@link Intent#ACTION_MAIN} or {@link Intent#ACTION_VIEW}), you may |
| 4590 | * 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] | 4591 | * are launching uses {@link Intent#FLAG_ACTIVITY_NEW_TASK}, it will not |
| 4592 | * 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] | 4593 | * |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4594 | * <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] | 4595 | * >= 0 during the initial onCreate(Bundle savedInstanceState)/onResume() of your |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 4596 | * activity, then your window will not be displayed until a result is |
| 4597 | * returned back from the started activity. This is to avoid visible |
| 4598 | * flickering when redirecting to another activity. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4599 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4600 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 4601 | * if there was no Activity found to run the given Intent. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4602 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4603 | * @param intent The intent to start. |
| 4604 | * @param requestCode If >= 0, this code will be returned in |
| 4605 | * onActivityResult() when the activity exits. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4606 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 4607 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4608 | * Context.startActivity(Intent, Bundle)} for more details. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4609 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4610 | * @throws android.content.ActivityNotFoundException |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4611 | * |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 4612 | * @see #startActivity |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4613 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 4614 | public void startActivityForResult(@RequiresPermission Intent intent, int requestCode, |
| 4615 | @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4616 | if (mParent == null) { |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 4617 | options = transferSpringboardActivityOptions(options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4618 | Instrumentation.ActivityResult ar = |
| 4619 | mInstrumentation.execStartActivity( |
| 4620 | this, mMainThread.getApplicationThread(), mToken, this, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4621 | intent, requestCode, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4622 | if (ar != null) { |
| 4623 | mMainThread.sendActivityResult( |
| 4624 | mToken, mEmbeddedID, requestCode, ar.getResultCode(), |
| 4625 | ar.getResultData()); |
| 4626 | } |
| 4627 | if (requestCode >= 0) { |
| 4628 | // If this start is requesting a result, we can avoid making |
| 4629 | // the activity visible until the result is received. Setting |
| 4630 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 4631 | // activity hidden during this time, to avoid flickering. |
| 4632 | // This can only be done when a result is requested because |
| 4633 | // that guarantees we will get information back when the |
| 4634 | // activity is finished, no matter what happens to it. |
| 4635 | mStartedActivity = true; |
| 4636 | } |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 4637 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4638 | cancelInputsAndStartExitTransition(options); |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 4639 | // 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] | 4640 | } else { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4641 | if (options != null) { |
| 4642 | mParent.startActivityFromChild(this, intent, requestCode, options); |
| 4643 | } else { |
| 4644 | // Note we want to go through this method for compatibility with |
| 4645 | // existing applications that may have overridden it. |
| 4646 | mParent.startActivityFromChild(this, intent, requestCode); |
| 4647 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4648 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | /** |
| 4652 | * Cancels pending inputs and if an Activity Transition is to be run, starts the transition. |
| 4653 | * |
| 4654 | * @param options The ActivityOptions bundle used to start an Activity. |
| 4655 | */ |
| 4656 | private void cancelInputsAndStartExitTransition(Bundle options) { |
| 4657 | final View decor = mWindow != null ? mWindow.peekDecorView() : null; |
| 4658 | if (decor != null) { |
| 4659 | decor.cancelPendingInputEvents(); |
| 4660 | } |
George Mount | ff24328 | 2014-07-07 16:12:07 -0700 | [diff] [blame] | 4661 | if (options != null && !isTopOfTask()) { |
| 4662 | mActivityTransitionState.startExitOutTransition(this, options); |
| 4663 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4664 | } |
| 4665 | |
Chet Haase | b64e777f | 2016-12-09 07:17:10 -0800 | [diff] [blame] | 4666 | /** |
| 4667 | * Returns whether there are any activity transitions currently running on this |
| 4668 | * activity. A return value of {@code true} can mean that either an enter or |
| 4669 | * exit transition is running, including whether the background of the activity |
| 4670 | * is animating as a part of that transition. |
| 4671 | * |
| 4672 | * @return true if a transition is currently running on this activity, false otherwise. |
| 4673 | */ |
| 4674 | public boolean isActivityTransitionRunning() { |
| 4675 | return mActivityTransitionState.isTransitionRunning(); |
| 4676 | } |
| 4677 | |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 4678 | private Bundle transferSpringboardActivityOptions(Bundle options) { |
| 4679 | if (options == null && (mWindow != null && !mWindow.isActive())) { |
| 4680 | final ActivityOptions activityOptions = getActivityOptions(); |
George Mount | 9638378 | 2016-06-08 15:13:52 -0700 | [diff] [blame] | 4681 | if (activityOptions != null && |
| 4682 | activityOptions.getAnimationType() == ActivityOptions.ANIM_SCENE_TRANSITION) { |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 4683 | return activityOptions.toBundle(); |
| 4684 | } |
| 4685 | } |
| 4686 | return options; |
| 4687 | } |
| 4688 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4689 | /** |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 4690 | * @hide Implement to provide correct calling token. |
| 4691 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 4692 | @UnsupportedAppUsage |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 4693 | public void startActivityForResultAsUser(Intent intent, int requestCode, UserHandle user) { |
| 4694 | startActivityForResultAsUser(intent, requestCode, null, user); |
| 4695 | } |
| 4696 | |
| 4697 | /** |
| 4698 | * @hide Implement to provide correct calling token. |
| 4699 | */ |
| 4700 | public void startActivityForResultAsUser(Intent intent, int requestCode, |
| 4701 | @Nullable Bundle options, UserHandle user) { |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 4702 | startActivityForResultAsUser(intent, mEmbeddedID, requestCode, options, user); |
| 4703 | } |
| 4704 | |
| 4705 | /** |
| 4706 | * @hide Implement to provide correct calling token. |
| 4707 | */ |
| 4708 | public void startActivityForResultAsUser(Intent intent, String resultWho, int requestCode, |
| 4709 | @Nullable Bundle options, UserHandle user) { |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 4710 | if (mParent != null) { |
| 4711 | throw new RuntimeException("Can't be called from a child"); |
| 4712 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 4713 | options = transferSpringboardActivityOptions(options); |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 4714 | Instrumentation.ActivityResult ar = mInstrumentation.execStartActivity( |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 4715 | this, mMainThread.getApplicationThread(), mToken, resultWho, intent, requestCode, |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 4716 | options, user); |
| 4717 | if (ar != null) { |
| 4718 | mMainThread.sendActivityResult( |
| 4719 | mToken, mEmbeddedID, requestCode, ar.getResultCode(), ar.getResultData()); |
| 4720 | } |
| 4721 | if (requestCode >= 0) { |
| 4722 | // If this start is requesting a result, we can avoid making |
| 4723 | // the activity visible until the result is received. Setting |
| 4724 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 4725 | // activity hidden during this time, to avoid flickering. |
| 4726 | // This can only be done when a result is requested because |
| 4727 | // that guarantees we will get information back when the |
| 4728 | // activity is finished, no matter what happens to it. |
| 4729 | mStartedActivity = true; |
| 4730 | } |
| 4731 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4732 | cancelInputsAndStartExitTransition(options); |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | /** |
| 4736 | * @hide Implement to provide correct calling token. |
| 4737 | */ |
Remi NGUYEN VAN | bf1ecd1 | 2019-01-20 21:18:22 +0900 | [diff] [blame] | 4738 | @Override |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 4739 | public void startActivityAsUser(Intent intent, UserHandle user) { |
| 4740 | startActivityAsUser(intent, null, user); |
| 4741 | } |
| 4742 | |
| 4743 | /** |
| 4744 | * @hide Implement to provide correct calling token. |
| 4745 | */ |
| 4746 | public void startActivityAsUser(Intent intent, Bundle options, UserHandle user) { |
| 4747 | if (mParent != null) { |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 4748 | throw new RuntimeException("Can't be called from a child"); |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 4749 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 4750 | options = transferSpringboardActivityOptions(options); |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 4751 | Instrumentation.ActivityResult ar = |
| 4752 | mInstrumentation.execStartActivity( |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 4753 | this, mMainThread.getApplicationThread(), mToken, mEmbeddedID, |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 4754 | intent, -1, options, user); |
| 4755 | if (ar != null) { |
| 4756 | mMainThread.sendActivityResult( |
| 4757 | mToken, mEmbeddedID, -1, ar.getResultCode(), |
| 4758 | ar.getResultData()); |
| 4759 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4760 | cancelInputsAndStartExitTransition(options); |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 4761 | } |
| 4762 | |
| 4763 | /** |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 4764 | * Start a new activity as if it was started by the activity that started our |
| 4765 | * current activity. This is for the resolver and chooser activities, which operate |
| 4766 | * as intermediaries that dispatch their intent to the target the user selects -- to |
| 4767 | * do this, they must perform all security checks including permission grants as if |
| 4768 | * their launch had come from the original activity. |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 4769 | * @param intent The Intent to start. |
| 4770 | * @param options ActivityOptions or null. |
| 4771 | * @param ignoreTargetSecurity If true, the activity manager will not check whether the |
| 4772 | * caller it is doing the start is, is actually allowed to start the target activity. |
| 4773 | * If you set this to true, you must set an explicit component in the Intent and do any |
| 4774 | * appropriate security checks yourself. |
| 4775 | * @param userId The user the new activity should run as. |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 4776 | * @hide |
| 4777 | */ |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 4778 | public void startActivityAsCaller(Intent intent, @Nullable Bundle options, |
Alison Cichowlas | 76f0ccb | 2018-01-29 16:34:33 -0500 | [diff] [blame] | 4779 | boolean ignoreTargetSecurity, int userId) { |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 4780 | if (mParent != null) { |
| 4781 | throw new RuntimeException("Can't be called from a child"); |
| 4782 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 4783 | options = transferSpringboardActivityOptions(options); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 4784 | Instrumentation.ActivityResult ar = |
| 4785 | mInstrumentation.execStartActivityAsCaller( |
| 4786 | this, mMainThread.getApplicationThread(), mToken, this, |
Alison Cichowlas | 76f0ccb | 2018-01-29 16:34:33 -0500 | [diff] [blame] | 4787 | intent, -1, options, ignoreTargetSecurity, userId); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 4788 | if (ar != null) { |
| 4789 | mMainThread.sendActivityResult( |
| 4790 | mToken, mEmbeddedID, -1, ar.getResultCode(), |
| 4791 | ar.getResultData()); |
| 4792 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4793 | cancelInputsAndStartExitTransition(options); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 4794 | } |
| 4795 | |
| 4796 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4797 | * Same as calling {@link #startIntentSenderForResult(IntentSender, int, |
| 4798 | * Intent, int, int, int, Bundle)} with no options. |
| 4799 | * |
| 4800 | * @param intent The IntentSender to launch. |
| 4801 | * @param requestCode If >= 0, this code will be returned in |
| 4802 | * onActivityResult() when the activity exits. |
| 4803 | * @param fillInIntent If non-null, this will be provided as the |
| 4804 | * intent parameter to {@link IntentSender#sendIntent}. |
| 4805 | * @param flagsMask Intent flags in the original IntentSender that you |
| 4806 | * would like to change. |
| 4807 | * @param flagsValues Desired values for any bits set in |
| 4808 | * <var>flagsMask</var> |
| 4809 | * @param extraFlags Always set to 0. |
| 4810 | */ |
| 4811 | public void startIntentSenderForResult(IntentSender intent, int requestCode, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4812 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4813 | throws IntentSender.SendIntentException { |
| 4814 | startIntentSenderForResult(intent, requestCode, fillInIntent, flagsMask, |
| 4815 | flagsValues, extraFlags, null); |
| 4816 | } |
| 4817 | |
| 4818 | /** |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4819 | * Like {@link #startActivityForResult(Intent, int)}, but allowing you |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4820 | * to use a IntentSender to describe the activity to be started. If |
| 4821 | * the IntentSender is for an activity, that activity will be started |
| 4822 | * as if you had called the regular {@link #startActivityForResult(Intent, int)} |
| 4823 | * here; otherwise, its associated action will be executed (such as |
| 4824 | * sending a broadcast) as if you had called |
| 4825 | * {@link IntentSender#sendIntent IntentSender.sendIntent} on it. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4826 | * |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4827 | * @param intent The IntentSender to launch. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4828 | * @param requestCode If >= 0, this code will be returned in |
| 4829 | * onActivityResult() when the activity exits. |
| 4830 | * @param fillInIntent If non-null, this will be provided as the |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4831 | * intent parameter to {@link IntentSender#sendIntent}. |
| 4832 | * @param flagsMask Intent flags in the original IntentSender that you |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4833 | * would like to change. |
| 4834 | * @param flagsValues Desired values for any bits set in |
| 4835 | * <var>flagsMask</var> |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4836 | * @param extraFlags Always set to 0. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4837 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 4838 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4839 | * Context.startActivity(Intent, Bundle)} for more details. If options |
| 4840 | * have also been supplied by the IntentSender, options given here will |
| 4841 | * override any that conflict with those given by the IntentSender. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4842 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4843 | public void startIntentSenderForResult(IntentSender intent, int requestCode, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4844 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4845 | Bundle options) throws IntentSender.SendIntentException { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4846 | if (mParent == null) { |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 4847 | startIntentSenderForResultInner(intent, mEmbeddedID, requestCode, fillInIntent, |
| 4848 | flagsMask, flagsValues, options); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4849 | } else if (options != null) { |
| 4850 | mParent.startIntentSenderFromChild(this, intent, requestCode, |
| 4851 | fillInIntent, flagsMask, flagsValues, extraFlags, options); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4852 | } else { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4853 | // Note we want to go through this call for compatibility with |
| 4854 | // existing applications that may have overridden the method. |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4855 | mParent.startIntentSenderFromChild(this, intent, requestCode, |
| 4856 | fillInIntent, flagsMask, flagsValues, extraFlags); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4857 | } |
| 4858 | } |
| 4859 | |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 4860 | private void startIntentSenderForResultInner(IntentSender intent, String who, int requestCode, |
| 4861 | Intent fillInIntent, int flagsMask, int flagsValues, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4862 | Bundle options) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4863 | throws IntentSender.SendIntentException { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4864 | try { |
| 4865 | String resolvedType = null; |
| 4866 | if (fillInIntent != null) { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 4867 | fillInIntent.migrateExtraStreamToClipData(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 4868 | fillInIntent.prepareToLeaveProcess(this); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4869 | resolvedType = fillInIntent.resolveTypeIfNeeded(getContentResolver()); |
| 4870 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4871 | int result = ActivityManager.getService() |
Dianne Hackborn | 3e6e385 | 2017-05-19 16:12:08 -0700 | [diff] [blame] | 4872 | .startActivityIntentSender(mMainThread.getApplicationThread(), |
| 4873 | intent != null ? intent.getTarget() : null, |
| 4874 | intent != null ? intent.getWhitelistToken() : null, |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 4875 | fillInIntent, resolvedType, mToken, who, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4876 | requestCode, flagsMask, flagsValues, options); |
| 4877 | if (result == ActivityManager.START_CANCELED) { |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4878 | throw new IntentSender.SendIntentException(); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4879 | } |
| 4880 | Instrumentation.checkStartActivityResult(result, null); |
| 4881 | } catch (RemoteException e) { |
| 4882 | } |
| 4883 | if (requestCode >= 0) { |
| 4884 | // If this start is requesting a result, we can avoid making |
| 4885 | // the activity visible until the result is received. Setting |
| 4886 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 4887 | // activity hidden during this time, to avoid flickering. |
| 4888 | // This can only be done when a result is requested because |
| 4889 | // that guarantees we will get information back when the |
| 4890 | // activity is finished, no matter what happens to it. |
| 4891 | mStartedActivity = true; |
| 4892 | } |
| 4893 | } |
| 4894 | |
| 4895 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4896 | * Same as {@link #startActivity(Intent, Bundle)} with no options |
| 4897 | * specified. |
| 4898 | * |
| 4899 | * @param intent The intent to start. |
| 4900 | * |
| 4901 | * @throws android.content.ActivityNotFoundException |
| 4902 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 4903 | * @see #startActivity(Intent, Bundle) |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4904 | * @see #startActivityForResult |
| 4905 | */ |
| 4906 | @Override |
| 4907 | public void startActivity(Intent intent) { |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 4908 | this.startActivity(intent, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4909 | } |
| 4910 | |
| 4911 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4912 | * Launch a new activity. You will not receive any information about when |
| 4913 | * the activity exits. This implementation overrides the base version, |
| 4914 | * providing information about |
| 4915 | * the activity performing the launch. Because of this additional |
| 4916 | * information, the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag is not |
| 4917 | * required; if not specified, the new activity will be added to the |
| 4918 | * task of the caller. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4919 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4920 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 4921 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4922 | * |
| 4923 | * @param intent The intent to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4924 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 4925 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4926 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4927 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4928 | * @throws android.content.ActivityNotFoundException |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4929 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 4930 | * @see #startActivity(Intent) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4931 | * @see #startActivityForResult |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4932 | */ |
| 4933 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4934 | public void startActivity(Intent intent, @Nullable Bundle options) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4935 | if (options != null) { |
| 4936 | startActivityForResult(intent, -1, options); |
| 4937 | } else { |
| 4938 | // Note we want to go through this call for compatibility with |
| 4939 | // applications that may have overridden the method. |
| 4940 | startActivityForResult(intent, -1); |
| 4941 | } |
| 4942 | } |
| 4943 | |
| 4944 | /** |
| 4945 | * Same as {@link #startActivities(Intent[], Bundle)} with no options |
| 4946 | * specified. |
| 4947 | * |
| 4948 | * @param intents The intents to start. |
| 4949 | * |
| 4950 | * @throws android.content.ActivityNotFoundException |
| 4951 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 4952 | * @see #startActivities(Intent[], Bundle) |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4953 | * @see #startActivityForResult |
| 4954 | */ |
| 4955 | @Override |
| 4956 | public void startActivities(Intent[] intents) { |
| 4957 | startActivities(intents, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4958 | } |
| 4959 | |
| 4960 | /** |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4961 | * Launch a new activity. You will not receive any information about when |
| 4962 | * the activity exits. This implementation overrides the base version, |
| 4963 | * providing information about |
| 4964 | * the activity performing the launch. Because of this additional |
| 4965 | * information, the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag is not |
| 4966 | * required; if not specified, the new activity will be added to the |
| 4967 | * task of the caller. |
| 4968 | * |
| 4969 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 4970 | * if there was no Activity found to run the given Intent. |
| 4971 | * |
| 4972 | * @param intents The intents to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4973 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 4974 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4975 | * Context.startActivity(Intent, Bundle)} for more details. |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4976 | * |
| 4977 | * @throws android.content.ActivityNotFoundException |
| 4978 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 4979 | * @see #startActivities(Intent[]) |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4980 | * @see #startActivityForResult |
| 4981 | */ |
| 4982 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4983 | public void startActivities(Intent[] intents, @Nullable Bundle options) { |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4984 | mInstrumentation.execStartActivities(this, mMainThread.getApplicationThread(), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4985 | mToken, this, intents, options); |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4989 | * Same as calling {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)} |
| 4990 | * with no options. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4991 | * |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4992 | * @param intent The IntentSender to launch. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4993 | * @param fillInIntent If non-null, this will be provided as the |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4994 | * intent parameter to {@link IntentSender#sendIntent}. |
| 4995 | * @param flagsMask Intent flags in the original IntentSender that you |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4996 | * would like to change. |
| 4997 | * @param flagsValues Desired values for any bits set in |
| 4998 | * <var>flagsMask</var> |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4999 | * @param extraFlags Always set to 0. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5000 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5001 | public void startIntentSender(IntentSender intent, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5002 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5003 | throws IntentSender.SendIntentException { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5004 | startIntentSender(intent, fillInIntent, flagsMask, flagsValues, |
| 5005 | extraFlags, null); |
| 5006 | } |
| 5007 | |
| 5008 | /** |
| 5009 | * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender |
| 5010 | * to start; see |
| 5011 | * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int, Bundle)} |
| 5012 | * for more information. |
| 5013 | * |
| 5014 | * @param intent The IntentSender to launch. |
| 5015 | * @param fillInIntent If non-null, this will be provided as the |
| 5016 | * intent parameter to {@link IntentSender#sendIntent}. |
| 5017 | * @param flagsMask Intent flags in the original IntentSender that you |
| 5018 | * would like to change. |
| 5019 | * @param flagsValues Desired values for any bits set in |
| 5020 | * <var>flagsMask</var> |
| 5021 | * @param extraFlags Always set to 0. |
| 5022 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5023 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5024 | * Context.startActivity(Intent, Bundle)} for more details. If options |
| 5025 | * have also been supplied by the IntentSender, options given here will |
| 5026 | * override any that conflict with those given by the IntentSender. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5027 | */ |
| 5028 | public void startIntentSender(IntentSender intent, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5029 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5030 | Bundle options) throws IntentSender.SendIntentException { |
| 5031 | if (options != null) { |
| 5032 | startIntentSenderForResult(intent, -1, fillInIntent, flagsMask, |
| 5033 | flagsValues, extraFlags, options); |
| 5034 | } else { |
| 5035 | // Note we want to go through this call for compatibility with |
| 5036 | // applications that may have overridden the method. |
| 5037 | startIntentSenderForResult(intent, -1, fillInIntent, flagsMask, |
| 5038 | flagsValues, extraFlags); |
| 5039 | } |
| 5040 | } |
| 5041 | |
| 5042 | /** |
| 5043 | * Same as calling {@link #startActivityIfNeeded(Intent, int, Bundle)} |
| 5044 | * with no options. |
| 5045 | * |
| 5046 | * @param intent The intent to start. |
| 5047 | * @param requestCode If >= 0, this code will be returned in |
| 5048 | * onActivityResult() when the activity exits, as described in |
| 5049 | * {@link #startActivityForResult}. |
| 5050 | * |
| 5051 | * @return If a new activity was launched then true is returned; otherwise |
| 5052 | * false is returned and you must handle the Intent yourself. |
| 5053 | * |
| 5054 | * @see #startActivity |
| 5055 | * @see #startActivityForResult |
| 5056 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5057 | public boolean startActivityIfNeeded(@RequiresPermission @NonNull Intent intent, |
| 5058 | int requestCode) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5059 | return startActivityIfNeeded(intent, requestCode, null); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5060 | } |
| 5061 | |
| 5062 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5063 | * A special variation to launch an activity only if a new activity |
| 5064 | * instance is needed to handle the given Intent. In other words, this is |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5065 | * 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] | 5066 | * using the {@link Intent#FLAG_ACTIVITY_SINGLE_TOP} flag, or |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5067 | * singleTask or singleTop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5068 | * {@link android.R.styleable#AndroidManifestActivity_launchMode launchMode}, |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5069 | * and the activity |
| 5070 | * that handles <var>intent</var> is the same as your currently running |
| 5071 | * activity, then a new instance is not needed. In this case, instead of |
| 5072 | * the normal behavior of calling {@link #onNewIntent} this function will |
| 5073 | * return and you can handle the Intent yourself. |
| 5074 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5075 | * <p>This function can only be called from a top-level activity; if it is |
| 5076 | * called from a child activity, a runtime exception will be thrown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5077 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5078 | * @param intent The intent to start. |
| 5079 | * @param requestCode If >= 0, this code will be returned in |
| 5080 | * onActivityResult() when the activity exits, as described in |
| 5081 | * {@link #startActivityForResult}. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5082 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5083 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5084 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5085 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5086 | * @return If a new activity was launched then true is returned; otherwise |
| 5087 | * false is returned and you must handle the Intent yourself. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5088 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5089 | * @see #startActivity |
| 5090 | * @see #startActivityForResult |
| 5091 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5092 | public boolean startActivityIfNeeded(@RequiresPermission @NonNull Intent intent, |
| 5093 | int requestCode, @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5094 | if (mParent == null) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5095 | int result = ActivityManager.START_RETURN_INTENT_TO_CALLER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5096 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 5097 | Uri referrer = onProvideReferrer(); |
| 5098 | if (referrer != null) { |
| 5099 | intent.putExtra(Intent.EXTRA_REFERRER, referrer); |
| 5100 | } |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 5101 | intent.migrateExtraStreamToClipData(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5102 | intent.prepareToLeaveProcess(this); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5103 | result = ActivityManager.getService() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5104 | .startActivity(mMainThread.getApplicationThread(), getBasePackageName(), |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5105 | intent, intent.resolveTypeIfNeeded(getContentResolver()), mToken, |
| 5106 | mEmbeddedID, requestCode, ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
| 5107 | null, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5108 | } catch (RemoteException e) { |
| 5109 | // Empty |
| 5110 | } |
Siva Velusamy | 92a8b22 | 2012-03-09 16:24:04 -0800 | [diff] [blame] | 5111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5112 | Instrumentation.checkStartActivityResult(result, intent); |
Siva Velusamy | 92a8b22 | 2012-03-09 16:24:04 -0800 | [diff] [blame] | 5113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5114 | if (requestCode >= 0) { |
| 5115 | // If this start is requesting a result, we can avoid making |
| 5116 | // the activity visible until the result is received. Setting |
| 5117 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 5118 | // activity hidden during this time, to avoid flickering. |
| 5119 | // This can only be done when a result is requested because |
| 5120 | // that guarantees we will get information back when the |
| 5121 | // activity is finished, no matter what happens to it. |
| 5122 | mStartedActivity = true; |
| 5123 | } |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5124 | return result != ActivityManager.START_RETURN_INTENT_TO_CALLER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5125 | } |
| 5126 | |
| 5127 | throw new UnsupportedOperationException( |
| 5128 | "startActivityIfNeeded can only be called from a top-level activity"); |
| 5129 | } |
| 5130 | |
| 5131 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5132 | * Same as calling {@link #startNextMatchingActivity(Intent, Bundle)} with |
| 5133 | * no options. |
| 5134 | * |
| 5135 | * @param intent The intent to dispatch to the next activity. For |
| 5136 | * correct behavior, this must be the same as the Intent that started |
| 5137 | * your own activity; the only changes you can make are to the extras |
| 5138 | * inside of it. |
| 5139 | * |
| 5140 | * @return Returns a boolean indicating whether there was another Activity |
| 5141 | * to start: true if there was a next activity to start, false if there |
| 5142 | * wasn't. In general, if true is returned you will then want to call |
| 5143 | * finish() on yourself. |
| 5144 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5145 | public boolean startNextMatchingActivity(@RequiresPermission @NonNull Intent intent) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5146 | return startNextMatchingActivity(intent, null); |
| 5147 | } |
| 5148 | |
| 5149 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5150 | * Special version of starting an activity, for use when you are replacing |
| 5151 | * other activity components. You can use this to hand the Intent off |
| 5152 | * to the next Activity that can handle it. You typically call this in |
| 5153 | * {@link #onCreate} with the Intent returned by {@link #getIntent}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5154 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5155 | * @param intent The intent to dispatch to the next activity. For |
| 5156 | * correct behavior, this must be the same as the Intent that started |
| 5157 | * your own activity; the only changes you can make are to the extras |
| 5158 | * inside of it. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5159 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5160 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5161 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5162 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5163 | * @return Returns a boolean indicating whether there was another Activity |
| 5164 | * to start: true if there was a next activity to start, false if there |
| 5165 | * wasn't. In general, if true is returned you will then want to call |
| 5166 | * finish() on yourself. |
| 5167 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5168 | public boolean startNextMatchingActivity(@RequiresPermission @NonNull Intent intent, |
| 5169 | @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5170 | if (mParent == null) { |
| 5171 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 5172 | intent.migrateExtraStreamToClipData(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5173 | intent.prepareToLeaveProcess(this); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5174 | return ActivityManager.getService() |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5175 | .startNextMatchingActivity(mToken, intent, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5176 | } catch (RemoteException e) { |
| 5177 | // Empty |
| 5178 | } |
| 5179 | return false; |
| 5180 | } |
| 5181 | |
| 5182 | throw new UnsupportedOperationException( |
| 5183 | "startNextMatchingActivity can only be called from a top-level activity"); |
| 5184 | } |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5185 | |
| 5186 | /** |
| 5187 | * Same as calling {@link #startActivityFromChild(Activity, Intent, int, Bundle)} |
| 5188 | * with no options. |
| 5189 | * |
| 5190 | * @param child The activity making the call. |
| 5191 | * @param intent The intent to start. |
| 5192 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 5193 | * |
| 5194 | * @throws android.content.ActivityNotFoundException |
| 5195 | * |
| 5196 | * @see #startActivity |
| 5197 | * @see #startActivityForResult |
| 5198 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5199 | public void startActivityFromChild(@NonNull Activity child, @RequiresPermission Intent intent, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5200 | int requestCode) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 5201 | startActivityFromChild(child, intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5202 | } |
| 5203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5204 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5205 | * 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] | 5206 | * {@link #startActivity} or {@link #startActivityForResult} method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5207 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5208 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 5209 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5210 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5211 | * @param child The activity making the call. |
| 5212 | * @param intent The intent to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5213 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 5214 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5215 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5216 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5217 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5218 | * @throws android.content.ActivityNotFoundException |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5219 | * |
| 5220 | * @see #startActivity |
| 5221 | * @see #startActivityForResult |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5222 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5223 | public void startActivityFromChild(@NonNull Activity child, @RequiresPermission Intent intent, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5224 | int requestCode, @Nullable Bundle options) { |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5225 | options = transferSpringboardActivityOptions(options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5226 | Instrumentation.ActivityResult ar = |
| 5227 | mInstrumentation.execStartActivity( |
| 5228 | this, mMainThread.getApplicationThread(), mToken, child, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5229 | intent, requestCode, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5230 | if (ar != null) { |
| 5231 | mMainThread.sendActivityResult( |
| 5232 | mToken, child.mEmbeddedID, requestCode, |
| 5233 | ar.getResultCode(), ar.getResultData()); |
| 5234 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5235 | cancelInputsAndStartExitTransition(options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5236 | } |
| 5237 | |
| 5238 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5239 | * Same as calling {@link #startActivityFromFragment(Fragment, Intent, int, Bundle)} |
| 5240 | * with no options. |
| 5241 | * |
| 5242 | * @param fragment The fragment making the call. |
| 5243 | * @param intent The intent to start. |
| 5244 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 5245 | * |
| 5246 | * @throws android.content.ActivityNotFoundException |
| 5247 | * |
| 5248 | * @see Fragment#startActivity |
| 5249 | * @see Fragment#startActivityForResult |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 5250 | * |
| 5251 | * @deprecated Use {@link android.support.v4.app.FragmentActivity#startActivityFromFragment( |
| 5252 | * android.support.v4.app.Fragment,Intent,int)} |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5253 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 5254 | @Deprecated |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5255 | public void startActivityFromFragment(@NonNull Fragment fragment, |
| 5256 | @RequiresPermission Intent intent, int requestCode) { |
George Mount | abb63cb | 2014-06-23 11:17:58 -0700 | [diff] [blame] | 5257 | startActivityFromFragment(fragment, intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5261 | * This is called when a Fragment in this activity calls its |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5262 | * {@link Fragment#startActivity} or {@link Fragment#startActivityForResult} |
| 5263 | * method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5264 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5265 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 5266 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5267 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5268 | * @param fragment The fragment making the call. |
| 5269 | * @param intent The intent to start. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5270 | * @param requestCode Reply request code. < 0 if reply is not requested. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5271 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5272 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5273 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5274 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5275 | * @throws android.content.ActivityNotFoundException |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5276 | * |
| 5277 | * @see Fragment#startActivity |
| 5278 | * @see Fragment#startActivityForResult |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 5279 | * |
| 5280 | * @deprecated Use {@link android.support.v4.app.FragmentActivity#startActivityFromFragment( |
| 5281 | * android.support.v4.app.Fragment,Intent,int,Bundle)} |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5282 | */ |
Ian Lake | 0a1feb8 | 2017-11-13 10:26:46 -0800 | [diff] [blame] | 5283 | @Deprecated |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5284 | public void startActivityFromFragment(@NonNull Fragment fragment, |
| 5285 | @RequiresPermission Intent intent, int requestCode, @Nullable Bundle options) { |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5286 | startActivityForResult(fragment.mWho, intent, requestCode, options); |
| 5287 | } |
| 5288 | |
| 5289 | /** |
| 5290 | * @hide |
| 5291 | */ |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 5292 | public void startActivityAsUserFromFragment(@NonNull Fragment fragment, |
| 5293 | @RequiresPermission Intent intent, int requestCode, @Nullable Bundle options, |
| 5294 | UserHandle user) { |
| 5295 | startActivityForResultAsUser(intent, fragment.mWho, requestCode, options, user); |
| 5296 | } |
| 5297 | |
| 5298 | /** |
| 5299 | * @hide |
| 5300 | */ |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5301 | @Override |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 5302 | @UnsupportedAppUsage |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5303 | public void startActivityForResult( |
| 5304 | String who, Intent intent, int requestCode, @Nullable Bundle options) { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 5305 | Uri referrer = onProvideReferrer(); |
| 5306 | if (referrer != null) { |
| 5307 | intent.putExtra(Intent.EXTRA_REFERRER, referrer); |
| 5308 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5309 | options = transferSpringboardActivityOptions(options); |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5310 | Instrumentation.ActivityResult ar = |
| 5311 | mInstrumentation.execStartActivity( |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5312 | this, mMainThread.getApplicationThread(), mToken, who, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5313 | intent, requestCode, options); |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5314 | if (ar != null) { |
| 5315 | mMainThread.sendActivityResult( |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5316 | mToken, who, requestCode, |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5317 | ar.getResultCode(), ar.getResultData()); |
| 5318 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5319 | cancelInputsAndStartExitTransition(options); |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5320 | } |
| 5321 | |
| 5322 | /** |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5323 | * @hide |
| 5324 | */ |
| 5325 | @Override |
| 5326 | public boolean canStartActivityForResult() { |
| 5327 | return true; |
| 5328 | } |
| 5329 | |
| 5330 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5331 | * Same as calling {@link #startIntentSenderFromChild(Activity, IntentSender, |
| 5332 | * int, Intent, int, int, int, Bundle)} with no options. |
| 5333 | */ |
| 5334 | public void startIntentSenderFromChild(Activity child, IntentSender intent, |
| 5335 | int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, |
| 5336 | int extraFlags) |
| 5337 | throws IntentSender.SendIntentException { |
| 5338 | startIntentSenderFromChild(child, intent, requestCode, fillInIntent, |
| 5339 | flagsMask, flagsValues, extraFlags, null); |
| 5340 | } |
| 5341 | |
| 5342 | /** |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5343 | * Like {@link #startActivityFromChild(Activity, Intent, int)}, but |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5344 | * taking a IntentSender; see |
Dianne Hackborn | ae22c05 | 2009-09-17 18:46:22 -0700 | [diff] [blame] | 5345 | * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int)} |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5346 | * for more information. |
| 5347 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5348 | public void startIntentSenderFromChild(Activity child, IntentSender intent, |
| 5349 | int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5350 | int extraFlags, @Nullable Bundle options) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5351 | throws IntentSender.SendIntentException { |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 5352 | startIntentSenderForResultInner(intent, child.mEmbeddedID, requestCode, fillInIntent, |
| 5353 | flagsMask, flagsValues, options); |
| 5354 | } |
| 5355 | |
| 5356 | /** |
| 5357 | * Like {@link #startIntentSenderFromChild}, but taking a Fragment; see |
| 5358 | * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int)} |
| 5359 | * for more information. |
| 5360 | * |
| 5361 | * @hide |
| 5362 | */ |
| 5363 | public void startIntentSenderFromChildFragment(Fragment child, IntentSender intent, |
| 5364 | int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, |
| 5365 | int extraFlags, @Nullable Bundle options) |
| 5366 | throws IntentSender.SendIntentException { |
| 5367 | startIntentSenderForResultInner(intent, child.mWho, requestCode, fillInIntent, |
| 5368 | flagsMask, flagsValues, options); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5369 | } |
| 5370 | |
| 5371 | /** |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5372 | * Call immediately after one of the flavors of {@link #startActivity(Intent)} |
| 5373 | * or {@link #finish} to specify an explicit transition animation to |
| 5374 | * perform next. |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5375 | * |
| 5376 | * <p>As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN} an alternative |
| 5377 | * to using this with starting activities is to supply the desired animation |
| 5378 | * information through a {@link ActivityOptions} bundle to |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 5379 | * {@link #startActivity(Intent, Bundle)} or a related function. This allows |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5380 | * you to specify a custom animation even when starting an activity from |
| 5381 | * outside the context of the current top activity. |
| 5382 | * |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5383 | * @param enterAnim A resource ID of the animation resource to use for |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 5384 | * the incoming activity. Use 0 for no animation. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5385 | * @param exitAnim A resource ID of the animation resource to use for |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 5386 | * the outgoing activity. Use 0 for no animation. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5387 | */ |
| 5388 | public void overridePendingTransition(int enterAnim, int exitAnim) { |
| 5389 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5390 | ActivityManager.getService().overridePendingTransition( |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5391 | mToken, getPackageName(), enterAnim, exitAnim); |
| 5392 | } catch (RemoteException e) { |
| 5393 | } |
| 5394 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5395 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5396 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5397 | * Call this to set the result that your activity will return to its |
| 5398 | * caller. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5399 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5400 | * @param resultCode The result code to propagate back to the originating |
| 5401 | * activity, often RESULT_CANCELED or RESULT_OK |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5402 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5403 | * @see #RESULT_CANCELED |
| 5404 | * @see #RESULT_OK |
| 5405 | * @see #RESULT_FIRST_USER |
| 5406 | * @see #setResult(int, Intent) |
| 5407 | */ |
| 5408 | public final void setResult(int resultCode) { |
| 5409 | synchronized (this) { |
| 5410 | mResultCode = resultCode; |
| 5411 | mResultData = null; |
| 5412 | } |
| 5413 | } |
| 5414 | |
| 5415 | /** |
| 5416 | * Call this to set the result that your activity will return to its |
| 5417 | * caller. |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 5418 | * |
| 5419 | * <p>As of {@link android.os.Build.VERSION_CODES#GINGERBREAD}, the Intent |
| 5420 | * you supply here can have {@link Intent#FLAG_GRANT_READ_URI_PERMISSION |
| 5421 | * Intent.FLAG_GRANT_READ_URI_PERMISSION} and/or {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 5422 | * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} set. This will grant the |
| 5423 | * Activity receiving the result access to the specific URIs in the Intent. |
| 5424 | * Access will remain until the Activity has finished (it will remain across the hosting |
| 5425 | * process being killed and other temporary destruction) and will be added |
| 5426 | * to any existing set of URI permissions it already holds. |
| 5427 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5428 | * @param resultCode The result code to propagate back to the originating |
| 5429 | * activity, often RESULT_CANCELED or RESULT_OK |
| 5430 | * @param data The data to propagate back to the originating activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5431 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5432 | * @see #RESULT_CANCELED |
| 5433 | * @see #RESULT_OK |
| 5434 | * @see #RESULT_FIRST_USER |
| 5435 | * @see #setResult(int) |
| 5436 | */ |
| 5437 | public final void setResult(int resultCode, Intent data) { |
| 5438 | synchronized (this) { |
| 5439 | mResultCode = resultCode; |
| 5440 | mResultData = data; |
| 5441 | } |
| 5442 | } |
| 5443 | |
| 5444 | /** |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 5445 | * Return information about who launched this activity. If the launching Intent |
| 5446 | * contains an {@link android.content.Intent#EXTRA_REFERRER Intent.EXTRA_REFERRER}, |
| 5447 | * that will be returned as-is; otherwise, if known, an |
| 5448 | * {@link Intent#URI_ANDROID_APP_SCHEME android-app:} referrer URI containing the |
| 5449 | * package name that started the Intent will be returned. This may return null if no |
| 5450 | * referrer can be identified -- it is neither explicitly specified, nor is it known which |
| 5451 | * application package was involved. |
| 5452 | * |
| 5453 | * <p>If called while inside the handling of {@link #onNewIntent}, this function will |
| 5454 | * return the referrer that submitted that new intent to the activity. Otherwise, it |
| 5455 | * always returns the referrer of the original Intent.</p> |
| 5456 | * |
| 5457 | * <p>Note that this is <em>not</em> a security feature -- you can not trust the |
| 5458 | * referrer information, applications can spoof it.</p> |
| 5459 | */ |
| 5460 | @Nullable |
| 5461 | public Uri getReferrer() { |
| 5462 | Intent intent = getIntent(); |
Adam Powell | d3c63a6 | 2016-06-09 12:36:16 -0700 | [diff] [blame] | 5463 | try { |
| 5464 | Uri referrer = intent.getParcelableExtra(Intent.EXTRA_REFERRER); |
| 5465 | if (referrer != null) { |
| 5466 | return referrer; |
| 5467 | } |
| 5468 | String referrerName = intent.getStringExtra(Intent.EXTRA_REFERRER_NAME); |
| 5469 | if (referrerName != null) { |
| 5470 | return Uri.parse(referrerName); |
| 5471 | } |
| 5472 | } catch (BadParcelableException e) { |
| 5473 | Log.w(TAG, "Cannot read referrer from intent;" |
| 5474 | + " intent extras contain unknown custom Parcelable objects"); |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 5475 | } |
| 5476 | if (mReferrer != null) { |
| 5477 | return new Uri.Builder().scheme("android-app").authority(mReferrer).build(); |
| 5478 | } |
| 5479 | return null; |
| 5480 | } |
| 5481 | |
| 5482 | /** |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 5483 | * Override to generate the desired referrer for the content currently being shown |
| 5484 | * by the app. The default implementation returns null, meaning the referrer will simply |
| 5485 | * be the android-app: of the package name of this activity. Return a non-null Uri to |
| 5486 | * have that supplied as the {@link Intent#EXTRA_REFERRER} of any activities started from it. |
| 5487 | */ |
| 5488 | public Uri onProvideReferrer() { |
| 5489 | return null; |
| 5490 | } |
| 5491 | |
| 5492 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5493 | * Return the name of the package that invoked this activity. This is who |
| 5494 | * the data in {@link #setResult setResult()} will be sent to. You can |
| 5495 | * use this information to validate that the recipient is allowed to |
| 5496 | * receive the data. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5497 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 5498 | * <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] | 5499 | * did not use the {@link #startActivityForResult} |
| 5500 | * form that includes a request code), then the calling package will be |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 5501 | * null.</p> |
| 5502 | * |
| 5503 | * <p class="note">Note: prior to {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, |
| 5504 | * the result from this method was unstable. If the process hosting the calling |
| 5505 | * package was no longer running, it would return null instead of the proper package |
| 5506 | * name. You can use {@link #getCallingActivity()} and retrieve the package name |
| 5507 | * from that instead.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5508 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5509 | * @return The package of the activity that will receive your |
| 5510 | * reply, or null if none. |
| 5511 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5512 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5513 | public String getCallingPackage() { |
| 5514 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5515 | return ActivityManager.getService().getCallingPackage(mToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5516 | } catch (RemoteException e) { |
| 5517 | return null; |
| 5518 | } |
| 5519 | } |
| 5520 | |
| 5521 | /** |
| 5522 | * Return the name of the activity that invoked this activity. This is |
| 5523 | * who the data in {@link #setResult setResult()} will be sent to. You |
| 5524 | * can use this information to validate that the recipient is allowed to |
| 5525 | * receive the data. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5526 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 5527 | * <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] | 5528 | * did not use the {@link #startActivityForResult} |
| 5529 | * form that includes a request code), then the calling package will be |
| 5530 | * null. |
| 5531 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 5532 | * @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] | 5533 | * reply, or null if none. |
| 5534 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5535 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5536 | public ComponentName getCallingActivity() { |
| 5537 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5538 | return ActivityManager.getService().getCallingActivity(mToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5539 | } catch (RemoteException e) { |
| 5540 | return null; |
| 5541 | } |
| 5542 | } |
| 5543 | |
| 5544 | /** |
| 5545 | * Control whether this activity's main window is visible. This is intended |
| 5546 | * only for the special case of an activity that is not going to show a |
| 5547 | * UI itself, but can't just finish prior to onResume() because it needs |
| 5548 | * to wait for a service binding or such. Setting this to false allows |
| 5549 | * you to prevent your UI from being shown during that time. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5550 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5551 | * <p>The default value for this is taken from the |
| 5552 | * {@link android.R.attr#windowNoDisplay} attribute of the activity's theme. |
| 5553 | */ |
| 5554 | public void setVisible(boolean visible) { |
| 5555 | if (mVisibleFromClient != visible) { |
| 5556 | mVisibleFromClient = visible; |
| 5557 | if (mVisibleFromServer) { |
| 5558 | if (visible) makeVisible(); |
| 5559 | else mDecor.setVisibility(View.INVISIBLE); |
| 5560 | } |
| 5561 | } |
| 5562 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5564 | void makeVisible() { |
| 5565 | if (!mWindowAdded) { |
| 5566 | ViewManager wm = getWindowManager(); |
| 5567 | wm.addView(mDecor, getWindow().getAttributes()); |
| 5568 | mWindowAdded = true; |
| 5569 | } |
| 5570 | mDecor.setVisibility(View.VISIBLE); |
| 5571 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5573 | /** |
| 5574 | * Check to see whether this activity is in the process of finishing, |
| 5575 | * either because you called {@link #finish} on it or someone else |
| 5576 | * has requested that it finished. This is often used in |
| 5577 | * {@link #onPause} to determine whether the activity is simply pausing or |
| 5578 | * completely finishing. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5579 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5580 | * @return If the activity is finishing, returns true; else returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5581 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5582 | * @see #finish |
| 5583 | */ |
| 5584 | public boolean isFinishing() { |
| 5585 | return mFinished; |
| 5586 | } |
| 5587 | |
| 5588 | /** |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 5589 | * Returns true if the final {@link #onDestroy()} call has been made |
| 5590 | * on the Activity, so this instance is now dead. |
| 5591 | */ |
| 5592 | public boolean isDestroyed() { |
| 5593 | return mDestroyed; |
| 5594 | } |
| 5595 | |
| 5596 | /** |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 5597 | * Check to see whether this activity is in the process of being destroyed in order to be |
| 5598 | * recreated with a new configuration. This is often used in |
| 5599 | * {@link #onStop} to determine whether the state needs to be cleaned up or will be passed |
| 5600 | * on to the next instance of the activity via {@link #onRetainNonConfigurationInstance()}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5601 | * |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 5602 | * @return If the activity is being torn down in order to be recreated with a new configuration, |
| 5603 | * returns true; else returns false. |
| 5604 | */ |
| 5605 | public boolean isChangingConfigurations() { |
| 5606 | return mChangingConfigurations; |
| 5607 | } |
| 5608 | |
| 5609 | /** |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5610 | * Cause this Activity to be recreated with a new instance. This results |
| 5611 | * in essentially the same flow as when the Activity is created due to |
| 5612 | * a configuration change -- the current instance will go through its |
| 5613 | * lifecycle to {@link #onDestroy} and a new instance then created after it. |
| 5614 | */ |
| 5615 | public void recreate() { |
| 5616 | if (mParent != null) { |
| 5617 | throw new IllegalStateException("Can only be called on top-level activity"); |
| 5618 | } |
Wale Ogunwale | 0527d91 | 2018-05-16 17:23:48 -0700 | [diff] [blame] | 5619 | if (Looper.myLooper() != mMainThread.getLooper()) { |
| 5620 | throw new IllegalStateException("Must be called from main thread"); |
| 5621 | } |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 5622 | mMainThread.scheduleRelaunchActivity(mToken); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5623 | } |
| 5624 | |
| 5625 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 5626 | * Finishes the current activity and specifies whether to remove the task associated with this |
| 5627 | * activity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5628 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 5629 | @UnsupportedAppUsage |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 5630 | private void finish(int finishTask) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5631 | if (mParent == null) { |
| 5632 | int resultCode; |
| 5633 | Intent resultData; |
| 5634 | synchronized (this) { |
| 5635 | resultCode = mResultCode; |
| 5636 | resultData = mResultData; |
| 5637 | } |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 5638 | if (false) Log.v(TAG, "Finishing self: token=" + mToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5639 | try { |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 5640 | if (resultData != null) { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5641 | resultData.prepareToLeaveProcess(this); |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 5642 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5643 | if (ActivityManager.getService() |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 5644 | .finishActivity(mToken, resultCode, resultData, finishTask)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5645 | mFinished = true; |
| 5646 | } |
| 5647 | } catch (RemoteException e) { |
| 5648 | // Empty |
| 5649 | } |
| 5650 | } else { |
| 5651 | mParent.finishFromChild(this); |
| 5652 | } |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 5653 | |
| 5654 | // Activity was launched when user tapped a link in the Autofill Save UI - Save UI must |
| 5655 | // be restored now. |
| 5656 | if (mIntent != null && mIntent.hasExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN)) { |
| 5657 | getAutofillManager().onPendingSaveUi(AutofillManager.PENDING_UI_OPERATION_RESTORE, |
| 5658 | mIntent.getIBinderExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN)); |
| 5659 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5660 | } |
| 5661 | |
| 5662 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 5663 | * Call this when your activity is done and should be closed. The |
| 5664 | * ActivityResult is propagated back to whoever launched you via |
| 5665 | * onActivityResult(). |
| 5666 | */ |
| 5667 | public void finish() { |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 5668 | finish(DONT_FINISH_TASK_WITH_ACTIVITY); |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | /** |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 5672 | * Finish this activity as well as all activities immediately below it |
| 5673 | * in the current task that have the same affinity. This is typically |
| 5674 | * used when an application can be launched on to another task (such as |
| 5675 | * from an ACTION_VIEW of a content type it understands) and the user |
| 5676 | * has used the up navigation to switch out of the current task and in |
| 5677 | * to its own task. In this case, if the user has navigated down into |
| 5678 | * any other activities of the second application, all of those should |
| 5679 | * be removed from the original task as part of the task switch. |
| 5680 | * |
| 5681 | * <p>Note that this finish does <em>not</em> allow you to deliver results |
| 5682 | * to the previous activity, and an exception will be thrown if you are trying |
| 5683 | * to do so.</p> |
| 5684 | */ |
| 5685 | public void finishAffinity() { |
| 5686 | if (mParent != null) { |
| 5687 | throw new IllegalStateException("Can not be called from an embedded activity"); |
| 5688 | } |
| 5689 | if (mResultCode != RESULT_CANCELED || mResultData != null) { |
| 5690 | throw new IllegalStateException("Can not be called to deliver a result"); |
| 5691 | } |
| 5692 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5693 | if (ActivityManager.getService().finishActivityAffinity(mToken)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 5694 | mFinished = true; |
| 5695 | } |
| 5696 | } catch (RemoteException e) { |
| 5697 | // Empty |
| 5698 | } |
| 5699 | } |
| 5700 | |
| 5701 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5702 | * 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] | 5703 | * {@link #finish} method. The default implementation simply calls |
| 5704 | * finish() on this activity (the parent), finishing the entire group. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5705 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5706 | * @param child The activity making the call. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5707 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5708 | * @see #finish |
| 5709 | */ |
| 5710 | public void finishFromChild(Activity child) { |
| 5711 | finish(); |
| 5712 | } |
| 5713 | |
| 5714 | /** |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 5715 | * Reverses the Activity Scene entry Transition and triggers the calling Activity |
| 5716 | * to reverse its exit Transition. When the exit Transition completes, |
| 5717 | * {@link #finish()} is called. If no entry Transition was used, finish() is called |
| 5718 | * immediately and the Activity exit Transition is run. |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5719 | * @see android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, android.util.Pair[]) |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 5720 | */ |
Craig Mautner | 73f843d | 2014-05-19 09:42:28 -0700 | [diff] [blame] | 5721 | public void finishAfterTransition() { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5722 | if (!mActivityTransitionState.startExitBackTransition(this)) { |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 5723 | finish(); |
| 5724 | } |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 5725 | } |
| 5726 | |
| 5727 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5728 | * Force finish another activity that you had previously started with |
| 5729 | * {@link #startActivityForResult}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5730 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5731 | * @param requestCode The request code of the activity that you had |
| 5732 | * given to startActivityForResult(). If there are multiple |
| 5733 | * activities started with this request code, they |
| 5734 | * will all be finished. |
| 5735 | */ |
| 5736 | public void finishActivity(int requestCode) { |
| 5737 | if (mParent == null) { |
| 5738 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5739 | ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5740 | .finishSubActivity(mToken, mEmbeddedID, requestCode); |
| 5741 | } catch (RemoteException e) { |
| 5742 | // Empty |
| 5743 | } |
| 5744 | } else { |
| 5745 | mParent.finishActivityFromChild(this, requestCode); |
| 5746 | } |
| 5747 | } |
| 5748 | |
| 5749 | /** |
| 5750 | * This is called when a child activity of this one calls its |
| 5751 | * finishActivity(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5752 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5753 | * @param child The activity making the call. |
| 5754 | * @param requestCode Request code that had been used to start the |
| 5755 | * activity. |
| 5756 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5757 | public void finishActivityFromChild(@NonNull Activity child, int requestCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5758 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5759 | ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5760 | .finishSubActivity(mToken, child.mEmbeddedID, requestCode); |
| 5761 | } catch (RemoteException e) { |
| 5762 | // Empty |
| 5763 | } |
| 5764 | } |
| 5765 | |
| 5766 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 5767 | * 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] | 5768 | * removed as a part of finishing the root activity of the task. |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 5769 | */ |
| 5770 | public void finishAndRemoveTask() { |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 5771 | finish(FINISH_TASK_WITH_ROOT_ACTIVITY); |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 5772 | } |
| 5773 | |
| 5774 | /** |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5775 | * Ask that the local app instance of this activity be released to free up its memory. |
| 5776 | * This is asking for the activity to be destroyed, but does <b>not</b> finish the activity -- |
| 5777 | * a new instance of the activity will later be re-created if needed due to the user |
| 5778 | * navigating back to it. |
| 5779 | * |
| 5780 | * @return Returns true if the activity was in a state that it has started the process |
| 5781 | * of destroying its current instance; returns false if for any reason this could not |
| 5782 | * be done: it is currently visible to the user, it is already being destroyed, it is |
| 5783 | * being finished, it hasn't yet saved its state, etc. |
| 5784 | */ |
| 5785 | public boolean releaseInstance() { |
| 5786 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5787 | return ActivityManager.getService().releaseActivityInstance(mToken); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5788 | } catch (RemoteException e) { |
| 5789 | // Empty |
| 5790 | } |
| 5791 | return false; |
| 5792 | } |
| 5793 | |
| 5794 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5795 | * Called when an activity you launched exits, giving you the requestCode |
| 5796 | * you started it with, the resultCode it returned, and any additional |
| 5797 | * data from it. The <var>resultCode</var> will be |
| 5798 | * {@link #RESULT_CANCELED} if the activity explicitly returned that, |
| 5799 | * didn't return any result, or crashed during its operation. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5800 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5801 | * <p>You will receive this call immediately before onResume() when your |
| 5802 | * activity is re-starting. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5803 | * |
Ricardo Cervera | 92f6a74 | 2014-04-04 11:17:06 -0700 | [diff] [blame] | 5804 | * <p>This method is never invoked if your activity sets |
| 5805 | * {@link android.R.styleable#AndroidManifestActivity_noHistory noHistory} to |
| 5806 | * <code>true</code>. |
Ricardo Cervera | 93f94c2 | 2015-01-16 09:54:30 -0800 | [diff] [blame] | 5807 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5808 | * @param requestCode The integer request code originally supplied to |
| 5809 | * startActivityForResult(), allowing you to identify who this |
| 5810 | * result came from. |
| 5811 | * @param resultCode The integer result code returned by the child activity |
| 5812 | * through its setResult(). |
| 5813 | * @param data An Intent, which can return result data to the caller |
| 5814 | * (various data can be attached to Intent "extras"). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5815 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5816 | * @see #startActivityForResult |
| 5817 | * @see #createPendingResult |
| 5818 | * @see #setResult(int) |
| 5819 | */ |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5820 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5821 | } |
| 5822 | |
| 5823 | /** |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5824 | * Called when an activity you launched with an activity transition exposes this |
| 5825 | * Activity through a returning activity transition, giving you the resultCode |
| 5826 | * and any additional data from it. This method will only be called if the activity |
| 5827 | * 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] | 5828 | * transitions with {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5829 | * |
| 5830 | * <p>The purpose of this function is to let the called Activity send a hint about |
| 5831 | * its state so that this underlying Activity can prepare to be exposed. A call to |
| 5832 | * this method does not guarantee that the called Activity has or will be exiting soon. |
| 5833 | * It only indicates that it will expose this Activity's Window and it has |
| 5834 | * some data to pass to prepare it.</p> |
| 5835 | * |
| 5836 | * @param resultCode The integer result code returned by the child activity |
| 5837 | * through its setResult(). |
| 5838 | * @param data An Intent, which can return result data to the caller |
| 5839 | * (various data can be attached to Intent "extras"). |
| 5840 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 5841 | public void onActivityReenter(int resultCode, Intent data) { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5842 | } |
| 5843 | |
| 5844 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5845 | * Create a new PendingIntent object which you can hand to others |
| 5846 | * for them to use to send result data back to your |
| 5847 | * {@link #onActivityResult} callback. The created object will be either |
| 5848 | * one-shot (becoming invalid after a result is sent back) or multiple |
| 5849 | * (allowing any number of results to be sent through it). |
| 5850 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5851 | * @param requestCode Private request code for the sender that will be |
| 5852 | * associated with the result data when it is returned. The sender can not |
| 5853 | * modify this value, allowing you to identify incoming results. |
| 5854 | * @param data Default data to supply in the result, which may be modified |
| 5855 | * by the sender. |
| 5856 | * @param flags May be {@link PendingIntent#FLAG_ONE_SHOT PendingIntent.FLAG_ONE_SHOT}, |
| 5857 | * {@link PendingIntent#FLAG_NO_CREATE PendingIntent.FLAG_NO_CREATE}, |
| 5858 | * {@link PendingIntent#FLAG_CANCEL_CURRENT PendingIntent.FLAG_CANCEL_CURRENT}, |
| 5859 | * {@link PendingIntent#FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT}, |
| 5860 | * or any of the flags as supported by |
| 5861 | * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts |
| 5862 | * of the intent that can be supplied when the actual send happens. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5863 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5864 | * @return Returns an existing or new PendingIntent matching the given |
| 5865 | * parameters. May return null only if |
| 5866 | * {@link PendingIntent#FLAG_NO_CREATE PendingIntent.FLAG_NO_CREATE} has been |
| 5867 | * supplied. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5868 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5869 | * @see PendingIntent |
| 5870 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5871 | public PendingIntent createPendingResult(int requestCode, @NonNull Intent data, |
| 5872 | @PendingIntent.Flags int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5873 | String packageName = getPackageName(); |
| 5874 | try { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5875 | data.prepareToLeaveProcess(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5876 | IIntentSender target = |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5877 | ActivityManager.getService().getIntentSender( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5878 | ActivityManager.INTENT_SENDER_ACTIVITY_RESULT, packageName, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5879 | mParent == null ? mToken : mParent.mToken, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 5880 | mEmbeddedID, requestCode, new Intent[] { data }, null, flags, null, |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 5881 | getUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5882 | return target != null ? new PendingIntent(target) : null; |
| 5883 | } catch (RemoteException e) { |
| 5884 | // Empty |
| 5885 | } |
| 5886 | return null; |
| 5887 | } |
| 5888 | |
| 5889 | /** |
| 5890 | * Change the desired orientation of this activity. If the activity |
| 5891 | * is currently in the foreground or otherwise impacting the screen |
| 5892 | * orientation, the screen will immediately be changed (possibly causing |
| 5893 | * the activity to be restarted). Otherwise, this will be used the next |
| 5894 | * time the activity is visible. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5895 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5896 | * @param requestedOrientation An orientation constant as used in |
| 5897 | * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}. |
| 5898 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5899 | public void setRequestedOrientation(@ActivityInfo.ScreenOrientation int requestedOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5900 | if (mParent == null) { |
| 5901 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5902 | ActivityManager.getService().setRequestedOrientation( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5903 | mToken, requestedOrientation); |
| 5904 | } catch (RemoteException e) { |
| 5905 | // Empty |
| 5906 | } |
| 5907 | } else { |
| 5908 | mParent.setRequestedOrientation(requestedOrientation); |
| 5909 | } |
| 5910 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5912 | /** |
| 5913 | * Return the current requested orientation of the activity. This will |
| 5914 | * either be the orientation requested in its component's manifest, or |
| 5915 | * the last requested orientation given to |
| 5916 | * {@link #setRequestedOrientation(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5917 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5918 | * @return Returns an orientation constant as used in |
| 5919 | * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}. |
| 5920 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5921 | @ActivityInfo.ScreenOrientation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5922 | public int getRequestedOrientation() { |
| 5923 | if (mParent == null) { |
| 5924 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5925 | return ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5926 | .getRequestedOrientation(mToken); |
| 5927 | } catch (RemoteException e) { |
| 5928 | // Empty |
| 5929 | } |
| 5930 | } else { |
| 5931 | return mParent.getRequestedOrientation(); |
| 5932 | } |
| 5933 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 5934 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5936 | /** |
| 5937 | * Return the identifier of the task this activity is in. This identifier |
| 5938 | * will remain the same for the lifetime of the activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5939 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5940 | * @return Task identifier, an opaque integer. |
| 5941 | */ |
| 5942 | public int getTaskId() { |
| 5943 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5944 | return ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5945 | .getTaskForActivity(mToken, false); |
| 5946 | } catch (RemoteException e) { |
| 5947 | return -1; |
| 5948 | } |
| 5949 | } |
| 5950 | |
| 5951 | /** |
| 5952 | * Return whether this activity is the root of a task. The root is the |
| 5953 | * first activity in a task. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5954 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5955 | * @return True if this is the root activity, else false. |
| 5956 | */ |
Winson Chung | 4d8681f | 2017-05-23 16:22:08 -0700 | [diff] [blame] | 5957 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5958 | public boolean isTaskRoot() { |
| 5959 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5960 | return ActivityManager.getService().getTaskForActivity(mToken, true) >= 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5961 | } catch (RemoteException e) { |
| 5962 | return false; |
| 5963 | } |
| 5964 | } |
| 5965 | |
| 5966 | /** |
| 5967 | * Move the task containing this activity to the back of the activity |
| 5968 | * stack. The activity's order within the task is unchanged. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5969 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5970 | * @param nonRoot If false then this only works if the activity is the root |
| 5971 | * of a task; if true it will work for any activity in |
| 5972 | * a task. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5973 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5974 | * @return If the task was moved (or it was already at the |
| 5975 | * back) true is returned, else false. |
| 5976 | */ |
| 5977 | public boolean moveTaskToBack(boolean nonRoot) { |
| 5978 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5979 | return ActivityManager.getService().moveActivityTaskToBack( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5980 | mToken, nonRoot); |
| 5981 | } catch (RemoteException e) { |
| 5982 | // Empty |
| 5983 | } |
| 5984 | return false; |
| 5985 | } |
| 5986 | |
| 5987 | /** |
| 5988 | * Returns class name for this activity with the package prefix removed. |
| 5989 | * This is the default name used to read and write settings. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5990 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5991 | * @return The local class name. |
| 5992 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5993 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5994 | public String getLocalClassName() { |
| 5995 | final String pkg = getPackageName(); |
| 5996 | final String cls = mComponent.getClassName(); |
| 5997 | int packageLen = pkg.length(); |
| 5998 | if (!cls.startsWith(pkg) || cls.length() <= packageLen |
| 5999 | || cls.charAt(packageLen) != '.') { |
| 6000 | return cls; |
| 6001 | } |
| 6002 | return cls.substring(packageLen+1); |
| 6003 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6004 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6005 | /** |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 6006 | * Returns the complete component name of this activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6007 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6008 | * @return Returns the complete component name for this activity |
| 6009 | */ |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 6010 | public ComponentName getComponentName() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6011 | return mComponent; |
| 6012 | } |
| 6013 | |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 6014 | /** @hide */ |
| 6015 | @Override |
| 6016 | public final ComponentName autofillClientGetComponentName() { |
| 6017 | return getComponentName(); |
| 6018 | } |
| 6019 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6020 | /** |
| 6021 | * Retrieve a {@link SharedPreferences} object for accessing preferences |
| 6022 | * that are private to this activity. This simply calls the underlying |
| 6023 | * {@link #getSharedPreferences(String, int)} method by passing in this activity's |
| 6024 | * class name as the preferences name. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6025 | * |
| 6026 | * @param mode Operating mode. Use {@link #MODE_PRIVATE} for the default |
Jeff Sharkey | 634dc42 | 2016-01-30 17:44:15 -0700 | [diff] [blame] | 6027 | * operation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6028 | * |
| 6029 | * @return Returns the single SharedPreferences instance that can be used |
| 6030 | * to retrieve and modify the preference values. |
| 6031 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 6032 | public SharedPreferences getPreferences(@Context.PreferencesMode int mode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6033 | return getSharedPreferences(getLocalClassName(), mode); |
| 6034 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6035 | |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 6036 | private void ensureSearchManager() { |
| 6037 | if (mSearchManager != null) { |
| 6038 | return; |
| 6039 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6040 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 6041 | try { |
| 6042 | mSearchManager = new SearchManager(this, null); |
| 6043 | } catch (ServiceNotFoundException e) { |
| 6044 | throw new IllegalStateException(e); |
| 6045 | } |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 6046 | } |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6047 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6048 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6049 | public Object getSystemService(@ServiceName @NonNull String name) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6050 | if (getBaseContext() == null) { |
| 6051 | throw new IllegalStateException( |
| 6052 | "System services not available to Activities before onCreate()"); |
| 6053 | } |
| 6054 | |
| 6055 | if (WINDOW_SERVICE.equals(name)) { |
| 6056 | return mWindowManager; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 6057 | } else if (SEARCH_SERVICE.equals(name)) { |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 6058 | ensureSearchManager(); |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 6059 | return mSearchManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6060 | } |
| 6061 | return super.getSystemService(name); |
| 6062 | } |
| 6063 | |
| 6064 | /** |
| 6065 | * Change the title associated with this activity. If this is a |
| 6066 | * top-level activity, the title for its window will change. If it |
| 6067 | * is an embedded activity, the parent can do whatever it wants |
| 6068 | * with it. |
| 6069 | */ |
| 6070 | public void setTitle(CharSequence title) { |
| 6071 | mTitle = title; |
| 6072 | onTitleChanged(title, mTitleColor); |
| 6073 | |
| 6074 | if (mParent != null) { |
| 6075 | mParent.onChildTitleChanged(this, title); |
| 6076 | } |
| 6077 | } |
| 6078 | |
| 6079 | /** |
| 6080 | * Change the title associated with this activity. If this is a |
| 6081 | * top-level activity, the title for its window will change. If it |
| 6082 | * is an embedded activity, the parent can do whatever it wants |
| 6083 | * with it. |
| 6084 | */ |
| 6085 | public void setTitle(int titleId) { |
| 6086 | setTitle(getText(titleId)); |
| 6087 | } |
| 6088 | |
Alan Viverette | 2525d9c | 2013-11-15 14:42:19 -0800 | [diff] [blame] | 6089 | /** |
| 6090 | * Change the color of the title associated with this activity. |
| 6091 | * <p> |
| 6092 | * This method is deprecated starting in API Level 11 and replaced by action |
| 6093 | * bar styles. For information on styling the Action Bar, read the <a |
| 6094 | * href="{@docRoot} guide/topics/ui/actionbar.html">Action Bar</a> developer |
| 6095 | * guide. |
| 6096 | * |
| 6097 | * @deprecated Use action bar styles instead. |
| 6098 | */ |
| 6099 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6100 | public void setTitleColor(int textColor) { |
| 6101 | mTitleColor = textColor; |
| 6102 | onTitleChanged(mTitle, textColor); |
| 6103 | } |
| 6104 | |
| 6105 | public final CharSequence getTitle() { |
| 6106 | return mTitle; |
| 6107 | } |
| 6108 | |
| 6109 | public final int getTitleColor() { |
| 6110 | return mTitleColor; |
| 6111 | } |
| 6112 | |
| 6113 | protected void onTitleChanged(CharSequence title, int color) { |
| 6114 | if (mTitleReady) { |
| 6115 | final Window win = getWindow(); |
| 6116 | if (win != null) { |
| 6117 | win.setTitle(title); |
| 6118 | if (color != 0) { |
| 6119 | win.setTitleColor(color); |
| 6120 | } |
| 6121 | } |
Adam Powell | af2d859 | 2014-08-26 18:06:40 -0700 | [diff] [blame] | 6122 | if (mActionBar != null) { |
| 6123 | mActionBar.setWindowTitle(title); |
| 6124 | } |
Adam Powell | a557fdc | 2014-08-21 18:05:53 -0700 | [diff] [blame] | 6125 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6126 | } |
| 6127 | |
| 6128 | protected void onChildTitleChanged(Activity childActivity, CharSequence title) { |
| 6129 | } |
| 6130 | |
| 6131 | /** |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 6132 | * Sets information describing the task with this activity for presentation inside the Recents |
| 6133 | * System UI. When {@link ActivityManager#getRecentTasks} is called, the activities of each task |
| 6134 | * are traversed in order from the topmost activity to the bottommost. The traversal continues |
| 6135 | * for each property until a suitable value is found. For each task the taskDescription will be |
| 6136 | * returned in {@link android.app.ActivityManager.TaskDescription}. |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6137 | * |
| 6138 | * @see ActivityManager#getRecentTasks |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 6139 | * @see android.app.ActivityManager.TaskDescription |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6140 | * |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 6141 | * @param taskDescription The TaskDescription properties that describe the task with this activity |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6142 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 6143 | public void setTaskDescription(ActivityManager.TaskDescription taskDescription) { |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 6144 | if (mTaskDescription != taskDescription) { |
Jorim Jaggi | f4156ea | 2017-04-10 18:39:04 -0700 | [diff] [blame] | 6145 | mTaskDescription.copyFromPreserveHiddenFields(taskDescription); |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 6146 | // Scale the icon down to something reasonable if it is provided |
| 6147 | if (taskDescription.getIconFilename() == null && taskDescription.getIcon() != null) { |
| 6148 | final int size = ActivityManager.getLauncherLargeIconSizeInner(this); |
| 6149 | final Bitmap icon = Bitmap.createScaledBitmap(taskDescription.getIcon(), size, size, |
| 6150 | true); |
| 6151 | mTaskDescription.setIcon(icon); |
| 6152 | } |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6153 | } |
| 6154 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6155 | ActivityManager.getService().setTaskDescription(mToken, mTaskDescription); |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 6156 | } catch (RemoteException e) { |
| 6157 | } |
| 6158 | } |
| 6159 | |
| 6160 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6161 | * Sets the visibility of the progress bar in the title. |
| 6162 | * <p> |
| 6163 | * In order for the progress bar to be shown, the feature must be requested |
| 6164 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6165 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6166 | * @param visible Whether to show the progress bars in the title. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6167 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6168 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6169 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6170 | public final void setProgressBarVisibility(boolean visible) { |
| 6171 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, visible ? Window.PROGRESS_VISIBILITY_ON : |
| 6172 | Window.PROGRESS_VISIBILITY_OFF); |
| 6173 | } |
| 6174 | |
| 6175 | /** |
| 6176 | * Sets the visibility of the indeterminate progress bar in the title. |
| 6177 | * <p> |
| 6178 | * In order for the progress bar to be shown, the feature must be requested |
| 6179 | * via {@link #requestWindowFeature(int)}. |
| 6180 | * |
| 6181 | * @param visible Whether to show the progress bars in the title. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6182 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6183 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6184 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6185 | public final void setProgressBarIndeterminateVisibility(boolean visible) { |
| 6186 | getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, |
| 6187 | visible ? Window.PROGRESS_VISIBILITY_ON : Window.PROGRESS_VISIBILITY_OFF); |
| 6188 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6189 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6190 | /** |
| 6191 | * Sets whether the horizontal progress bar in the title should be indeterminate (the circular |
| 6192 | * is always indeterminate). |
| 6193 | * <p> |
| 6194 | * In order for the progress bar to be shown, the feature must be requested |
| 6195 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6196 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6197 | * @param indeterminate Whether the horizontal progress bar should be indeterminate. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6198 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6199 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6200 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6201 | public final void setProgressBarIndeterminate(boolean indeterminate) { |
| 6202 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 6203 | indeterminate ? Window.PROGRESS_INDETERMINATE_ON |
| 6204 | : Window.PROGRESS_INDETERMINATE_OFF); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6205 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6206 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6207 | /** |
| 6208 | * Sets the progress for the progress bars in the title. |
| 6209 | * <p> |
| 6210 | * In order for the progress bar to be shown, the feature must be requested |
| 6211 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6212 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6213 | * @param progress The progress for the progress bar. Valid ranges are from |
| 6214 | * 0 to 10000 (both inclusive). If 10000 is given, the progress |
| 6215 | * bar will be completely filled and will fade out. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6216 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6217 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6218 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6219 | public final void setProgress(int progress) { |
| 6220 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, progress + Window.PROGRESS_START); |
| 6221 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6223 | /** |
| 6224 | * Sets the secondary progress for the progress bar in the title. This |
| 6225 | * progress is drawn between the primary progress (set via |
| 6226 | * {@link #setProgress(int)} and the background. It can be ideal for media |
| 6227 | * scenarios such as showing the buffering progress while the default |
| 6228 | * progress shows the play progress. |
| 6229 | * <p> |
| 6230 | * In order for the progress bar to be shown, the feature must be requested |
| 6231 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6232 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6233 | * @param secondaryProgress The secondary progress for the progress bar. Valid ranges are from |
| 6234 | * 0 to 10000 (both inclusive). |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6235 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6236 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6237 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6238 | public final void setSecondaryProgress(int secondaryProgress) { |
| 6239 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, |
| 6240 | secondaryProgress + Window.PROGRESS_SECONDARY_START); |
| 6241 | } |
| 6242 | |
| 6243 | /** |
| 6244 | * Suggests an audio stream whose volume should be changed by the hardware |
| 6245 | * volume controls. |
| 6246 | * <p> |
| 6247 | * The suggested audio stream will be tied to the window of this Activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6248 | * Volume requests which are received while the Activity is in the |
| 6249 | * foreground will affect this stream. |
| 6250 | * <p> |
| 6251 | * It is not guaranteed that the hardware volume controls will always change |
| 6252 | * this stream's volume (for example, if a call is in progress, its stream's |
| 6253 | * volume may be changed instead). To reset back to the default, use |
| 6254 | * {@link AudioManager#USE_DEFAULT_STREAM_TYPE}. |
| 6255 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6256 | * @param streamType The type of the audio stream whose volume should be |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6257 | * changed by the hardware volume controls. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6258 | */ |
| 6259 | public final void setVolumeControlStream(int streamType) { |
| 6260 | getWindow().setVolumeControlStream(streamType); |
| 6261 | } |
| 6262 | |
| 6263 | /** |
| 6264 | * Gets the suggested audio stream whose volume should be changed by the |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6265 | * hardware volume controls. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6266 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6267 | * @return The suggested audio stream type whose volume should be changed by |
| 6268 | * the hardware volume controls. |
| 6269 | * @see #setVolumeControlStream(int) |
| 6270 | */ |
| 6271 | public final int getVolumeControlStream() { |
| 6272 | return getWindow().getVolumeControlStream(); |
| 6273 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6274 | |
| 6275 | /** |
| 6276 | * Sets a {@link MediaController} to send media keys and volume changes to. |
| 6277 | * <p> |
| 6278 | * The controller will be tied to the window of this Activity. Media key and |
| 6279 | * volume events which are received while the Activity is in the foreground |
| 6280 | * will be forwarded to the controller and used to invoke transport controls |
| 6281 | * or adjust the volume. This may be used instead of or in addition to |
| 6282 | * {@link #setVolumeControlStream} to affect a specific session instead of a |
| 6283 | * specific stream. |
| 6284 | * <p> |
| 6285 | * It is not guaranteed that the hardware volume controls will always change |
| 6286 | * this session's volume (for example, if a call is in progress, its |
| 6287 | * stream's volume may be changed instead). To reset back to the default use |
| 6288 | * null as the controller. |
| 6289 | * |
| 6290 | * @param controller The controller for the session which should receive |
| 6291 | * media keys and volume changes. |
| 6292 | */ |
| 6293 | public final void setMediaController(MediaController controller) { |
| 6294 | getWindow().setMediaController(controller); |
| 6295 | } |
| 6296 | |
| 6297 | /** |
| 6298 | * Gets the controller which should be receiving media key and volume events |
| 6299 | * while this activity is in the foreground. |
| 6300 | * |
| 6301 | * @return The controller which should receive events. |
| 6302 | * @see #setMediaController(android.media.session.MediaController) |
| 6303 | */ |
| 6304 | public final MediaController getMediaController() { |
| 6305 | return getWindow().getMediaController(); |
| 6306 | } |
| 6307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6308 | /** |
| 6309 | * Runs the specified action on the UI thread. If the current thread is the UI |
| 6310 | * thread, then the action is executed immediately. If the current thread is |
| 6311 | * not the UI thread, the action is posted to the event queue of the UI thread. |
| 6312 | * |
| 6313 | * @param action the action to run on the UI thread |
| 6314 | */ |
| 6315 | public final void runOnUiThread(Runnable action) { |
| 6316 | if (Thread.currentThread() != mUiThread) { |
| 6317 | mHandler.post(action); |
| 6318 | } else { |
| 6319 | action.run(); |
| 6320 | } |
| 6321 | } |
| 6322 | |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 6323 | /** @hide */ |
| 6324 | @Override |
| 6325 | public final void autofillClientRunOnUiThread(Runnable action) { |
| 6326 | runOnUiThread(action); |
| 6327 | } |
| 6328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6329 | /** |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6330 | * Standard implementation of |
| 6331 | * {@link android.view.LayoutInflater.Factory#onCreateView} used when |
| 6332 | * inflating with the LayoutInflater returned by {@link #getSystemService}. |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6333 | * This implementation does nothing and is for |
| 6334 | * pre-{@link android.os.Build.VERSION_CODES#HONEYCOMB} apps. Newer apps |
| 6335 | * should use {@link #onCreateView(View, String, Context, AttributeSet)}. |
| 6336 | * |
| 6337 | * @see android.view.LayoutInflater#createView |
| 6338 | * @see android.view.Window#getLayoutInflater |
| 6339 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6340 | @Nullable |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6341 | public View onCreateView(String name, Context context, AttributeSet attrs) { |
| 6342 | return null; |
| 6343 | } |
| 6344 | |
| 6345 | /** |
| 6346 | * Standard implementation of |
| 6347 | * {@link android.view.LayoutInflater.Factory2#onCreateView(View, String, Context, AttributeSet)} |
| 6348 | * used when inflating with the LayoutInflater returned by {@link #getSystemService}. |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6349 | * This implementation handles <fragment> tags to embed fragments inside |
| 6350 | * of the activity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6351 | * |
| 6352 | * @see android.view.LayoutInflater#createView |
| 6353 | * @see android.view.Window#getLayoutInflater |
| 6354 | */ |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6355 | public View onCreateView(View parent, String name, Context context, AttributeSet attrs) { |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6356 | if (!"fragment".equals(name)) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6357 | return onCreateView(name, context, attrs); |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6358 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6359 | |
Adam Powell | 371a809 | 2014-06-20 12:51:12 -0700 | [diff] [blame] | 6360 | return mFragments.onCreateView(parent, name, context, attrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6361 | } |
| 6362 | |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6363 | /** |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6364 | * 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] | 6365 | * you run "adb shell dumpsys activity <activity_component_name>". |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6366 | * |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 6367 | * @param prefix Desired prefix to prepend at each line of output. |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6368 | * @param fd The raw file descriptor that the dump is being sent to. |
| 6369 | * @param writer The PrintWriter to which you should dump your state. This will be |
| 6370 | * closed for you after you return. |
| 6371 | * @param args additional arguments to the dump request. |
| 6372 | */ |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 6373 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 6374 | dumpInner(prefix, fd, writer, args); |
| 6375 | } |
| 6376 | |
| 6377 | void dumpInner(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
Felipe Leme | 4226033 | 2018-08-15 08:44:12 -0700 | [diff] [blame] | 6378 | if (args != null && args.length > 0 && args[0].equals("--autofill")) { |
| 6379 | dumpAutofillManager(prefix, writer); |
| 6380 | return; |
| 6381 | } |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 6382 | writer.print(prefix); writer.print("Local Activity "); |
| 6383 | writer.print(Integer.toHexString(System.identityHashCode(this))); |
| 6384 | writer.println(" State:"); |
| 6385 | String innerPrefix = prefix + " "; |
| 6386 | writer.print(innerPrefix); writer.print("mResumed="); |
| 6387 | writer.print(mResumed); writer.print(" mStopped="); |
| 6388 | writer.print(mStopped); writer.print(" mFinished="); |
| 6389 | writer.println(mFinished); |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 6390 | writer.print(innerPrefix); writer.print("mChangingConfigurations="); |
| 6391 | writer.println(mChangingConfigurations); |
| 6392 | writer.print(innerPrefix); writer.print("mCurrentConfig="); |
| 6393 | writer.println(mCurrentConfig); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6394 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 6395 | mFragments.dumpLoaders(innerPrefix, fd, writer, args); |
| 6396 | mFragments.getFragmentManager().dump(innerPrefix, fd, writer, args); |
Dianne Hackborn | 57dd737 | 2015-07-27 18:11:14 -0700 | [diff] [blame] | 6397 | if (mVoiceInteractor != null) { |
| 6398 | mVoiceInteractor.dump(innerPrefix, fd, writer, args); |
| 6399 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6400 | |
Michael Wright | 5f48dc7 | 2013-11-01 12:42:49 -0700 | [diff] [blame] | 6401 | if (getWindow() != null && |
| 6402 | getWindow().peekDecorView() != null && |
| 6403 | getWindow().peekDecorView().getViewRootImpl() != null) { |
| 6404 | getWindow().peekDecorView().getViewRootImpl().dump(prefix, fd, writer, args); |
| 6405 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6406 | |
| 6407 | mHandler.getLooper().dump(new PrintWriterPrinter(writer), prefix); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 6408 | |
Felipe Leme | 4226033 | 2018-08-15 08:44:12 -0700 | [diff] [blame] | 6409 | dumpAutofillManager(prefix, writer); |
| 6410 | |
| 6411 | ResourcesManager.getInstance().dump(prefix, writer); |
| 6412 | } |
| 6413 | |
| 6414 | void dumpAutofillManager(String prefix, PrintWriter writer) { |
Felipe Leme | 9d16dff | 2018-01-29 18:12:43 -0800 | [diff] [blame] | 6415 | final AutofillManager afm = getAutofillManager(); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 6416 | if (afm != null) { |
Felipe Leme | 4226033 | 2018-08-15 08:44:12 -0700 | [diff] [blame] | 6417 | afm.dump(prefix, writer); |
Svet Ganov | 47b37aa | 2018-02-16 00:11:39 -0800 | [diff] [blame] | 6418 | writer.print(prefix); writer.print("Autofill Compat Mode: "); |
| 6419 | writer.println(isAutofillCompatibilityEnabled()); |
Felipe Leme | 686128e | 2017-10-17 14:02:20 -0700 | [diff] [blame] | 6420 | } else { |
| 6421 | writer.print(prefix); writer.println("No AutofillManager"); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 6422 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6423 | } |
| 6424 | |
| 6425 | /** |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6426 | * Bit indicating that this activity is "immersive" and should not be |
| 6427 | * interrupted by notifications if possible. |
| 6428 | * |
| 6429 | * This value is initially set by the manifest property |
| 6430 | * <code>android:immersive</code> but may be changed at runtime by |
| 6431 | * {@link #setImmersive}. |
| 6432 | * |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 6433 | * @see #setImmersive(boolean) |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6434 | * @see android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 6435 | */ |
| 6436 | public boolean isImmersive() { |
| 6437 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6438 | return ActivityManager.getService().isImmersive(mToken); |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6439 | } catch (RemoteException e) { |
| 6440 | return false; |
| 6441 | } |
| 6442 | } |
| 6443 | |
| 6444 | /** |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 6445 | * Indication of whether this is the highest level activity in this task. Can be used to |
| 6446 | * determine whether an activity launched by this activity was placed in the same task or |
| 6447 | * another task. |
| 6448 | * |
| 6449 | * @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] | 6450 | */ |
George Mount | ff24328 | 2014-07-07 16:12:07 -0700 | [diff] [blame] | 6451 | private boolean isTopOfTask() { |
George Mount | f43ea5d | 2016-05-26 09:52:53 -0700 | [diff] [blame] | 6452 | if (mToken == null || mWindow == null) { |
George Mount | d0ca0e0 | 2016-03-29 10:32:56 -0700 | [diff] [blame] | 6453 | return false; |
| 6454 | } |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 6455 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6456 | return ActivityManager.getService().isTopOfTask(getActivityToken()); |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 6457 | } catch (RemoteException e) { |
| 6458 | return false; |
| 6459 | } |
| 6460 | } |
| 6461 | |
| 6462 | /** |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6463 | * Convert a translucent themed Activity {@link android.R.attr#windowIsTranslucent} to a |
| 6464 | * fullscreen opaque Activity. |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6465 | * <p> |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6466 | * 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] | 6467 | * Doing so will allow the {@link android.view.Surface} of the Activity behind to be released. |
| 6468 | * <p> |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6469 | * This call has no effect on non-translucent activities or on activities with the |
| 6470 | * {@link android.R.attr#windowIsFloating} attribute. |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6471 | * |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6472 | * @see #convertToTranslucent(android.app.Activity.TranslucentConversionListener, |
| 6473 | * ActivityOptions) |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6474 | * @see TranslucentConversionListener |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 6475 | * |
| 6476 | * @hide |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6477 | */ |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6478 | @SystemApi |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6479 | public void convertFromTranslucent() { |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6480 | try { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6481 | mTranslucentCallback = null; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6482 | if (ActivityManager.getService().convertFromTranslucent(mToken)) { |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 6483 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, true); |
| 6484 | } |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6485 | } catch (RemoteException e) { |
| 6486 | // pass |
| 6487 | } |
| 6488 | } |
| 6489 | |
| 6490 | /** |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6491 | * Convert a translucent themed Activity {@link android.R.attr#windowIsTranslucent} back from |
| 6492 | * opaque to translucent following a call to {@link #convertFromTranslucent()}. |
| 6493 | * <p> |
| 6494 | * Calling this allows the Activity behind this one to be seen again. Once all such Activities |
| 6495 | * have been redrawn {@link TranslucentConversionListener#onTranslucentConversionComplete} will |
| 6496 | * be called indicating that it is safe to make this activity translucent again. Until |
| 6497 | * {@link TranslucentConversionListener#onTranslucentConversionComplete} is called the image |
| 6498 | * behind the frontmost Activity will be indeterminate. |
| 6499 | * <p> |
| 6500 | * This call has no effect on non-translucent activities or on activities with the |
| 6501 | * {@link android.R.attr#windowIsFloating} attribute. |
| 6502 | * |
| 6503 | * @param callback the method to call when all visible Activities behind this one have been |
| 6504 | * drawn and it is safe to make this Activity translucent again. |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6505 | * @param options activity options delivered to the activity below this one. The options |
| 6506 | * are retrieved using {@link #getActivityOptions}. |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 6507 | * @return <code>true</code> if Window was opaque and will become translucent or |
| 6508 | * <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] | 6509 | * |
| 6510 | * @see #convertFromTranslucent() |
| 6511 | * @see TranslucentConversionListener |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 6512 | * |
| 6513 | * @hide |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6514 | */ |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6515 | @SystemApi |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 6516 | public boolean convertToTranslucent(TranslucentConversionListener callback, |
Jose Lima | 5517ea7 | 2014-06-10 12:31:43 -0700 | [diff] [blame] | 6517 | ActivityOptions options) { |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6518 | boolean drawComplete; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6519 | try { |
| 6520 | mTranslucentCallback = callback; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6521 | mChangeCanvasToTranslucent = ActivityManager.getService().convertToTranslucent( |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6522 | mToken, options == null ? null : options.toBundle()); |
George Mount | 9e18397 | 2014-09-03 12:35:09 -0700 | [diff] [blame] | 6523 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, false); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6524 | drawComplete = true; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6525 | } catch (RemoteException e) { |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6526 | // Make callback return as though it timed out. |
| 6527 | mChangeCanvasToTranslucent = false; |
| 6528 | drawComplete = false; |
| 6529 | } |
| 6530 | if (!mChangeCanvasToTranslucent && mTranslucentCallback != null) { |
| 6531 | // Window is already translucent. |
| 6532 | mTranslucentCallback.onTranslucentConversionComplete(drawComplete); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6533 | } |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 6534 | return mChangeCanvasToTranslucent; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6535 | } |
| 6536 | |
| 6537 | /** @hide */ |
| 6538 | void onTranslucentConversionComplete(boolean drawComplete) { |
| 6539 | if (mTranslucentCallback != null) { |
| 6540 | mTranslucentCallback.onTranslucentConversionComplete(drawComplete); |
| 6541 | mTranslucentCallback = null; |
| 6542 | } |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 6543 | if (mChangeCanvasToTranslucent) { |
| 6544 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, false); |
| 6545 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6546 | } |
| 6547 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 6548 | /** @hide */ |
| 6549 | public void onNewActivityOptions(ActivityOptions options) { |
| 6550 | mActivityTransitionState.setEnterActivityOptions(this, options); |
| 6551 | if (!mStopped) { |
| 6552 | mActivityTransitionState.enterReady(this); |
| 6553 | } |
| 6554 | } |
| 6555 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6556 | /** |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6557 | * Retrieve the ActivityOptions passed in from the launching activity or passed back |
| 6558 | * from an activity launched by this activity in its call to {@link |
| 6559 | * #convertToTranslucent(TranslucentConversionListener, ActivityOptions)} |
| 6560 | * |
| 6561 | * @return The ActivityOptions passed to {@link #convertToTranslucent}. |
| 6562 | * @hide |
| 6563 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 6564 | @UnsupportedAppUsage |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6565 | ActivityOptions getActivityOptions() { |
| 6566 | try { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6567 | return ActivityOptions.fromBundle( |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6568 | ActivityManager.getService().getActivityOptions(mToken)); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6569 | } catch (RemoteException e) { |
| 6570 | } |
| 6571 | return null; |
| 6572 | } |
| 6573 | |
| 6574 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6575 | * 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] | 6576 | * this method anytime between the start of {@link #onResume()} and the return from |
| 6577 | * {@link #onPause()}. If this call is successful then the activity will remain visible after |
| 6578 | * {@link #onPause()} is called, and is allowed to continue playing media in the background. |
| 6579 | * |
| 6580 | * <p>The actions of this call are reset each time that this activity is brought to the |
| 6581 | * front. That is, every time {@link #onResume()} is called the activity will be assumed |
| 6582 | * to not have requested visible behind. Therefore, if you want this activity to continue to |
| 6583 | * be visible in the background you must call this method again. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6584 | * |
| 6585 | * <p>Only fullscreen opaque activities may make this call. I.e. this call is a nop |
| 6586 | * for dialog and translucent activities. |
| 6587 | * |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 6588 | * <p>Under all circumstances, the activity must stop playing and release resources prior to or |
| 6589 | * within a call to {@link #onVisibleBehindCanceled()} or if this call returns false. |
| 6590 | * |
| 6591 | * <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] | 6592 | * the next call to onResume. |
| 6593 | * |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6594 | * @deprecated This method's functionality is no longer supported as of |
| 6595 | * {@link android.os.Build.VERSION_CODES#O} and will be removed in a future release. |
| 6596 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6597 | * @param visible true to notify the system that the activity wishes to be visible behind other |
| 6598 | * translucent activities, false to indicate otherwise. Resources must be |
| 6599 | * released when passing false to this method. |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6600 | * |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 6601 | * @return the resulting visibiity state. If true the activity will remain visible beyond |
| 6602 | * {@link #onPause()} if the next activity is translucent or not fullscreen. If false |
| 6603 | * then the activity may not count on being visible behind other translucent activities, |
| 6604 | * and must stop any media playback and release resources. |
| 6605 | * Returning false may occur in lieu of a call to {@link #onVisibleBehindCanceled()} so |
| 6606 | * the return value must be checked. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6607 | * |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 6608 | * @see #onVisibleBehindCanceled() |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6609 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6610 | @Deprecated |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6611 | public boolean requestVisibleBehind(boolean visible) { |
Robert Carr | 8661c5e | 2017-06-27 13:46:14 -0700 | [diff] [blame] | 6612 | return false; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6613 | } |
| 6614 | |
| 6615 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6616 | * Called when a translucent activity over this activity is becoming opaque or another |
| 6617 | * activity is being launched. Activities that override this method must call |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 6618 | * <code>super.onVisibleBehindCanceled()</code> or a SuperNotCalledException will be thrown. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6619 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6620 | * <p>When this method is called the activity has 500 msec to release any resources it may be |
| 6621 | * using while visible in the background. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6622 | * 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] | 6623 | * 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] | 6624 | * process. Otherwise {@link #onStop()} will be called following return. |
| 6625 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6626 | * @see #requestVisibleBehind(boolean) |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6627 | * |
| 6628 | * @deprecated This method's functionality is no longer supported as of |
| 6629 | * {@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] | 6630 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6631 | @Deprecated |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 6632 | @CallSuper |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 6633 | public void onVisibleBehindCanceled() { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6634 | mCalled = true; |
| 6635 | } |
| 6636 | |
| 6637 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6638 | * Translucent activities may call this to determine if there is an activity below them that |
| 6639 | * is currently set to be visible in the background. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6640 | * |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6641 | * @deprecated This method's functionality is no longer supported as of |
| 6642 | * {@link android.os.Build.VERSION_CODES#O} and will be removed in a future release. |
| 6643 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6644 | * @return true if an activity below is set to visible according to the most recent call to |
| 6645 | * {@link #requestVisibleBehind(boolean)}, false otherwise. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6646 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6647 | * @see #requestVisibleBehind(boolean) |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 6648 | * @see #onVisibleBehindCanceled() |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6649 | * @see #onBackgroundVisibleBehindChanged(boolean) |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6650 | * @hide |
| 6651 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6652 | @Deprecated |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6653 | @SystemApi |
| 6654 | public boolean isBackgroundVisibleBehind() { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6655 | return false; |
| 6656 | } |
| 6657 | |
| 6658 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6659 | * The topmost foreground activity will receive this call when the background visibility state |
| 6660 | * of the activity below it changes. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6661 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6662 | * 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] | 6663 | * due to a background activity finishing itself. |
| 6664 | * |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6665 | * @deprecated This method's functionality is no longer supported as of |
| 6666 | * {@link android.os.Build.VERSION_CODES#O} and will be removed in a future release. |
| 6667 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6668 | * @param visible true if a background activity is visible, false otherwise. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6669 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6670 | * @see #requestVisibleBehind(boolean) |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 6671 | * @see #onVisibleBehindCanceled() |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6672 | * @hide |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6673 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6674 | @Deprecated |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6675 | @SystemApi |
| 6676 | public void onBackgroundVisibleBehindChanged(boolean visible) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6677 | } |
| 6678 | |
| 6679 | /** |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 6680 | * Activities cannot draw during the period that their windows are animating in. In order |
| 6681 | * to know when it is safe to begin drawing they can override this method which will be |
| 6682 | * called when the entering animation has completed. |
| 6683 | */ |
| 6684 | public void onEnterAnimationComplete() { |
| 6685 | } |
| 6686 | |
| 6687 | /** |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 6688 | * @hide |
| 6689 | */ |
| 6690 | public void dispatchEnterAnimationComplete() { |
| 6691 | onEnterAnimationComplete(); |
| 6692 | if (getWindow() != null && getWindow().getDecorView() != null) { |
| 6693 | getWindow().getDecorView().getViewTreeObserver().dispatchOnEnterAnimationComplete(); |
| 6694 | } |
| 6695 | } |
| 6696 | |
| 6697 | /** |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6698 | * Adjust the current immersive mode setting. |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 6699 | * |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6700 | * Note that changing this value will have no effect on the activity's |
| 6701 | * {@link android.content.pm.ActivityInfo} structure; that is, if |
| 6702 | * <code>android:immersive</code> is set to <code>true</code> |
| 6703 | * in the application's manifest entry for this activity, the {@link |
| 6704 | * android.content.pm.ActivityInfo#flags ActivityInfo.flags} member will |
| 6705 | * always have its {@link android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 6706 | * FLAG_IMMERSIVE} bit set. |
| 6707 | * |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 6708 | * @see #isImmersive() |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6709 | * @see android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 6710 | */ |
| 6711 | public void setImmersive(boolean i) { |
| 6712 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6713 | ActivityManager.getService().setImmersive(mToken, i); |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6714 | } catch (RemoteException e) { |
| 6715 | // pass |
| 6716 | } |
| 6717 | } |
| 6718 | |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 6719 | /** |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 6720 | * Enable or disable virtual reality (VR) mode for this Activity. |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 6721 | * |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 6722 | * <p>VR mode is a hint to Android system to switch to a mode optimized for VR applications |
| 6723 | * while this Activity has user focus.</p> |
| 6724 | * |
| 6725 | * <p>It is recommended that applications additionally declare |
| 6726 | * {@link android.R.attr#enableVrMode} in their manifest to allow for smooth activity |
| 6727 | * transitions when switching between VR activities.</p> |
| 6728 | * |
| 6729 | * <p>If the requested {@link android.service.vr.VrListenerService} component is not available, |
| 6730 | * VR mode will not be started. Developers can handle this case as follows:</p> |
| 6731 | * |
| 6732 | * <pre> |
| 6733 | * String servicePackage = "com.whatever.app"; |
| 6734 | * String serviceClass = "com.whatever.app.MyVrListenerService"; |
| 6735 | * |
| 6736 | * // Name of the component of the VrListenerService to start. |
| 6737 | * ComponentName serviceComponent = new ComponentName(servicePackage, serviceClass); |
| 6738 | * |
| 6739 | * try { |
| 6740 | * setVrModeEnabled(true, myComponentName); |
| 6741 | * } catch (PackageManager.NameNotFoundException e) { |
| 6742 | * List<ApplicationInfo> installed = getPackageManager().getInstalledApplications(0); |
| 6743 | * boolean isInstalled = false; |
| 6744 | * for (ApplicationInfo app : installed) { |
| 6745 | * if (app.packageName.equals(servicePackage)) { |
| 6746 | * isInstalled = true; |
| 6747 | * break; |
| 6748 | * } |
| 6749 | * } |
| 6750 | * if (isInstalled) { |
| 6751 | * // Package is installed, but not enabled in Settings. Let user enable it. |
| 6752 | * startActivity(new Intent(Settings.ACTION_VR_LISTENER_SETTINGS)); |
| 6753 | * } else { |
| 6754 | * // Package is not installed. Send an intent to download this. |
| 6755 | * sentIntentToLaunchAppStore(servicePackage); |
| 6756 | * } |
| 6757 | * } |
| 6758 | * </pre> |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 6759 | * |
| 6760 | * @param enabled {@code true} to enable this mode. |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 6761 | * @param requestedComponent the name of the component to use as a |
| 6762 | * {@link android.service.vr.VrListenerService} while VR mode is enabled. |
| 6763 | * |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 6764 | * @throws android.content.pm.PackageManager.NameNotFoundException if the given component |
| 6765 | * to run as a {@link android.service.vr.VrListenerService} is not installed, or has |
| 6766 | * not been enabled in user settings. |
| 6767 | * |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 6768 | * @see android.content.pm.PackageManager#FEATURE_VR_MODE_HIGH_PERFORMANCE |
| 6769 | * @see android.service.vr.VrListenerService |
| 6770 | * @see android.provider.Settings#ACTION_VR_LISTENER_SETTINGS |
| 6771 | * @see android.R.attr#enableVrMode |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 6772 | */ |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 6773 | public void setVrModeEnabled(boolean enabled, @NonNull ComponentName requestedComponent) |
| 6774 | throws PackageManager.NameNotFoundException { |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 6775 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6776 | if (ActivityManager.getService().setVrMode(mToken, enabled, requestedComponent) |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 6777 | != 0) { |
| 6778 | throw new PackageManager.NameNotFoundException( |
| 6779 | requestedComponent.flattenToString()); |
| 6780 | } |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 6781 | } catch (RemoteException e) { |
| 6782 | // pass |
| 6783 | } |
| 6784 | } |
| 6785 | |
| 6786 | /** |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 6787 | * Start an action mode of the default type {@link ActionMode#TYPE_PRIMARY}. |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 6788 | * |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 6789 | * @param callback Callback that will manage lifecycle events for this action mode |
| 6790 | * @return The ActionMode that was started, or null if it was canceled |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 6791 | * |
| 6792 | * @see ActionMode |
| 6793 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6794 | @Nullable |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 6795 | public ActionMode startActionMode(ActionMode.Callback callback) { |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 6796 | return mWindow.getDecorView().startActionMode(callback); |
| 6797 | } |
| 6798 | |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 6799 | /** |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 6800 | * Start an action mode of the given type. |
| 6801 | * |
| 6802 | * @param callback Callback that will manage lifecycle events for this action mode |
| 6803 | * @param type One of {@link ActionMode#TYPE_PRIMARY} or {@link ActionMode#TYPE_FLOATING}. |
| 6804 | * @return The ActionMode that was started, or null if it was canceled |
| 6805 | * |
| 6806 | * @see ActionMode |
| 6807 | */ |
| 6808 | @Nullable |
| 6809 | public ActionMode startActionMode(ActionMode.Callback callback, int type) { |
| 6810 | return mWindow.getDecorView().startActionMode(callback, type); |
| 6811 | } |
| 6812 | |
| 6813 | /** |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 6814 | * Give the Activity a chance to control the UI for an action mode requested |
| 6815 | * by the system. |
| 6816 | * |
| 6817 | * <p>Note: If you are looking for a notification callback that an action mode |
| 6818 | * has been started for this activity, see {@link #onActionModeStarted(ActionMode)}.</p> |
| 6819 | * |
| 6820 | * @param callback The callback that should control the new action mode |
| 6821 | * @return The new action mode, or <code>null</code> if the activity does not want to |
| 6822 | * provide special handling for this action mode. (It will be handled by the system.) |
| 6823 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6824 | @Nullable |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6825 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 6826 | public ActionMode onWindowStartingActionMode(ActionMode.Callback callback) { |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 6827 | // Only Primary ActionModes are represented in the ActionBar. |
| 6828 | if (mActionModeTypeStarting == ActionMode.TYPE_PRIMARY) { |
| 6829 | initWindowDecorActionBar(); |
| 6830 | if (mActionBar != null) { |
| 6831 | return mActionBar.startActionMode(callback); |
| 6832 | } |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 6833 | } |
| 6834 | return null; |
| 6835 | } |
| 6836 | |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 6837 | /** |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 6838 | * {@inheritDoc} |
| 6839 | */ |
| 6840 | @Nullable |
| 6841 | @Override |
| 6842 | public ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int type) { |
| 6843 | try { |
| 6844 | mActionModeTypeStarting = type; |
| 6845 | return onWindowStartingActionMode(callback); |
| 6846 | } finally { |
| 6847 | mActionModeTypeStarting = ActionMode.TYPE_PRIMARY; |
| 6848 | } |
| 6849 | } |
| 6850 | |
| 6851 | /** |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 6852 | * Notifies the Activity that an action mode has been started. |
| 6853 | * Activity subclasses overriding this method should call the superclass implementation. |
| 6854 | * |
| 6855 | * @param mode The new action mode. |
| 6856 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 6857 | @CallSuper |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6858 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 6859 | public void onActionModeStarted(ActionMode mode) { |
| 6860 | } |
| 6861 | |
| 6862 | /** |
| 6863 | * Notifies the activity that an action mode has finished. |
| 6864 | * Activity subclasses overriding this method should call the superclass implementation. |
| 6865 | * |
| 6866 | * @param mode The action mode that just finished. |
| 6867 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 6868 | @CallSuper |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6869 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 6870 | public void onActionModeFinished(ActionMode mode) { |
| 6871 | } |
| 6872 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6873 | /** |
| 6874 | * Returns true if the app should recreate the task when navigating 'up' from this activity |
| 6875 | * by using targetIntent. |
| 6876 | * |
| 6877 | * <p>If this method returns false the app can trivially call |
| 6878 | * {@link #navigateUpTo(Intent)} using the same parameters to correctly perform |
| 6879 | * up navigation. If this method returns false, the app should synthesize a new task stack |
| 6880 | * by using {@link TaskStackBuilder} or another similar mechanism to perform up navigation.</p> |
| 6881 | * |
| 6882 | * @param targetIntent An intent representing the target destination for up navigation |
| 6883 | * @return true if navigating up should recreate a new task stack, false if the same task |
| 6884 | * should be used for the destination |
| 6885 | */ |
| 6886 | public boolean shouldUpRecreateTask(Intent targetIntent) { |
| 6887 | try { |
| 6888 | PackageManager pm = getPackageManager(); |
| 6889 | ComponentName cn = targetIntent.getComponent(); |
| 6890 | if (cn == null) { |
| 6891 | cn = targetIntent.resolveActivity(pm); |
| 6892 | } |
| 6893 | ActivityInfo info = pm.getActivityInfo(cn, 0); |
| 6894 | if (info.taskAffinity == null) { |
| 6895 | return false; |
| 6896 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6897 | return ActivityManager.getService() |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 6898 | .shouldUpRecreateTask(mToken, info.taskAffinity); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6899 | } catch (RemoteException e) { |
| 6900 | return false; |
| 6901 | } catch (NameNotFoundException e) { |
| 6902 | return false; |
| 6903 | } |
| 6904 | } |
| 6905 | |
| 6906 | /** |
| 6907 | * Navigate from this activity to the activity specified by upIntent, finishing this activity |
| 6908 | * in the process. If the activity indicated by upIntent already exists in the task's history, |
| 6909 | * 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] | 6910 | * finished. |
| 6911 | * |
| 6912 | * <p>If the indicated activity does not appear in the history stack, this will finish |
| 6913 | * each activity in this task until the root activity of the task is reached, resulting in |
| 6914 | * an "in-app home" behavior. This can be useful in apps with a complex navigation hierarchy |
| 6915 | * when an activity may be reached by a path not passing through a canonical parent |
| 6916 | * activity.</p> |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6917 | * |
| 6918 | * <p>This method should be used when performing up navigation from within the same task |
| 6919 | * as the destination. If up navigation should cross tasks in some cases, see |
| 6920 | * {@link #shouldUpRecreateTask(Intent)}.</p> |
| 6921 | * |
| 6922 | * @param upIntent An intent representing the target destination for up navigation |
| 6923 | * |
| 6924 | * @return true if up navigation successfully reached the activity indicated by upIntent and |
| 6925 | * upIntent was delivered to it. false if an instance of the indicated activity could |
| 6926 | * not be found and this activity was simply finished normally. |
| 6927 | */ |
| 6928 | public boolean navigateUpTo(Intent upIntent) { |
| 6929 | if (mParent == null) { |
| 6930 | ComponentName destInfo = upIntent.getComponent(); |
| 6931 | if (destInfo == null) { |
| 6932 | destInfo = upIntent.resolveActivity(getPackageManager()); |
| 6933 | if (destInfo == null) { |
| 6934 | return false; |
| 6935 | } |
| 6936 | upIntent = new Intent(upIntent); |
| 6937 | upIntent.setComponent(destInfo); |
| 6938 | } |
| 6939 | int resultCode; |
| 6940 | Intent resultData; |
| 6941 | synchronized (this) { |
| 6942 | resultCode = mResultCode; |
| 6943 | resultData = mResultData; |
| 6944 | } |
| 6945 | if (resultData != null) { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 6946 | resultData.prepareToLeaveProcess(this); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6947 | } |
| 6948 | try { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 6949 | upIntent.prepareToLeaveProcess(this); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6950 | return ActivityManager.getService().navigateUpTo(mToken, upIntent, |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6951 | resultCode, resultData); |
| 6952 | } catch (RemoteException e) { |
| 6953 | return false; |
| 6954 | } |
| 6955 | } else { |
| 6956 | return mParent.navigateUpToFromChild(this, upIntent); |
| 6957 | } |
| 6958 | } |
| 6959 | |
| 6960 | /** |
| 6961 | * This is called when a child activity of this one calls its |
| 6962 | * {@link #navigateUpTo} method. The default implementation simply calls |
| 6963 | * navigateUpTo(upIntent) on this activity (the parent). |
| 6964 | * |
| 6965 | * @param child The activity making the call. |
| 6966 | * @param upIntent An intent representing the target destination for up navigation |
| 6967 | * |
| 6968 | * @return true if up navigation successfully reached the activity indicated by upIntent and |
| 6969 | * upIntent was delivered to it. false if an instance of the indicated activity could |
| 6970 | * not be found and this activity was simply finished normally. |
| 6971 | */ |
| 6972 | public boolean navigateUpToFromChild(Activity child, Intent upIntent) { |
| 6973 | return navigateUpTo(upIntent); |
| 6974 | } |
| 6975 | |
| 6976 | /** |
| 6977 | * Obtain an {@link Intent} that will launch an explicit target activity specified by |
| 6978 | * this activity's logical parent. The logical parent is named in the application's manifest |
| 6979 | * by the {@link android.R.attr#parentActivityName parentActivityName} attribute. |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 6980 | * Activity subclasses may override this method to modify the Intent returned by |
| 6981 | * super.getParentActivityIntent() or to implement a different mechanism of retrieving |
| 6982 | * the parent intent entirely. |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6983 | * |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 6984 | * @return a new Intent targeting the defined parent of this activity or null if |
| 6985 | * there is no valid parent. |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6986 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6987 | @Nullable |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6988 | public Intent getParentActivityIntent() { |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 6989 | final String parentName = mActivityInfo.parentActivityName; |
| 6990 | if (TextUtils.isEmpty(parentName)) { |
| 6991 | return null; |
| 6992 | } |
Adam Powell | 5a4010c | 2012-09-16 15:14:05 -0700 | [diff] [blame] | 6993 | |
| 6994 | // If the parent itself has no parent, generate a main activity intent. |
| 6995 | final ComponentName target = new ComponentName(this, parentName); |
| 6996 | try { |
| 6997 | final ActivityInfo parentInfo = getPackageManager().getActivityInfo(target, 0); |
| 6998 | final String parentActivity = parentInfo.parentActivityName; |
| 6999 | final Intent parentIntent = parentActivity == null |
| 7000 | ? Intent.makeMainActivity(target) |
| 7001 | : new Intent().setComponent(target); |
| 7002 | return parentIntent; |
| 7003 | } catch (NameNotFoundException e) { |
| 7004 | Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName + |
| 7005 | "' in manifest"); |
| 7006 | return null; |
| 7007 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 7008 | } |
| 7009 | |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7010 | /** |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 7011 | * When {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7012 | * 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] | 7013 | * 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] | 7014 | * {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7015 | * |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7016 | * @param callback Used to manipulate shared element transitions on the launched Activity. |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7017 | */ |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7018 | public void setEnterSharedElementCallback(SharedElementCallback callback) { |
| 7019 | if (callback == null) { |
| 7020 | callback = SharedElementCallback.NULL_CALLBACK; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7021 | } |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7022 | mEnterTransitionListener = callback; |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7023 | } |
| 7024 | |
| 7025 | /** |
| 7026 | * When {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7027 | * 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] | 7028 | * will be called to handle shared elements on the <i>launching</i> Activity. Most |
| 7029 | * calls will only come when returning from the started Activity. |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 7030 | * This requires {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7031 | * |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7032 | * @param callback Used to manipulate shared element transitions on the launching Activity. |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7033 | */ |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7034 | public void setExitSharedElementCallback(SharedElementCallback callback) { |
| 7035 | if (callback == null) { |
| 7036 | callback = SharedElementCallback.NULL_CALLBACK; |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7037 | } |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 7038 | mExitTransitionListener = callback; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 7039 | } |
| 7040 | |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 7041 | /** |
| 7042 | * Postpone the entering activity transition when Activity was started with |
| 7043 | * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
| 7044 | * android.util.Pair[])}. |
| 7045 | * <p>This method gives the Activity the ability to delay starting the entering and |
| 7046 | * shared element transitions until all data is loaded. Until then, the Activity won't |
| 7047 | * draw into its window, leaving the window transparent. This may also cause the |
| 7048 | * returning animation to be delayed until data is ready. This method should be |
| 7049 | * called in {@link #onCreate(android.os.Bundle)} or in |
| 7050 | * {@link #onActivityReenter(int, android.content.Intent)}. |
| 7051 | * {@link #startPostponedEnterTransition()} must be called to allow the Activity to |
| 7052 | * start the transitions. If the Activity did not use |
| 7053 | * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
| 7054 | * android.util.Pair[])}, then this method does nothing.</p> |
| 7055 | */ |
| 7056 | public void postponeEnterTransition() { |
| 7057 | mActivityTransitionState.postponeEnterTransition(); |
| 7058 | } |
| 7059 | |
| 7060 | /** |
| 7061 | * Begin postponed transitions after {@link #postponeEnterTransition()} was called. |
| 7062 | * If postponeEnterTransition() was called, you must call startPostponedEnterTransition() |
| 7063 | * to have your Activity start drawing. |
| 7064 | */ |
| 7065 | public void startPostponedEnterTransition() { |
| 7066 | mActivityTransitionState.startPostponedEnterTransition(); |
| 7067 | } |
| 7068 | |
Vladislav Kaznacheev | b23a757 | 2015-12-18 12:23:43 -0800 | [diff] [blame] | 7069 | /** |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 7070 | * Create {@link DragAndDropPermissions} object bound to this activity and controlling the |
| 7071 | * access permissions for content URIs associated with the {@link DragEvent}. |
Vladislav Kaznacheev | b23a757 | 2015-12-18 12:23:43 -0800 | [diff] [blame] | 7072 | * @param event Drag event |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 7073 | * @return The {@link DragAndDropPermissions} object used to control access to the content URIs. |
| 7074 | * 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] | 7075 | */ |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 7076 | public DragAndDropPermissions requestDragAndDropPermissions(DragEvent event) { |
| 7077 | DragAndDropPermissions dragAndDropPermissions = DragAndDropPermissions.obtain(event); |
| 7078 | if (dragAndDropPermissions != null && dragAndDropPermissions.take(getActivityToken())) { |
| 7079 | return dragAndDropPermissions; |
Vladislav Kaznacheev | b23a757 | 2015-12-18 12:23:43 -0800 | [diff] [blame] | 7080 | } |
| 7081 | return null; |
| 7082 | } |
| 7083 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7084 | // ------------------ Internal API ------------------ |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7085 | |
Mathew Inwood | 45d2c25 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 7086 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7087 | final void setParent(Activity parent) { |
| 7088 | mParent = parent; |
| 7089 | } |
| 7090 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 7091 | @UnsupportedAppUsage |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 7092 | final void attach(Context context, ActivityThread aThread, |
| 7093 | Instrumentation instr, IBinder token, int ident, |
| 7094 | Application application, Intent intent, ActivityInfo info, |
| 7095 | CharSequence title, Activity parent, String id, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 7096 | NonConfigurationInstances lastNonConfigurationInstances, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 7097 | Configuration config, String referrer, IVoiceInteractor voiceInteractor, |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 7098 | Window window, ActivityConfigCallback activityConfigCallback) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7099 | attachBaseContext(context); |
| 7100 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7101 | mFragments.attachHost(null /*parent*/); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7102 | |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 7103 | mWindow = new PhoneWindow(this, window, activityConfigCallback); |
Skuhne | ce2faa5 | 2015-08-11 10:36:38 -0700 | [diff] [blame] | 7104 | mWindow.setWindowControllerCallback(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7105 | mWindow.setCallback(this); |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 7106 | mWindow.setOnWindowDismissedCallback(this); |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 7107 | mWindow.getLayoutInflater().setPrivateFactory(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7108 | if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) { |
| 7109 | mWindow.setSoftInputMode(info.softInputMode); |
| 7110 | } |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 7111 | if (info.uiOptions != 0) { |
| 7112 | mWindow.setUiOptions(info.uiOptions); |
| 7113 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7114 | mUiThread = Thread.currentThread(); |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7116 | mMainThread = aThread; |
| 7117 | mInstrumentation = instr; |
| 7118 | mToken = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 7119 | mIdent = ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7120 | mApplication = application; |
| 7121 | mIntent = intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 7122 | mReferrer = referrer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7123 | mComponent = intent.getComponent(); |
| 7124 | mActivityInfo = info; |
| 7125 | mTitle = title; |
| 7126 | mParent = parent; |
| 7127 | mEmbeddedID = id; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 7128 | mLastNonConfigurationInstances = lastNonConfigurationInstances; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 7129 | if (voiceInteractor != null) { |
| 7130 | if (lastNonConfigurationInstances != null) { |
| 7131 | mVoiceInteractor = lastNonConfigurationInstances.voiceInteractor; |
| 7132 | } else { |
| 7133 | mVoiceInteractor = new VoiceInteractor(voiceInteractor, this, this, |
| 7134 | Looper.myLooper()); |
| 7135 | } |
| 7136 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7137 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7138 | mWindow.setWindowManager( |
| 7139 | (WindowManager)context.getSystemService(Context.WINDOW_SERVICE), |
| 7140 | mToken, mComponent.flattenToString(), |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 7141 | (info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7142 | if (mParent != null) { |
| 7143 | mWindow.setContainer(mParent.getWindow()); |
| 7144 | } |
| 7145 | mWindowManager = mWindow.getWindowManager(); |
| 7146 | mCurrentConfig = config; |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 7147 | |
| 7148 | mWindow.setColorMode(info.colorMode); |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7149 | |
| 7150 | setAutofillCompatibilityEnabled(application.isAutofillCompatibilityEnabled()); |
| 7151 | enableAutofillCompatibilityIfNeeded(); |
| 7152 | } |
| 7153 | |
| 7154 | private void enableAutofillCompatibilityIfNeeded() { |
| 7155 | if (isAutofillCompatibilityEnabled()) { |
| 7156 | final AutofillManager afm = getSystemService(AutofillManager.class); |
| 7157 | if (afm != null) { |
| 7158 | afm.enableCompatibilityMode(); |
| 7159 | } |
| 7160 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7161 | } |
| 7162 | |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 7163 | /** @hide */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 7164 | @UnsupportedAppUsage |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 7165 | public final IBinder getActivityToken() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7166 | return mParent != null ? mParent.getActivityToken() : mToken; |
| 7167 | } |
| 7168 | |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 7169 | /** @hide */ |
| 7170 | @VisibleForTesting |
| 7171 | public final ActivityThread getActivityThread() { |
| 7172 | return mMainThread; |
| 7173 | } |
| 7174 | |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7175 | final void performCreate(Bundle icicle) { |
| 7176 | performCreate(icicle, null); |
| 7177 | } |
| 7178 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 7179 | @UnsupportedAppUsage |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7180 | final void performCreate(Bundle icicle, PersistableBundle persistentState) { |
| 7181 | mCanEnterPictureInPicture = true; |
| 7182 | restoreHasCurrentPermissionRequest(icicle); |
| 7183 | if (persistentState != null) { |
| 7184 | onCreate(icicle, persistentState); |
| 7185 | } else { |
| 7186 | onCreate(icicle); |
| 7187 | } |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7188 | writeEventLog(LOG_AM_ON_CREATE_CALLED, "performCreate"); |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7189 | mActivityTransitionState.readState(icicle); |
| 7190 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 7191 | mVisibleFromClient = !mWindow.getWindowStyle().getBoolean( |
| 7192 | com.android.internal.R.styleable.Window_windowNoDisplay, false); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 7193 | mFragments.dispatchActivityCreated(); |
Eino-Ville Talvala | 563df3b | 2016-06-06 22:04:54 +0000 | [diff] [blame] | 7194 | mActivityTransitionState.setEnterActivityOptions(this, getActivityOptions()); |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7195 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7196 | |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7197 | final void performNewIntent(Intent intent) { |
| 7198 | mCanEnterPictureInPicture = true; |
| 7199 | onNewIntent(intent); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7200 | } |
| 7201 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7202 | final void performStart(String reason) { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 7203 | mActivityTransitionState.setEnterActivityOptions(this, getActivityOptions()); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 7204 | mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7205 | mCalled = false; |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 7206 | mFragments.execPendingActions(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7207 | mInstrumentation.callActivityOnStart(this); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7208 | writeEventLog(LOG_AM_ON_START_CALLED, reason); |
| 7209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7210 | if (!mCalled) { |
| 7211 | throw new SuperNotCalledException( |
| 7212 | "Activity " + mComponent.toShortString() + |
| 7213 | " did not call through to super.onStart()"); |
| 7214 | } |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7215 | mFragments.dispatchStart(); |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7216 | mFragments.reportLoaderStart(); |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 7217 | |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 7218 | boolean isAppDebuggable = |
| 7219 | (mApplication.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 7220 | |
David Brazdil | 795cbfb | 2018-01-26 12:23:15 +0000 | [diff] [blame] | 7221 | // This property is set for all non-user builds except final release |
David Brazdil | 927d6de | 2018-01-24 19:54:30 +0000 | [diff] [blame] | 7222 | boolean isDlwarningEnabled = SystemProperties.getInt("ro.bionic.ld.warning", 0) == 1; |
| 7223 | |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 7224 | if (isAppDebuggable || isDlwarningEnabled) { |
| 7225 | String dlwarning = getDlWarning(); |
| 7226 | if (dlwarning != null) { |
Adam Powell | d93f3b1 | 2016-03-03 08:43:37 -0800 | [diff] [blame] | 7227 | String appName = getApplicationInfo().loadLabel(getPackageManager()) |
| 7228 | .toString(); |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 7229 | String warning = "Detected problems with app native libraries\n" + |
| 7230 | "(please consult log for detail):\n" + dlwarning; |
| 7231 | if (isAppDebuggable) { |
| 7232 | new AlertDialog.Builder(this). |
| 7233 | setTitle(appName). |
| 7234 | setMessage(warning). |
| 7235 | setPositiveButton(android.R.string.ok, null). |
| 7236 | setCancelable(false). |
| 7237 | show(); |
| 7238 | } else { |
| 7239 | Toast.makeText(this, appName + "\n" + warning, Toast.LENGTH_LONG).show(); |
| 7240 | } |
| 7241 | } |
| 7242 | } |
| 7243 | |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 7244 | mActivityTransitionState.enterReady(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7245 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7246 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 7247 | /** |
| 7248 | * Restart the activity. |
| 7249 | * @param start Indicates whether the activity should also be started after restart. |
| 7250 | * The option to not start immediately is needed in case a transaction with |
| 7251 | * multiple lifecycle transitions is in progress. |
| 7252 | */ |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7253 | final void performRestart(boolean start, String reason) { |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 7254 | mCanEnterPictureInPicture = true; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 7255 | mFragments.noteStateNotSaved(); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 7256 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 7257 | if (mToken != null && mParent == null) { |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 7258 | // 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] | 7259 | WindowManagerGlobal.getInstance().setStoppedState(mToken, false /* stopped */); |
| 7260 | } |
| 7261 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7262 | if (mStopped) { |
| 7263 | mStopped = false; |
Dianne Hackborn | 185e3e2 | 2011-06-03 15:26:01 -0700 | [diff] [blame] | 7264 | |
| 7265 | synchronized (mManagedCursors) { |
| 7266 | final int N = mManagedCursors.size(); |
| 7267 | for (int i=0; i<N; i++) { |
| 7268 | ManagedCursor mc = mManagedCursors.get(i); |
| 7269 | if (mc.mReleased || mc.mUpdated) { |
| 7270 | if (!mc.mCursor.requery()) { |
Dianne Hackborn | a5445d3 | 2011-09-01 14:38:24 -0700 | [diff] [blame] | 7271 | if (getApplicationInfo().targetSdkVersion |
| 7272 | >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
| 7273 | throw new IllegalStateException( |
| 7274 | "trying to requery an already closed cursor " |
| 7275 | + mc.mCursor); |
| 7276 | } |
Dianne Hackborn | 185e3e2 | 2011-06-03 15:26:01 -0700 | [diff] [blame] | 7277 | } |
| 7278 | mc.mReleased = false; |
| 7279 | mc.mUpdated = false; |
| 7280 | } |
| 7281 | } |
| 7282 | } |
| 7283 | |
| 7284 | mCalled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7285 | mInstrumentation.callActivityOnRestart(this); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7286 | writeEventLog(LOG_AM_ON_RESTART_CALLED, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7287 | if (!mCalled) { |
| 7288 | throw new SuperNotCalledException( |
| 7289 | "Activity " + mComponent.toShortString() + |
| 7290 | " did not call through to super.onRestart()"); |
| 7291 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 7292 | if (start) { |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7293 | performStart(reason); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 7294 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7295 | } |
| 7296 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7297 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7298 | final void performResume(boolean followedByPause, String reason) { |
| 7299 | performRestart(true /* start */, reason); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7300 | |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 7301 | mFragments.execPendingActions(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7302 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 7303 | mLastNonConfigurationInstances = null; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7304 | |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 7305 | if (mAutoFillResetNeeded) { |
| 7306 | // When Activity is destroyed in paused state, and relaunch activity, there will be |
| 7307 | // extra onResume and onPause event, ignore the first onResume and onPause. |
| 7308 | // see ActivityThread.handleRelaunchActivity() |
| 7309 | mAutoFillIgnoreFirstResumePause = followedByPause; |
| 7310 | if (mAutoFillIgnoreFirstResumePause && DEBUG_LIFECYCLE) { |
| 7311 | Slog.v(TAG, "autofill will ignore first pause when relaunching " + this); |
| 7312 | } |
| 7313 | } |
| 7314 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7315 | mCalled = false; |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 7316 | // mResumed is set by the instrumentation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7317 | mInstrumentation.callActivityOnResume(this); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7318 | writeEventLog(LOG_AM_ON_RESUME_CALLED, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7319 | if (!mCalled) { |
| 7320 | throw new SuperNotCalledException( |
| 7321 | "Activity " + mComponent.toShortString() + |
| 7322 | " did not call through to super.onResume()"); |
| 7323 | } |
| 7324 | |
Todd Kennedy | ee8c9c6 | 2014-12-10 14:22:59 -0800 | [diff] [blame] | 7325 | // invisible activities must be finished before onResume() completes |
| 7326 | if (!mVisibleFromClient && !mFinished) { |
| 7327 | Log.w(TAG, "An activity without a UI must call finish() before onResume() completes"); |
| 7328 | if (getApplicationInfo().targetSdkVersion |
| 7329 | > android.os.Build.VERSION_CODES.LOLLIPOP_MR1) { |
| 7330 | throw new IllegalStateException( |
| 7331 | "Activity " + mComponent.toShortString() + |
| 7332 | " did not call finish() prior to onResume() completing"); |
| 7333 | } |
| 7334 | } |
| 7335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7336 | // 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] | 7337 | mCalled = false; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7338 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7339 | mFragments.dispatchResume(); |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 7340 | mFragments.execPendingActions(); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 7341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7342 | onPostResume(); |
| 7343 | if (!mCalled) { |
| 7344 | throw new SuperNotCalledException( |
| 7345 | "Activity " + mComponent.toShortString() + |
| 7346 | " did not call through to super.onPostResume()"); |
| 7347 | } |
| 7348 | } |
| 7349 | |
| 7350 | final void performPause() { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 7351 | mDoReportFullyDrawn = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7352 | mFragments.dispatchPause(); |
Dianne Hackborn | e794e9f | 2010-08-24 12:32:10 -0700 | [diff] [blame] | 7353 | mCalled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7354 | onPause(); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7355 | writeEventLog(LOG_AM_ON_PAUSE_CALLED, "performPause"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 7356 | mResumed = false; |
Dianne Hackborn | e794e9f | 2010-08-24 12:32:10 -0700 | [diff] [blame] | 7357 | if (!mCalled && getApplicationInfo().targetSdkVersion |
| 7358 | >= android.os.Build.VERSION_CODES.GINGERBREAD) { |
| 7359 | throw new SuperNotCalledException( |
| 7360 | "Activity " + mComponent.toShortString() + |
| 7361 | " did not call through to super.onPause()"); |
| 7362 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7363 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7364 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7365 | final void performUserLeaving() { |
| 7366 | onUserInteraction(); |
| 7367 | onUserLeaveHint(); |
| 7368 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7369 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7370 | final void performStop(boolean preserveWindow, String reason) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 7371 | mDoReportFullyDrawn = false; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7372 | mFragments.doLoaderStop(mChangingConfigurations /*retain*/); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 7373 | |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 7374 | // Disallow entering picture-in-picture after the activity has been stopped |
| 7375 | mCanEnterPictureInPicture = false; |
| 7376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7377 | if (!mStopped) { |
| 7378 | if (mWindow != null) { |
| 7379 | mWindow.closeAllPanels(); |
| 7380 | } |
| 7381 | |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 7382 | // If we're preserving the window, don't setStoppedState to true, since we |
| 7383 | // need the window started immediately again. Stopping the window will |
| 7384 | // destroys hardware resources and causes flicker. |
| 7385 | if (!preserveWindow && mToken != null && mParent == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7386 | WindowManagerGlobal.getInstance().setStoppedState(mToken, true); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 7387 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7388 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7389 | mFragments.dispatchStop(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7390 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7391 | mCalled = false; |
| 7392 | mInstrumentation.callActivityOnStop(this); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7393 | writeEventLog(LOG_AM_ON_STOP_CALLED, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7394 | if (!mCalled) { |
| 7395 | throw new SuperNotCalledException( |
| 7396 | "Activity " + mComponent.toShortString() + |
| 7397 | " did not call through to super.onStop()"); |
| 7398 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7399 | |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 7400 | synchronized (mManagedCursors) { |
| 7401 | final int N = mManagedCursors.size(); |
| 7402 | for (int i=0; i<N; i++) { |
| 7403 | ManagedCursor mc = mManagedCursors.get(i); |
| 7404 | if (!mc.mReleased) { |
| 7405 | mc.mCursor.deactivate(); |
| 7406 | mc.mReleased = true; |
| 7407 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7408 | } |
| 7409 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7411 | mStopped = true; |
| 7412 | } |
| 7413 | mResumed = false; |
| 7414 | } |
| 7415 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7416 | final void performDestroy() { |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 7417 | mDestroyed = true; |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 7418 | mWindow.destroy(); |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7419 | mFragments.dispatchDestroy(); |
| 7420 | onDestroy(); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7421 | writeEventLog(LOG_AM_ON_DESTROY_CALLED, "performDestroy"); |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7422 | mFragments.doLoaderDestroy(); |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 7423 | if (mVoiceInteractor != null) { |
| 7424 | mVoiceInteractor.detachActivity(); |
| 7425 | } |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7426 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7427 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7428 | final void dispatchMultiWindowModeChanged(boolean isInMultiWindowMode, |
| 7429 | Configuration newConfig) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7430 | if (DEBUG_LIFECYCLE) Slog.v(TAG, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7431 | "dispatchMultiWindowModeChanged " + this + ": " + isInMultiWindowMode |
| 7432 | + " " + newConfig); |
| 7433 | mFragments.dispatchMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7434 | if (mWindow != null) { |
| 7435 | mWindow.onMultiWindowModeChanged(); |
| 7436 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7437 | onMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7438 | } |
| 7439 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7440 | final void dispatchPictureInPictureModeChanged(boolean isInPictureInPictureMode, |
| 7441 | Configuration newConfig) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7442 | if (DEBUG_LIFECYCLE) Slog.v(TAG, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7443 | "dispatchPictureInPictureModeChanged " + this + ": " + isInPictureInPictureMode |
| 7444 | + " " + newConfig); |
| 7445 | mFragments.dispatchPictureInPictureModeChanged(isInPictureInPictureMode, newConfig); |
Winson Chung | 4d8681f | 2017-05-23 16:22:08 -0700 | [diff] [blame] | 7446 | if (mWindow != null) { |
| 7447 | mWindow.onPictureInPictureModeChanged(isInPictureInPictureMode); |
| 7448 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7449 | onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig); |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7450 | } |
| 7451 | |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7452 | /** |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 7453 | * @hide |
| 7454 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 7455 | @UnsupportedAppUsage |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 7456 | public final boolean isResumed() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7457 | return mResumed; |
| 7458 | } |
| 7459 | |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 7460 | private void storeHasCurrentPermissionRequest(Bundle bundle) { |
| 7461 | if (bundle != null && mHasCurrentPermissionsRequest) { |
| 7462 | bundle.putBoolean(HAS_CURENT_PERMISSIONS_REQUEST_KEY, true); |
| 7463 | } |
| 7464 | } |
| 7465 | |
| 7466 | private void restoreHasCurrentPermissionRequest(Bundle bundle) { |
| 7467 | if (bundle != null) { |
| 7468 | mHasCurrentPermissionsRequest = bundle.getBoolean( |
| 7469 | HAS_CURENT_PERMISSIONS_REQUEST_KEY, false); |
| 7470 | } |
| 7471 | } |
| 7472 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 7473 | @UnsupportedAppUsage |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 7474 | void dispatchActivityResult(String who, int requestCode, int resultCode, Intent data, |
| 7475 | String reason) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 7476 | if (false) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7477 | TAG, "Dispatching result: who=" + who + ", reqCode=" + requestCode |
| 7478 | + ", resCode=" + resultCode + ", data=" + data); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 7479 | mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7480 | if (who == null) { |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 7481 | onActivityResult(requestCode, resultCode, data); |
| 7482 | } else if (who.startsWith(REQUEST_PERMISSIONS_WHO_PREFIX)) { |
| 7483 | who = who.substring(REQUEST_PERMISSIONS_WHO_PREFIX.length()); |
| 7484 | if (TextUtils.isEmpty(who)) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 7485 | dispatchRequestPermissionsResult(requestCode, data); |
| 7486 | } else { |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 7487 | Fragment frag = mFragments.findFragmentByWho(who); |
| 7488 | if (frag != null) { |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 7489 | dispatchRequestPermissionsResultToFragment(requestCode, data, frag); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 7490 | } |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 7491 | } |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 7492 | } else if (who.startsWith("@android:view:")) { |
| 7493 | ArrayList<ViewRootImpl> views = WindowManagerGlobal.getInstance().getRootViews( |
| 7494 | getActivityToken()); |
| 7495 | for (ViewRootImpl viewRoot : views) { |
| 7496 | if (viewRoot.getView() != null |
| 7497 | && viewRoot.getView().dispatchActivityResult( |
| 7498 | who, requestCode, resultCode, data)) { |
| 7499 | return; |
| 7500 | } |
| 7501 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 7502 | } else if (who.startsWith(AUTO_FILL_AUTH_WHO_PREFIX)) { |
Svet Ganov | 00c771dc | 2017-02-19 00:06:22 -0800 | [diff] [blame] | 7503 | Intent resultData = (resultCode == Activity.RESULT_OK) ? data : null; |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 7504 | getAutofillManager().onAuthenticationResult(requestCode, resultData, getCurrentFocus()); |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 7505 | } else { |
| 7506 | Fragment frag = mFragments.findFragmentByWho(who); |
| 7507 | if (frag != null) { |
| 7508 | frag.onActivityResult(requestCode, resultCode, data); |
| 7509 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7510 | } |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 7511 | writeEventLog(LOG_AM_ON_ACTIVITY_RESULT_CALLED, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7512 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7513 | |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 7514 | /** |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 7515 | * Request to put this activity in a mode where the user is locked to a restricted set of |
| 7516 | * applications. |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 7517 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 7518 | * <p>If {@link DevicePolicyManager#isLockTaskPermitted(String)} returns {@code true} |
| 7519 | * for this component, the current task will be launched directly into LockTask mode. Only apps |
| 7520 | * whitelisted by {@link DevicePolicyManager#setLockTaskPackages(ComponentName, String[])} can |
| 7521 | * be launched while LockTask mode is active. The user will not be able to leave this mode |
| 7522 | * until this activity calls {@link #stopLockTask()}. Calling this method while the device is |
| 7523 | * already in LockTask mode has no effect. |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 7524 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 7525 | * <p>Otherwise, the current task will be launched into screen pinning mode. In this case, the |
| 7526 | * system will prompt the user with a dialog requesting permission to use this mode. |
| 7527 | * The user can exit at any time through instructions shown on the request dialog. Calling |
| 7528 | * {@link #stopLockTask()} will also terminate this mode. |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 7529 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 7530 | * <p><strong>Note:</strong> this method can only be called when the activity is foreground. |
| 7531 | * That is, between {@link #onResume()} and {@link #onPause()}. |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 7532 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 7533 | * @see #stopLockTask() |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 7534 | * @see android.R.attr#lockTaskMode |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 7535 | */ |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 7536 | public void startLockTask() { |
| 7537 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7538 | ActivityManager.getService().startLockTaskModeByToken(mToken); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 7539 | } catch (RemoteException e) { |
| 7540 | } |
| 7541 | } |
| 7542 | |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 7543 | /** |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 7544 | * Stop the current task from being locked. |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 7545 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 7546 | * <p>Called to end the LockTask or screen pinning mode started by {@link #startLockTask()}. |
| 7547 | * 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] | 7548 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 7549 | * <p><strong>Note:</strong> If the device is in LockTask mode that is not initially started |
| 7550 | * by this activity, then calling this method will not terminate the LockTask mode, but only |
| 7551 | * finish its own task. The device will remain in LockTask mode, until the activity which |
| 7552 | * started the LockTask mode calls this method, or until its whitelist authorization is revoked |
| 7553 | * by {@link DevicePolicyManager#setLockTaskPackages(ComponentName, String[])}. |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 7554 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 7555 | * @see #startLockTask() |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 7556 | * @see android.R.attr#lockTaskMode |
| 7557 | * @see ActivityManager#getLockTaskModeState() |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 7558 | */ |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 7559 | public void stopLockTask() { |
| 7560 | try { |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 7561 | ActivityManager.getService().stopLockTaskModeByToken(mToken); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 7562 | } catch (RemoteException e) { |
| 7563 | } |
| 7564 | } |
| 7565 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7566 | /** |
Craig Mautner | c21ae9e | 2015-04-15 09:45:42 -0700 | [diff] [blame] | 7567 | * Shows the user the system defined message for telling the user how to exit |
| 7568 | * lock task mode. The task containing this activity must be in lock task mode at the time |
| 7569 | * of this call for the message to be displayed. |
| 7570 | */ |
| 7571 | public void showLockTaskEscapeMessage() { |
| 7572 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7573 | ActivityManager.getService().showLockTaskEscapeMessage(mToken); |
Craig Mautner | c21ae9e | 2015-04-15 09:45:42 -0700 | [diff] [blame] | 7574 | } catch (RemoteException e) { |
| 7575 | } |
| 7576 | } |
| 7577 | |
| 7578 | /** |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 7579 | * Check whether the caption on freeform windows is displayed directly on the content. |
| 7580 | * |
| 7581 | * @return True if caption is displayed on content, false if it pushes the content down. |
| 7582 | * |
Elliot Waite | d5ed3bc | 2017-01-25 15:22:55 -0800 | [diff] [blame] | 7583 | * @see #setOverlayWithDecorCaptionEnabled(boolean) |
Wale Ogunwale | 724ca14 | 2017-04-24 13:40:34 -0700 | [diff] [blame] | 7584 | * @hide |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 7585 | */ |
| 7586 | public boolean isOverlayWithDecorCaptionEnabled() { |
| 7587 | return mWindow.isOverlayWithDecorCaptionEnabled(); |
| 7588 | } |
| 7589 | |
| 7590 | /** |
Filip Gruszczynski | 6325065 | 2015-11-18 14:43:01 -0800 | [diff] [blame] | 7591 | * Set whether the caption should displayed directly on the content rather than push it down. |
| 7592 | * |
| 7593 | * This affects only freeform windows since they display the caption and only the main |
| 7594 | * window of the activity. The caption is used to drag the window around and also shows |
| 7595 | * maximize and close action buttons. |
Wale Ogunwale | 724ca14 | 2017-04-24 13:40:34 -0700 | [diff] [blame] | 7596 | * @hide |
Filip Gruszczynski | 6325065 | 2015-11-18 14:43:01 -0800 | [diff] [blame] | 7597 | */ |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 7598 | public void setOverlayWithDecorCaptionEnabled(boolean enabled) { |
| 7599 | mWindow.setOverlayWithDecorCaptionEnabled(enabled); |
Filip Gruszczynski | 6325065 | 2015-11-18 14:43:01 -0800 | [diff] [blame] | 7600 | } |
| 7601 | |
| 7602 | /** |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7603 | * Interface for informing a translucent {@link Activity} once all visible activities below it |
| 7604 | * have completed drawing. This is necessary only after an {@link Activity} has been made |
| 7605 | * opaque using {@link Activity#convertFromTranslucent()} and before it has been drawn |
| 7606 | * translucent again following a call to {@link |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7607 | * Activity#convertToTranslucent(android.app.Activity.TranslucentConversionListener, |
| 7608 | * ActivityOptions)} |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 7609 | * |
| 7610 | * @hide |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7611 | */ |
Jose Lima | 1491485 | 2014-08-14 09:14:12 -0700 | [diff] [blame] | 7612 | @SystemApi |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7613 | public interface TranslucentConversionListener { |
| 7614 | /** |
| 7615 | * Callback made following {@link Activity#convertToTranslucent} once all visible Activities |
| 7616 | * below the top one have been redrawn. Following this callback it is safe to make the top |
| 7617 | * Activity translucent because the underlying Activity has been drawn. |
| 7618 | * |
| 7619 | * @param drawComplete True if the background Activity has drawn itself. False if a timeout |
| 7620 | * occurred waiting for the Activity to complete drawing. |
| 7621 | * |
| 7622 | * @see Activity#convertFromTranslucent() |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7623 | * @see Activity#convertToTranslucent(TranslucentConversionListener, ActivityOptions) |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7624 | */ |
| 7625 | public void onTranslucentConversionComplete(boolean drawComplete); |
| 7626 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 7627 | |
| 7628 | private void dispatchRequestPermissionsResult(int requestCode, Intent data) { |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 7629 | mHasCurrentPermissionsRequest = false; |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 7630 | // If the package installer crashed we may have not data - best effort. |
| 7631 | String[] permissions = (data != null) ? data.getStringArrayExtra( |
| 7632 | PackageManager.EXTRA_REQUEST_PERMISSIONS_NAMES) : new String[0]; |
| 7633 | final int[] grantResults = (data != null) ? data.getIntArrayExtra( |
| 7634 | PackageManager.EXTRA_REQUEST_PERMISSIONS_RESULTS) : new int[0]; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 7635 | onRequestPermissionsResult(requestCode, permissions, grantResults); |
| 7636 | } |
| 7637 | |
| 7638 | private void dispatchRequestPermissionsResultToFragment(int requestCode, Intent data, |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 7639 | Fragment fragment) { |
| 7640 | // If the package installer crashed we may have not data - best effort. |
| 7641 | String[] permissions = (data != null) ? data.getStringArrayExtra( |
| 7642 | PackageManager.EXTRA_REQUEST_PERMISSIONS_NAMES) : new String[0]; |
| 7643 | final int[] grantResults = (data != null) ? data.getIntArrayExtra( |
| 7644 | PackageManager.EXTRA_REQUEST_PERMISSIONS_RESULTS) : new int[0]; |
| 7645 | fragment.onRequestPermissionsResult(requestCode, permissions, grantResults); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 7646 | } |
| 7647 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 7648 | /** @hide */ |
| 7649 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7650 | public final void autofillClientAuthenticate(int authenticationId, IntentSender intent, |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 7651 | Intent fillInIntent) { |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 7652 | try { |
| 7653 | startIntentSenderForResultInner(intent, AUTO_FILL_AUTH_WHO_PREFIX, |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 7654 | authenticationId, fillInIntent, 0, 0, null); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 7655 | } catch (IntentSender.SendIntentException e) { |
| 7656 | Log.e(TAG, "authenticate() failed for intent:" + intent, e); |
| 7657 | } |
| 7658 | } |
| 7659 | |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 7660 | /** @hide */ |
| 7661 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7662 | public final void autofillClientResetableStateAvailable() { |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 7663 | mAutoFillResetNeeded = true; |
| 7664 | } |
| 7665 | |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 7666 | /** @hide */ |
| 7667 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7668 | public final boolean autofillClientRequestShowFillUi(@NonNull View anchor, int width, |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 7669 | int height, @Nullable Rect anchorBounds, IAutofillWindowPresenter presenter) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 7670 | final boolean wasShowing; |
| 7671 | |
| 7672 | if (mAutofillPopupWindow == null) { |
| 7673 | wasShowing = false; |
| 7674 | mAutofillPopupWindow = new AutofillPopupWindow(presenter); |
| 7675 | } else { |
| 7676 | wasShowing = mAutofillPopupWindow.isShowing(); |
| 7677 | } |
Svet Ganov | 374cae1 | 2017-05-10 13:42:33 -0700 | [diff] [blame] | 7678 | mAutofillPopupWindow.update(anchor, 0, 0, width, height, anchorBounds); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 7679 | |
| 7680 | return !wasShowing && mAutofillPopupWindow.isShowing(); |
| 7681 | } |
| 7682 | |
| 7683 | /** @hide */ |
| 7684 | @Override |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 7685 | public final void autofillClientDispatchUnhandledKey(@NonNull View anchor, |
| 7686 | @NonNull KeyEvent keyEvent) { |
| 7687 | ViewRootImpl rootImpl = anchor.getViewRootImpl(); |
| 7688 | if (rootImpl != null) { |
| 7689 | // dont care if anchorView is current focus, for example a custom view may only receive |
| 7690 | // touchEvent, not focusable but can still trigger autofill window. The Key handling |
| 7691 | // might be inside parent of the custom view. |
| 7692 | rootImpl.dispatchKeyFromAutofill(keyEvent); |
| 7693 | } |
| 7694 | } |
| 7695 | |
| 7696 | /** @hide */ |
| 7697 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7698 | public final boolean autofillClientRequestHideFillUi() { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 7699 | if (mAutofillPopupWindow == null) { |
| 7700 | return false; |
| 7701 | } |
| 7702 | mAutofillPopupWindow.dismiss(); |
| 7703 | mAutofillPopupWindow = null; |
| 7704 | return true; |
| 7705 | } |
| 7706 | |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 7707 | /** @hide */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 7708 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7709 | public final boolean autofillClientIsFillUiShowing() { |
| 7710 | return mAutofillPopupWindow != null && mAutofillPopupWindow.isShowing(); |
| 7711 | } |
| 7712 | |
| 7713 | /** @hide */ |
| 7714 | @Override |
| 7715 | @NonNull |
| 7716 | public final View[] autofillClientFindViewsByAutofillIdTraversal( |
| 7717 | @NonNull AutofillId[] autofillId) { |
| 7718 | final View[] views = new View[autofillId.length]; |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 7719 | final ArrayList<ViewRootImpl> roots = |
| 7720 | WindowManagerGlobal.getInstance().getRootViews(getActivityToken()); |
| 7721 | |
| 7722 | for (int rootNum = 0; rootNum < roots.size(); rootNum++) { |
| 7723 | final View rootView = roots.get(rootNum).getView(); |
| 7724 | |
| 7725 | if (rootView != null) { |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7726 | final int viewCount = autofillId.length; |
| 7727 | for (int viewNum = 0; viewNum < viewCount; viewNum++) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 7728 | if (views[viewNum] == null) { |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 7729 | views[viewNum] = rootView.findViewByAutofillIdTraversal( |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7730 | autofillId[viewNum].getViewId()); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 7731 | } |
| 7732 | } |
| 7733 | } |
| 7734 | } |
| 7735 | |
| 7736 | return views; |
| 7737 | } |
| 7738 | |
| 7739 | /** @hide */ |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 7740 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7741 | @Nullable |
| 7742 | public final View autofillClientFindViewByAutofillIdTraversal(AutofillId autofillId) { |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 7743 | final ArrayList<ViewRootImpl> roots = |
| 7744 | WindowManagerGlobal.getInstance().getRootViews(getActivityToken()); |
| 7745 | for (int rootNum = 0; rootNum < roots.size(); rootNum++) { |
| 7746 | final View rootView = roots.get(rootNum).getView(); |
| 7747 | |
| 7748 | if (rootView != null) { |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7749 | final View view = rootView.findViewByAutofillIdTraversal(autofillId.getViewId()); |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 7750 | if (view != null) { |
| 7751 | return view; |
| 7752 | } |
| 7753 | } |
| 7754 | } |
| 7755 | |
| 7756 | return null; |
| 7757 | } |
| 7758 | |
| 7759 | /** @hide */ |
| 7760 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7761 | public final @NonNull boolean[] autofillClientGetViewVisibility( |
| 7762 | @NonNull AutofillId[] autofillIds) { |
| 7763 | final int autofillIdCount = autofillIds.length; |
| 7764 | final boolean[] visible = new boolean[autofillIdCount]; |
| 7765 | for (int i = 0; i < autofillIdCount; i++) { |
| 7766 | final AutofillId autofillId = autofillIds[i]; |
| 7767 | final View view = autofillClientFindViewByAutofillIdTraversal(autofillId); |
| 7768 | if (view != null) { |
| 7769 | if (!autofillId.isVirtual()) { |
| 7770 | visible[i] = view.isVisibleToUser(); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 7771 | } else { |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7772 | visible[i] = view.isVisibleToUserForAutofill(autofillId.getVirtualChildId()); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 7773 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 7774 | } |
| 7775 | } |
Felipe Leme | 5b32ebe | 2018-02-15 12:52:19 -0800 | [diff] [blame] | 7776 | if (android.view.autofill.Helper.sVerbose) { |
| 7777 | Log.v(TAG, "autofillClientGetViewVisibility(): " + Arrays.toString(visible)); |
| 7778 | } |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7779 | return visible; |
| 7780 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 7781 | |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7782 | /** @hide */ |
| 7783 | public final @Nullable View autofillClientFindViewByAccessibilityIdTraversal(int viewId, |
| 7784 | int windowId) { |
| 7785 | final ArrayList<ViewRootImpl> roots = WindowManagerGlobal.getInstance() |
| 7786 | .getRootViews(getActivityToken()); |
| 7787 | for (int rootNum = 0; rootNum < roots.size(); rootNum++) { |
| 7788 | final View rootView = roots.get(rootNum).getView(); |
| 7789 | if (rootView != null && rootView.getAccessibilityWindowId() == windowId) { |
| 7790 | final View view = rootView.findViewByAccessibilityIdTraversal(viewId); |
| 7791 | if (view != null) { |
| 7792 | return view; |
| 7793 | } |
| 7794 | } |
| 7795 | } |
| 7796 | return null; |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 7797 | } |
| 7798 | |
| 7799 | /** @hide */ |
| 7800 | @Override |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7801 | public final @Nullable IBinder autofillClientGetActivityToken() { |
| 7802 | return getActivityToken(); |
| 7803 | } |
| 7804 | |
| 7805 | /** @hide */ |
| 7806 | @Override |
| 7807 | public final boolean autofillClientIsVisibleForAutofill() { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 7808 | return !mStopped; |
| 7809 | } |
| 7810 | |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 7811 | /** @hide */ |
| 7812 | @Override |
Felipe Leme | 42b9793 | 2018-02-20 13:04:31 -0800 | [diff] [blame] | 7813 | public final boolean autofillClientIsCompatibilityModeEnabled() { |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 7814 | return isAutofillCompatibilityEnabled(); |
| 7815 | } |
| 7816 | |
| 7817 | /** @hide */ |
| 7818 | @Override |
| 7819 | public final boolean isDisablingEnterExitEventForAutofill() { |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 7820 | return mAutoFillIgnoreFirstResumePause || !mResumed; |
| 7821 | } |
| 7822 | |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 7823 | /** |
| 7824 | * If set to true, this indicates to the system that it should never take a |
| 7825 | * screenshot of the activity to be used as a representation while it is not in a started state. |
| 7826 | * <p> |
| 7827 | * Note that the system may use the window background of the theme instead to represent |
| 7828 | * the window when it is not running. |
| 7829 | * <p> |
| 7830 | * Also note that in comparison to {@link android.view.WindowManager.LayoutParams#FLAG_SECURE}, |
| 7831 | * this only affects the behavior when the activity's screenshot would be used as a |
| 7832 | * representation when the activity is not in a started state, i.e. in Overview. The system may |
| 7833 | * still take screenshots of the activity in other contexts; for example, when the user takes a |
| 7834 | * screenshot of the entire screen, or when the active |
| 7835 | * {@link android.service.voice.VoiceInteractionService} requests a screenshot via |
| 7836 | * {@link android.service.voice.VoiceInteractionSession#SHOW_WITH_SCREENSHOT}. |
| 7837 | * |
| 7838 | * @param disable {@code true} to disable preview screenshots; {@code false} otherwise. |
| 7839 | * @hide |
| 7840 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 7841 | @UnsupportedAppUsage |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 7842 | public void setDisablePreviewScreenshots(boolean disable) { |
| 7843 | try { |
| 7844 | ActivityManager.getService().setDisablePreviewScreenshots(mToken, disable); |
| 7845 | } catch (RemoteException e) { |
| 7846 | Log.e(TAG, "Failed to call setDisablePreviewScreenshots", e); |
| 7847 | } |
| 7848 | } |
| 7849 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 7850 | /** |
| 7851 | * Specifies whether an {@link Activity} should be shown on top of the the lock screen whenever |
| 7852 | * the lockscreen is up and the activity is resumed. Normally an activity will be transitioned |
| 7853 | * to the stopped state if it is started while the lockscreen is up, but with this flag set the |
| 7854 | * activity will remain in the resumed state visible on-top of the lock screen. This value can |
| 7855 | * be set as a manifest attribute using {@link android.R.attr#showWhenLocked}. |
| 7856 | * |
| 7857 | * @param showWhenLocked {@code true} to show the {@link Activity} on top of the lock screen; |
| 7858 | * {@code false} otherwise. |
| 7859 | * @see #setTurnScreenOn(boolean) |
| 7860 | * @see android.R.attr#turnScreenOn |
| 7861 | * @see android.R.attr#showWhenLocked |
| 7862 | */ |
| 7863 | public void setShowWhenLocked(boolean showWhenLocked) { |
| 7864 | try { |
| 7865 | ActivityManager.getService().setShowWhenLocked(mToken, showWhenLocked); |
| 7866 | } catch (RemoteException e) { |
| 7867 | Log.e(TAG, "Failed to call setShowWhenLocked", e); |
| 7868 | } |
| 7869 | } |
| 7870 | |
| 7871 | /** |
| 7872 | * Specifies whether the screen should be turned on when the {@link Activity} is resumed. |
| 7873 | * Normally an activity will be transitioned to the stopped state if it is started while the |
| 7874 | * screen if off, but with this flag set the activity will cause the screen to turn on if the |
| 7875 | * activity will be visible and resumed due to the screen coming on. The screen will not be |
| 7876 | * turned on if the activity won't be visible after the screen is turned on. This flag is |
| 7877 | * normally used in conjunction with the {@link android.R.attr#showWhenLocked} flag to make sure |
| 7878 | * the activity is visible after the screen is turned on when the lockscreen is up. In addition, |
| 7879 | * if this flag is set and the activity calls {@link |
| 7880 | * KeyguardManager#requestDismissKeyguard(Activity, KeyguardManager.KeyguardDismissCallback)} |
| 7881 | * the screen will turn on. |
| 7882 | * |
| 7883 | * @param turnScreenOn {@code true} to turn on the screen; {@code false} otherwise. |
| 7884 | * |
| 7885 | * @see #setShowWhenLocked(boolean) |
| 7886 | * @see android.R.attr#turnScreenOn |
| 7887 | * @see android.R.attr#showWhenLocked |
| 7888 | */ |
| 7889 | public void setTurnScreenOn(boolean turnScreenOn) { |
| 7890 | try { |
| 7891 | ActivityManager.getService().setTurnScreenOn(mToken, turnScreenOn); |
| 7892 | } catch (RemoteException e) { |
| 7893 | Log.e(TAG, "Failed to call setTurnScreenOn", e); |
| 7894 | } |
| 7895 | } |
| 7896 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 7897 | /** |
| 7898 | * Registers remote animations per transition type for this activity. |
| 7899 | * |
| 7900 | * @param definition The remote animation definition that defines which transition whould run |
| 7901 | * which remote animation. |
| 7902 | * @hide |
| 7903 | */ |
| 7904 | @RequiresPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS) |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 7905 | @UnsupportedAppUsage |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 7906 | public void registerRemoteAnimations(RemoteAnimationDefinition definition) { |
| 7907 | try { |
| 7908 | ActivityManager.getService().registerRemoteAnimations(mToken, definition); |
| 7909 | } catch (RemoteException e) { |
| 7910 | Log.e(TAG, "Failed to call registerRemoteAnimations", e); |
| 7911 | } |
| 7912 | } |
| 7913 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 7914 | /** Log a lifecycle event for current user id and component class. */ |
| 7915 | private void writeEventLog(int event, String reason) { |
| 7916 | EventLog.writeEvent(event, UserHandle.myUserId(), getComponentName().getClassName(), |
| 7917 | reason); |
| 7918 | } |
| 7919 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7920 | class HostCallbacks extends FragmentHostCallback<Activity> { |
| 7921 | public HostCallbacks() { |
| 7922 | super(Activity.this /*activity*/); |
| 7923 | } |
| 7924 | |
| 7925 | @Override |
| 7926 | public void onDump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 7927 | Activity.this.dump(prefix, fd, writer, args); |
| 7928 | } |
| 7929 | |
| 7930 | @Override |
| 7931 | public boolean onShouldSaveFragmentState(Fragment fragment) { |
| 7932 | return !isFinishing(); |
| 7933 | } |
| 7934 | |
| 7935 | @Override |
| 7936 | public LayoutInflater onGetLayoutInflater() { |
| 7937 | final LayoutInflater result = Activity.this.getLayoutInflater(); |
| 7938 | if (onUseFragmentManagerInflaterFactory()) { |
| 7939 | return result.cloneInContext(Activity.this); |
| 7940 | } |
| 7941 | return result; |
| 7942 | } |
| 7943 | |
| 7944 | @Override |
| 7945 | public boolean onUseFragmentManagerInflaterFactory() { |
| 7946 | // Newer platform versions use the child fragment manager's LayoutInflaterFactory. |
| 7947 | return getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP; |
| 7948 | } |
| 7949 | |
| 7950 | @Override |
| 7951 | public Activity onGetHost() { |
| 7952 | return Activity.this; |
| 7953 | } |
| 7954 | |
| 7955 | @Override |
| 7956 | public void onInvalidateOptionsMenu() { |
| 7957 | Activity.this.invalidateOptionsMenu(); |
| 7958 | } |
| 7959 | |
| 7960 | @Override |
| 7961 | public void onStartActivityFromFragment(Fragment fragment, Intent intent, int requestCode, |
| 7962 | Bundle options) { |
| 7963 | Activity.this.startActivityFromFragment(fragment, intent, requestCode, options); |
| 7964 | } |
| 7965 | |
| 7966 | @Override |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 7967 | public void onStartActivityAsUserFromFragment( |
| 7968 | Fragment fragment, Intent intent, int requestCode, Bundle options, |
| 7969 | UserHandle user) { |
| 7970 | Activity.this.startActivityAsUserFromFragment( |
| 7971 | fragment, intent, requestCode, options, user); |
| 7972 | } |
| 7973 | |
| 7974 | @Override |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 7975 | public void onStartIntentSenderFromFragment(Fragment fragment, IntentSender intent, |
| 7976 | int requestCode, @Nullable Intent fillInIntent, int flagsMask, int flagsValues, |
| 7977 | int extraFlags, Bundle options) throws IntentSender.SendIntentException { |
| 7978 | if (mParent == null) { |
| 7979 | startIntentSenderForResultInner(intent, fragment.mWho, requestCode, fillInIntent, |
| 7980 | flagsMask, flagsValues, options); |
| 7981 | } else if (options != null) { |
| 7982 | mParent.startIntentSenderFromChildFragment(fragment, intent, requestCode, |
| 7983 | fillInIntent, flagsMask, flagsValues, extraFlags, options); |
| 7984 | } |
| 7985 | } |
| 7986 | |
| 7987 | @Override |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 7988 | public void onRequestPermissionsFromFragment(Fragment fragment, String[] permissions, |
| 7989 | int requestCode) { |
| 7990 | String who = REQUEST_PERMISSIONS_WHO_PREFIX + fragment.mWho; |
| 7991 | Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions); |
| 7992 | startActivityForResult(who, intent, requestCode, null); |
| 7993 | } |
| 7994 | |
| 7995 | @Override |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7996 | public boolean onHasWindowAnimations() { |
| 7997 | return getWindow() != null; |
| 7998 | } |
| 7999 | |
| 8000 | @Override |
| 8001 | public int onGetWindowAnimations() { |
| 8002 | final Window w = getWindow(); |
| 8003 | return (w == null) ? 0 : w.getAttributes().windowAnimations; |
| 8004 | } |
| 8005 | |
Todd Kennedy | 434bd65 | 2015-05-04 12:29:50 -0700 | [diff] [blame] | 8006 | @Override |
| 8007 | public void onAttachFragment(Fragment fragment) { |
| 8008 | Activity.this.onAttachFragment(fragment); |
| 8009 | } |
| 8010 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 8011 | @Nullable |
| 8012 | @Override |
Alan Viverette | 04fd470 | 2017-04-13 16:37:06 -0400 | [diff] [blame] | 8013 | public <T extends View> T onFindViewById(int id) { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 8014 | return Activity.this.findViewById(id); |
| 8015 | } |
| 8016 | |
| 8017 | @Override |
| 8018 | public boolean onHasView() { |
| 8019 | final Window w = getWindow(); |
| 8020 | return (w != null && w.peekDecorView() != null); |
| 8021 | } |
| 8022 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8023 | } |