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 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 20 | import android.os.PersistableBundle; |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 21 | import android.transition.Scene; |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 22 | import android.transition.TransitionManager; |
Dianne Hackborn | 3e82ba1 | 2013-07-16 13:23:55 -0700 | [diff] [blame] | 23 | import android.util.ArrayMap; |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 24 | import android.util.SuperNotCalledException; |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 25 | import android.widget.Toolbar; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 26 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 27 | import com.android.internal.app.IVoiceInteractor; |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 28 | import com.android.internal.app.WindowDecorActionBar; |
| 29 | import com.android.internal.app.ToolbarActionBar; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 30 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 31 | import android.annotation.IntDef; |
| 32 | import android.annotation.Nullable; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 33 | import android.annotation.SystemApi; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 34 | import android.app.admin.DevicePolicyManager; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 35 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.content.ComponentName; |
| 37 | import android.content.ContentResolver; |
| 38 | import android.content.Context; |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 39 | import android.content.CursorLoader; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 40 | import android.content.IIntentSender; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 41 | import android.content.Intent; |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 42 | import android.content.IntentSender; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import android.content.SharedPreferences; |
| 44 | import android.content.pm.ActivityInfo; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 45 | import android.content.pm.PackageManager; |
| 46 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.content.res.Configuration; |
| 48 | import android.content.res.Resources; |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 49 | import android.content.res.TypedArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.database.Cursor; |
| 51 | import android.graphics.Bitmap; |
| 52 | import android.graphics.Canvas; |
| 53 | import android.graphics.drawable.Drawable; |
| 54 | import android.media.AudioManager; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 55 | import android.media.session.MediaController; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.net.Uri; |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 57 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.os.Handler; |
| 60 | import android.os.IBinder; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 61 | import android.os.Looper; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 62 | import android.os.Parcelable; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 63 | import android.os.RemoteException; |
Brad Fitzpatrick | 7580357 | 2011-01-13 14:21:03 -0800 | [diff] [blame] | 64 | import android.os.StrictMode; |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 65 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.text.Selection; |
| 67 | import android.text.SpannableStringBuilder; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 68 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.text.method.TextKeyListener; |
| 70 | import android.util.AttributeSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.util.EventLog; |
| 72 | import android.util.Log; |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 73 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 74 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.util.SparseArray; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 76 | import android.view.ActionMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import android.view.ContextMenu; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 78 | import android.view.ContextMenu.ContextMenuInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | import android.view.ContextThemeWrapper; |
| 80 | import android.view.KeyEvent; |
| 81 | import android.view.LayoutInflater; |
| 82 | import android.view.Menu; |
| 83 | import android.view.MenuInflater; |
| 84 | import android.view.MenuItem; |
| 85 | import android.view.MotionEvent; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame^] | 86 | import android.view.PhoneWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | import android.view.View; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 88 | import android.view.View.OnCreateContextMenuListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | import android.view.ViewGroup; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 90 | import android.view.ViewGroup.LayoutParams; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | import android.view.ViewManager; |
| 92 | import android.view.Window; |
| 93 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 94 | import android.view.WindowManagerGlobal; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 95 | import android.view.accessibility.AccessibilityEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.widget.AdapterView; |
| 97 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 98 | import java.io.FileDescriptor; |
| 99 | import java.io.PrintWriter; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 100 | import java.lang.annotation.Retention; |
| 101 | import java.lang.annotation.RetentionPolicy; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 102 | import java.util.ArrayList; |
| 103 | import java.util.HashMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * An activity is a single, focused thing that the user can do. Almost all |
| 107 | * activities interact with the user, so the Activity class takes care of |
| 108 | * creating a window for you in which you can place your UI with |
| 109 | * {@link #setContentView}. While activities are often presented to the user |
| 110 | * as full-screen windows, they can also be used in other ways: as floating |
| 111 | * windows (via a theme with {@link android.R.attr#windowIsFloating} set) |
| 112 | * or embedded inside of another activity (using {@link ActivityGroup}). |
| 113 | * |
| 114 | * There are two methods almost all subclasses of Activity will implement: |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 115 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | * <ul> |
| 117 | * <li> {@link #onCreate} is where you initialize your activity. Most |
| 118 | * importantly, here you will usually call {@link #setContentView(int)} |
| 119 | * with a layout resource defining your UI, and using {@link #findViewById} |
| 120 | * to retrieve the widgets in that UI that you need to interact with |
| 121 | * programmatically. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 122 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | * <li> {@link #onPause} is where you deal with the user leaving your |
| 124 | * activity. Most importantly, any changes made by the user should at this |
| 125 | * point be committed (usually to the |
| 126 | * {@link android.content.ContentProvider} holding the data). |
| 127 | * </ul> |
| 128 | * |
| 129 | * <p>To be of use with {@link android.content.Context#startActivity Context.startActivity()}, all |
| 130 | * activity classes must have a corresponding |
| 131 | * {@link android.R.styleable#AndroidManifestActivity <activity>} |
| 132 | * declaration in their package's <code>AndroidManifest.xml</code>.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 133 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | * <p>Topics covered here: |
| 135 | * <ol> |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 136 | * <li><a href="#Fragments">Fragments</a> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | * <li><a href="#ActivityLifecycle">Activity Lifecycle</a> |
| 138 | * <li><a href="#ConfigurationChanges">Configuration Changes</a> |
| 139 | * <li><a href="#StartingActivities">Starting Activities and Getting Results</a> |
| 140 | * <li><a href="#SavingPersistentState">Saving Persistent State</a> |
| 141 | * <li><a href="#Permissions">Permissions</a> |
| 142 | * <li><a href="#ProcessLifecycle">Process Lifecycle</a> |
| 143 | * </ol> |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 144 | * |
| 145 | * <div class="special reference"> |
| 146 | * <h3>Developer Guides</h3> |
| 147 | * <p>The Activity class is an important part of an application's overall lifecycle, |
| 148 | * and the way activities are launched and put together is a fundamental |
| 149 | * part of the platform's application model. For a detailed perspective on the structure of an |
| 150 | * Android application and how activities behave, please read the |
| 151 | * <a href="{@docRoot}guide/topics/fundamentals.html">Application Fundamentals</a> and |
| 152 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back Stack</a> |
| 153 | * developer guides.</p> |
| 154 | * |
| 155 | * <p>You can also find a detailed discussion about how to create activities in the |
| 156 | * <a href="{@docRoot}guide/topics/fundamentals/activities.html">Activities</a> |
| 157 | * developer guide.</p> |
| 158 | * </div> |
| 159 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 160 | * <a name="Fragments"></a> |
| 161 | * <h3>Fragments</h3> |
| 162 | * |
| 163 | * <p>Starting with {@link android.os.Build.VERSION_CODES#HONEYCOMB}, Activity |
| 164 | * implementations can make use of the {@link Fragment} class to better |
| 165 | * modularize their code, build more sophisticated user interfaces for larger |
| 166 | * screens, and help scale their application between small and large screens. |
| 167 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | * <a name="ActivityLifecycle"></a> |
| 169 | * <h3>Activity Lifecycle</h3> |
| 170 | * |
| 171 | * <p>Activities in the system are managed as an <em>activity stack</em>. |
| 172 | * When a new activity is started, it is placed on the top of the stack |
| 173 | * and becomes the running activity -- the previous activity always remains |
| 174 | * below it in the stack, and will not come to the foreground again until |
| 175 | * the new activity exits.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 176 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | * <p>An activity has essentially four states:</p> |
| 178 | * <ul> |
| 179 | * <li> If an activity in the foreground of the screen (at the top of |
| 180 | * the stack), |
| 181 | * it is <em>active</em> or <em>running</em>. </li> |
| 182 | * <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] | 183 | * 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] | 184 | * is <em>paused</em>. A paused activity is completely alive (it |
| 185 | * maintains all state and member information and remains attached to |
| 186 | * the window manager), but can be killed by the system in extreme |
| 187 | * low memory situations. |
| 188 | * <li>If an activity is completely obscured by another activity, |
| 189 | * it is <em>stopped</em>. It still retains all state and member information, |
| 190 | * however, it is no longer visible to the user so its window is hidden |
| 191 | * and it will often be killed by the system when memory is needed |
| 192 | * elsewhere.</li> |
| 193 | * <li>If an activity is paused or stopped, the system can drop the activity |
| 194 | * from memory by either asking it to finish, or simply killing its |
| 195 | * process. When it is displayed again to the user, it must be |
| 196 | * completely restarted and restored to its previous state.</li> |
| 197 | * </ul> |
| 198 | * |
| 199 | * <p>The following diagram shows the important state paths of an Activity. |
| 200 | * The square rectangles represent callback methods you can implement to |
| 201 | * perform operations when the Activity moves between states. The colored |
| 202 | * ovals are major states the Activity can be in.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 203 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | * <p><img src="../../../images/activity_lifecycle.png" |
| 205 | * alt="State diagram for an Android Activity Lifecycle." border="0" /></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 206 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | * <p>There are three key loops you may be interested in monitoring within your |
| 208 | * activity: |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 209 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | * <ul> |
| 211 | * <li>The <b>entire lifetime</b> of an activity happens between the first call |
| 212 | * to {@link android.app.Activity#onCreate} through to a single final call |
| 213 | * to {@link android.app.Activity#onDestroy}. An activity will do all setup |
| 214 | * of "global" state in onCreate(), and release all remaining resources in |
| 215 | * onDestroy(). For example, if it has a thread running in the background |
| 216 | * to download data from the network, it may create that thread in onCreate() |
| 217 | * and then stop the thread in onDestroy(). |
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 | * <li>The <b>visible lifetime</b> of an activity happens between a call to |
| 220 | * {@link android.app.Activity#onStart} until a corresponding call to |
| 221 | * {@link android.app.Activity#onStop}. During this time the user can see the |
| 222 | * activity on-screen, though it may not be in the foreground and interacting |
| 223 | * with the user. Between these two methods you can maintain resources that |
| 224 | * are needed to show the activity to the user. For example, you can register |
| 225 | * a {@link android.content.BroadcastReceiver} in onStart() to monitor for changes |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 226 | * that impact your UI, and unregister it in onStop() when the user no |
| 227 | * 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] | 228 | * can be called multiple times, as the activity becomes visible and hidden |
| 229 | * to the user. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 230 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | * <li>The <b>foreground lifetime</b> of an activity happens between a call to |
| 232 | * {@link android.app.Activity#onResume} until a corresponding call to |
| 233 | * {@link android.app.Activity#onPause}. During this time the activity is |
| 234 | * in front of all other activities and interacting with the user. An activity |
| 235 | * can frequently go between the resumed and paused states -- for example when |
| 236 | * the device goes to sleep, when an activity result is delivered, when a new |
| 237 | * intent is delivered -- so the code in these methods should be fairly |
| 238 | * lightweight. |
| 239 | * </ul> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 240 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | * <p>The entire lifecycle of an activity is defined by the following |
| 242 | * Activity methods. All of these are hooks that you can override |
| 243 | * to do appropriate work when the activity changes state. All |
| 244 | * activities will implement {@link android.app.Activity#onCreate} |
| 245 | * to do their initial setup; many will also implement |
| 246 | * {@link android.app.Activity#onPause} to commit changes to data and |
| 247 | * otherwise prepare to stop interacting with the user. You should always |
| 248 | * call up to your superclass when implementing these methods.</p> |
| 249 | * |
| 250 | * </p> |
| 251 | * <pre class="prettyprint"> |
| 252 | * public class Activity extends ApplicationContext { |
| 253 | * protected void onCreate(Bundle savedInstanceState); |
| 254 | * |
| 255 | * protected void onStart(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 256 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | * protected void onRestart(); |
| 258 | * |
| 259 | * protected void onResume(); |
| 260 | * |
| 261 | * protected void onPause(); |
| 262 | * |
| 263 | * protected void onStop(); |
| 264 | * |
| 265 | * protected void onDestroy(); |
| 266 | * } |
| 267 | * </pre> |
| 268 | * |
| 269 | * <p>In general the movement through an activity's lifecycle looks like |
| 270 | * this:</p> |
| 271 | * |
| 272 | * <table border="2" width="85%" align="center" frame="hsides" rules="rows"> |
| 273 | * <colgroup align="left" span="3" /> |
| 274 | * <colgroup align="left" /> |
| 275 | * <colgroup align="center" /> |
| 276 | * <colgroup align="center" /> |
| 277 | * |
| 278 | * <thead> |
| 279 | * <tr><th colspan="3">Method</th> <th>Description</th> <th>Killable?</th> <th>Next</th></tr> |
| 280 | * </thead> |
| 281 | * |
| 282 | * <tbody> |
| 283 | * <tr><th colspan="3" align="left" border="0">{@link android.app.Activity#onCreate onCreate()}</th> |
| 284 | * <td>Called when the activity is first created. |
| 285 | * This is where you should do all of your normal static set up: |
| 286 | * create views, bind data to lists, etc. This method also |
| 287 | * provides you with a Bundle containing the activity's previously |
| 288 | * frozen state, if there was one. |
| 289 | * <p>Always followed by <code>onStart()</code>.</td> |
| 290 | * <td align="center">No</td> |
| 291 | * <td align="center"><code>onStart()</code></td> |
| 292 | * </tr> |
| 293 | * |
| 294 | * <tr><td rowspan="5" style="border-left: none; border-right: none;"> </td> |
| 295 | * <th colspan="2" align="left" border="0">{@link android.app.Activity#onRestart onRestart()}</th> |
| 296 | * <td>Called after your activity has been stopped, prior to it being |
| 297 | * started again. |
| 298 | * <p>Always followed by <code>onStart()</code></td> |
| 299 | * <td align="center">No</td> |
| 300 | * <td align="center"><code>onStart()</code></td> |
| 301 | * </tr> |
| 302 | * |
| 303 | * <tr><th colspan="2" align="left" border="0">{@link android.app.Activity#onStart onStart()}</th> |
| 304 | * <td>Called when the activity is becoming visible to the user. |
| 305 | * <p>Followed by <code>onResume()</code> if the activity comes |
| 306 | * to the foreground, or <code>onStop()</code> if it becomes hidden.</td> |
| 307 | * <td align="center">No</td> |
| 308 | * <td align="center"><code>onResume()</code> or <code>onStop()</code></td> |
| 309 | * </tr> |
| 310 | * |
| 311 | * <tr><td rowspan="2" style="border-left: none;"> </td> |
| 312 | * <th align="left" border="0">{@link android.app.Activity#onResume onResume()}</th> |
| 313 | * <td>Called when the activity will start |
| 314 | * interacting with the user. At this point your activity is at |
| 315 | * the top of the activity stack, with user input going to it. |
| 316 | * <p>Always followed by <code>onPause()</code>.</td> |
| 317 | * <td align="center">No</td> |
| 318 | * <td align="center"><code>onPause()</code></td> |
| 319 | * </tr> |
| 320 | * |
| 321 | * <tr><th align="left" border="0">{@link android.app.Activity#onPause onPause()}</th> |
| 322 | * <td>Called when the system is about to start resuming a previous |
| 323 | * activity. This is typically used to commit unsaved changes to |
| 324 | * persistent data, stop animations and other things that may be consuming |
| 325 | * CPU, etc. Implementations of this method must be very quick because |
| 326 | * the next activity will not be resumed until this method returns. |
| 327 | * <p>Followed by either <code>onResume()</code> if the activity |
| 328 | * returns back to the front, or <code>onStop()</code> if it becomes |
| 329 | * invisible to the user.</td> |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 330 | * <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] | 331 | * <td align="center"><code>onResume()</code> or<br> |
| 332 | * <code>onStop()</code></td> |
| 333 | * </tr> |
| 334 | * |
| 335 | * <tr><th colspan="2" align="left" border="0">{@link android.app.Activity#onStop onStop()}</th> |
| 336 | * <td>Called when the activity is no longer visible to the user, because |
| 337 | * another activity has been resumed and is covering this one. This |
| 338 | * may happen either because a new activity is being started, an existing |
| 339 | * one is being brought in front of this one, or this one is being |
| 340 | * destroyed. |
| 341 | * <p>Followed by either <code>onRestart()</code> if |
| 342 | * this activity is coming back to interact with the user, or |
| 343 | * <code>onDestroy()</code> if this activity is going away.</td> |
| 344 | * <td align="center"><font color="#800000"><strong>Yes</strong></font></td> |
| 345 | * <td align="center"><code>onRestart()</code> or<br> |
| 346 | * <code>onDestroy()</code></td> |
| 347 | * </tr> |
| 348 | * |
| 349 | * <tr><th colspan="3" align="left" border="0">{@link android.app.Activity#onDestroy onDestroy()}</th> |
| 350 | * <td>The final call you receive before your |
| 351 | * activity is destroyed. This can happen either because the |
| 352 | * activity is finishing (someone called {@link Activity#finish} on |
| 353 | * it, or because the system is temporarily destroying this |
| 354 | * instance of the activity to save space. You can distinguish |
| 355 | * between these two scenarios with the {@link |
| 356 | * Activity#isFinishing} method.</td> |
| 357 | * <td align="center"><font color="#800000"><strong>Yes</strong></font></td> |
| 358 | * <td align="center"><em>nothing</em></td> |
| 359 | * </tr> |
| 360 | * </tbody> |
| 361 | * </table> |
| 362 | * |
| 363 | * <p>Note the "Killable" column in the above table -- for those methods that |
| 364 | * 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] | 365 | * 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] | 366 | * of its code being executed. Because of this, you should use the |
| 367 | * {@link #onPause} method to write any persistent data (such as user edits) |
| 368 | * to storage. In addition, the method |
| 369 | * {@link #onSaveInstanceState(Bundle)} is called before placing the activity |
| 370 | * in such a background state, allowing you to save away any dynamic instance |
| 371 | * state in your activity into the given Bundle, to be later received in |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 372 | * {@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] | 373 | * See the <a href="#ProcessLifecycle">Process Lifecycle</a> |
| 374 | * section for more information on how the lifecycle of a process is tied |
| 375 | * to the activities it is hosting. Note that it is important to save |
| 376 | * persistent data in {@link #onPause} instead of {@link #onSaveInstanceState} |
Daisuke Miyakawa | 5c40f3f | 2011-02-15 13:24:36 -0800 | [diff] [blame] | 377 | * 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] | 378 | * be called in every situation as described in its documentation.</p> |
| 379 | * |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 380 | * <p class="note">Be aware that these semantics will change slightly between |
| 381 | * applications targeting platforms starting with {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 382 | * vs. those targeting prior platforms. Starting with Honeycomb, an application |
| 383 | * is not in the killable state until its {@link #onStop} has returned. This |
| 384 | * impacts when {@link #onSaveInstanceState(Bundle)} may be called (it may be |
| 385 | * safely called after {@link #onPause()} and allows and application to safely |
| 386 | * wait until {@link #onStop()} to save persistent state.</p> |
| 387 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | * <p>For those methods that are not marked as being killable, the activity's |
| 389 | * process will not be killed by the system starting from the time the method |
| 390 | * is called and continuing after it returns. Thus an activity is in the killable |
| 391 | * state, for example, between after <code>onPause()</code> to the start of |
| 392 | * <code>onResume()</code>.</p> |
| 393 | * |
| 394 | * <a name="ConfigurationChanges"></a> |
| 395 | * <h3>Configuration Changes</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 396 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | * <p>If the configuration of the device (as defined by the |
| 398 | * {@link Configuration Resources.Configuration} class) changes, |
| 399 | * then anything displaying a user interface will need to update to match that |
| 400 | * configuration. Because Activity is the primary mechanism for interacting |
| 401 | * with the user, it includes special support for handling configuration |
| 402 | * changes.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 403 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | * <p>Unless you specify otherwise, a configuration change (such as a change |
| 405 | * in screen orientation, language, input devices, etc) will cause your |
| 406 | * current activity to be <em>destroyed</em>, going through the normal activity |
| 407 | * lifecycle process of {@link #onPause}, |
| 408 | * {@link #onStop}, and {@link #onDestroy} as appropriate. If the activity |
| 409 | * had been in the foreground or visible to the user, once {@link #onDestroy} is |
| 410 | * called in that instance then a new instance of the activity will be |
| 411 | * created, with whatever savedInstanceState the previous instance had generated |
| 412 | * from {@link #onSaveInstanceState}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 413 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | * <p>This is done because any application resource, |
| 415 | * including layout files, can change based on any configuration value. Thus |
| 416 | * the only safe way to handle a configuration change is to re-retrieve all |
| 417 | * resources, including layouts, drawables, and strings. Because activities |
| 418 | * must already know how to save their state and re-create themselves from |
| 419 | * that state, this is a convenient way to have an activity restart itself |
| 420 | * with a new configuration.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 421 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | * <p>In some special cases, you may want to bypass restarting of your |
| 423 | * activity based on one or more types of configuration changes. This is |
| 424 | * done with the {@link android.R.attr#configChanges android:configChanges} |
| 425 | * attribute in its manifest. For any types of configuration changes you say |
| 426 | * that you handle there, you will receive a call to your current activity's |
| 427 | * {@link #onConfigurationChanged} method instead of being restarted. If |
| 428 | * a configuration change involves any that you do not handle, however, the |
| 429 | * activity will still be restarted and {@link #onConfigurationChanged} |
| 430 | * will not be called.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 431 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | * <a name="StartingActivities"></a> |
| 433 | * <h3>Starting Activities and Getting Results</h3> |
| 434 | * |
| 435 | * <p>The {@link android.app.Activity#startActivity} |
| 436 | * method is used to start a |
| 437 | * new activity, which will be placed at the top of the activity stack. It |
| 438 | * takes a single argument, an {@link android.content.Intent Intent}, |
| 439 | * which describes the activity |
| 440 | * to be executed.</p> |
| 441 | * |
| 442 | * <p>Sometimes you want to get a result back from an activity when it |
| 443 | * ends. For example, you may start an activity that lets the user pick |
| 444 | * a person in a list of contacts; when it ends, it returns the person |
| 445 | * that was selected. To do this, you call the |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 446 | * {@link android.app.Activity#startActivityForResult(Intent, int)} |
| 447 | * 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] | 448 | * will come back through your {@link android.app.Activity#onActivityResult} |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 449 | * method.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | * |
| 451 | * <p>When an activity exits, it can call |
| 452 | * {@link android.app.Activity#setResult(int)} |
| 453 | * to return data back to its parent. It must always supply a result code, |
| 454 | * which can be the standard results RESULT_CANCELED, RESULT_OK, or any |
| 455 | * custom values starting at RESULT_FIRST_USER. In addition, it can optionally |
| 456 | * return back an Intent containing any additional data it wants. All of this |
| 457 | * information appears back on the |
| 458 | * parent's <code>Activity.onActivityResult()</code>, along with the integer |
| 459 | * identifier it originally supplied.</p> |
| 460 | * |
| 461 | * <p>If a child activity fails for any reason (such as crashing), the parent |
| 462 | * activity will receive a result with the code RESULT_CANCELED.</p> |
| 463 | * |
| 464 | * <pre class="prettyprint"> |
| 465 | * public class MyActivity extends Activity { |
| 466 | * ... |
| 467 | * |
| 468 | * static final int PICK_CONTACT_REQUEST = 0; |
| 469 | * |
Michael Wright | 5438e4e | 2014-07-25 14:05:42 -0700 | [diff] [blame] | 470 | * public boolean onKeyDown(int keyCode, KeyEvent event) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | * if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { |
| 472 | * // When the user center presses, let them pick a contact. |
| 473 | * startActivityForResult( |
| 474 | * new Intent(Intent.ACTION_PICK, |
| 475 | * new Uri("content://contacts")), |
| 476 | * PICK_CONTACT_REQUEST); |
| 477 | * return true; |
| 478 | * } |
| 479 | * return false; |
| 480 | * } |
| 481 | * |
| 482 | * protected void onActivityResult(int requestCode, int resultCode, |
| 483 | * Intent data) { |
| 484 | * if (requestCode == PICK_CONTACT_REQUEST) { |
| 485 | * if (resultCode == RESULT_OK) { |
| 486 | * // A contact was picked. Here we will just display it |
| 487 | * // to the user. |
| 488 | * startActivity(new Intent(Intent.ACTION_VIEW, data)); |
| 489 | * } |
| 490 | * } |
| 491 | * } |
| 492 | * } |
| 493 | * </pre> |
| 494 | * |
| 495 | * <a name="SavingPersistentState"></a> |
| 496 | * <h3>Saving Persistent State</h3> |
| 497 | * |
| 498 | * <p>There are generally two kinds of persistent state than an activity |
| 499 | * will deal with: shared document-like data (typically stored in a SQLite |
| 500 | * database using a {@linkplain android.content.ContentProvider content provider}) |
| 501 | * and internal state such as user preferences.</p> |
| 502 | * |
| 503 | * <p>For content provider data, we suggest that activities use a |
| 504 | * "edit in place" user model. That is, any edits a user makes are effectively |
| 505 | * made immediately without requiring an additional confirmation step. |
| 506 | * Supporting this model is generally a simple matter of following two rules:</p> |
| 507 | * |
| 508 | * <ul> |
| 509 | * <li> <p>When creating a new document, the backing database entry or file for |
| 510 | * it is created immediately. For example, if the user chooses to write |
| 511 | * a new e-mail, a new entry for that e-mail is created as soon as they |
| 512 | * start entering data, so that if they go to any other activity after |
| 513 | * that point this e-mail will now appear in the list of drafts.</p> |
| 514 | * <li> <p>When an activity's <code>onPause()</code> method is called, it should |
| 515 | * commit to the backing content provider or file any changes the user |
| 516 | * has made. This ensures that those changes will be seen by any other |
| 517 | * activity that is about to run. You will probably want to commit |
| 518 | * your data even more aggressively at key times during your |
| 519 | * activity's lifecycle: for example before starting a new |
| 520 | * activity, before finishing your own activity, when the user |
| 521 | * switches between input fields, etc.</p> |
| 522 | * </ul> |
| 523 | * |
| 524 | * <p>This model is designed to prevent data loss when a user is navigating |
| 525 | * between activities, and allows the system to safely kill an activity (because |
| 526 | * system resources are needed somewhere else) at any time after it has been |
| 527 | * paused. Note this implies |
| 528 | * that the user pressing BACK from your activity does <em>not</em> |
| 529 | * mean "cancel" -- it means to leave the activity with its current contents |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 530 | * 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] | 531 | * some other mechanism, such as an explicit "revert" or "undo" option.</p> |
| 532 | * |
| 533 | * <p>See the {@linkplain android.content.ContentProvider content package} for |
| 534 | * more information about content providers. These are a key aspect of how |
| 535 | * different activities invoke and propagate data between themselves.</p> |
| 536 | * |
| 537 | * <p>The Activity class also provides an API for managing internal persistent state |
| 538 | * associated with an activity. This can be used, for example, to remember |
| 539 | * the user's preferred initial display in a calendar (day view or week view) |
| 540 | * or the user's default home page in a web browser.</p> |
| 541 | * |
| 542 | * <p>Activity persistent state is managed |
| 543 | * with the method {@link #getPreferences}, |
| 544 | * allowing you to retrieve and |
| 545 | * modify a set of name/value pairs associated with the activity. To use |
| 546 | * preferences that are shared across multiple application components |
| 547 | * (activities, receivers, services, providers), you can use the underlying |
| 548 | * {@link Context#getSharedPreferences Context.getSharedPreferences()} method |
| 549 | * to retrieve a preferences |
| 550 | * object stored under a specific name. |
| 551 | * (Note that it is not possible to share settings data across application |
| 552 | * packages -- for that you will need a content provider.)</p> |
| 553 | * |
| 554 | * <p>Here is an excerpt from a calendar activity that stores the user's |
| 555 | * preferred view mode in its persistent settings:</p> |
| 556 | * |
| 557 | * <pre class="prettyprint"> |
| 558 | * public class CalendarActivity extends Activity { |
| 559 | * ... |
| 560 | * |
| 561 | * static final int DAY_VIEW_MODE = 0; |
| 562 | * static final int WEEK_VIEW_MODE = 1; |
| 563 | * |
| 564 | * private SharedPreferences mPrefs; |
| 565 | * private int mCurViewMode; |
| 566 | * |
| 567 | * protected void onCreate(Bundle savedInstanceState) { |
| 568 | * super.onCreate(savedInstanceState); |
| 569 | * |
| 570 | * SharedPreferences mPrefs = getSharedPreferences(); |
Quddus Chong | 3fa98cb | 2012-04-13 11:17:24 -0700 | [diff] [blame] | 571 | * mCurViewMode = mPrefs.getInt("view_mode", DAY_VIEW_MODE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | * } |
| 573 | * |
| 574 | * protected void onPause() { |
| 575 | * super.onPause(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 576 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 577 | * SharedPreferences.Editor ed = mPrefs.edit(); |
| 578 | * ed.putInt("view_mode", mCurViewMode); |
| 579 | * ed.commit(); |
| 580 | * } |
| 581 | * } |
| 582 | * </pre> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 583 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | * <a name="Permissions"></a> |
| 585 | * <h3>Permissions</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 586 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | * <p>The ability to start a particular Activity can be enforced when it is |
| 588 | * declared in its |
| 589 | * manifest's {@link android.R.styleable#AndroidManifestActivity <activity>} |
| 590 | * tag. By doing so, other applications will need to declare a corresponding |
| 591 | * {@link android.R.styleable#AndroidManifestUsesPermission <uses-permission>} |
| 592 | * element in their own manifest to be able to start that activity. |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 593 | * |
| 594 | * <p>When starting an Activity you can set {@link Intent#FLAG_GRANT_READ_URI_PERMISSION |
| 595 | * Intent.FLAG_GRANT_READ_URI_PERMISSION} and/or {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 596 | * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} on the Intent. This will grant the |
| 597 | * Activity access to the specific URIs in the Intent. Access will remain |
| 598 | * until the Activity has finished (it will remain across the hosting |
| 599 | * process being killed and other temporary destruction). As of |
| 600 | * {@link android.os.Build.VERSION_CODES#GINGERBREAD}, if the Activity |
| 601 | * was already created and a new Intent is being delivered to |
| 602 | * {@link #onNewIntent(Intent)}, any newly granted URI permissions will be added |
| 603 | * to the existing ones it holds. |
| 604 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 605 | * <p>See the <a href="{@docRoot}guide/topics/security/security.html">Security and Permissions</a> |
| 606 | * document for more information on permissions and security in general. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 607 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | * <a name="ProcessLifecycle"></a> |
| 609 | * <h3>Process Lifecycle</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 610 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 611 | * <p>The Android system attempts to keep application process around for as |
| 612 | * long as possible, but eventually will need to remove old processes when |
| 613 | * memory runs low. As described in <a href="#ActivityLifecycle">Activity |
| 614 | * Lifecycle</a>, the decision about which process to remove is intimately |
| 615 | * tied to the state of the user's interaction with it. In general, there |
| 616 | * are four states a process can be in based on the activities running in it, |
| 617 | * listed here in order of importance. The system will kill less important |
| 618 | * processes (the last ones) before it resorts to killing more important |
| 619 | * processes (the first ones). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 620 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | * <ol> |
| 622 | * <li> <p>The <b>foreground activity</b> (the activity at the top of the screen |
| 623 | * that the user is currently interacting with) is considered the most important. |
| 624 | * Its process will only be killed as a last resort, if it uses more memory |
| 625 | * than is available on the device. Generally at this point the device has |
| 626 | * reached a memory paging state, so this is required in order to keep the user |
| 627 | * interface responsive. |
| 628 | * <li> <p>A <b>visible activity</b> (an activity that is visible to the user |
| 629 | * but not in the foreground, such as one sitting behind a foreground dialog) |
| 630 | * is considered extremely important and will not be killed unless that is |
| 631 | * required to keep the foreground activity running. |
| 632 | * <li> <p>A <b>background activity</b> (an activity that is not visible to |
| 633 | * the user and has been paused) is no longer critical, so the system may |
| 634 | * safely kill its process to reclaim memory for other foreground or |
| 635 | * visible processes. If its process needs to be killed, when the user navigates |
| 636 | * back to the activity (making it visible on the screen again), its |
| 637 | * {@link #onCreate} method will be called with the savedInstanceState it had previously |
| 638 | * supplied in {@link #onSaveInstanceState} so that it can restart itself in the same |
| 639 | * state as the user last left it. |
| 640 | * <li> <p>An <b>empty process</b> is one hosting no activities or other |
| 641 | * application components (such as {@link Service} or |
| 642 | * {@link android.content.BroadcastReceiver} classes). These are killed very |
| 643 | * quickly by the system as memory becomes low. For this reason, any |
| 644 | * background operation you do outside of an activity must be executed in the |
| 645 | * context of an activity BroadcastReceiver or Service to ensure that the system |
| 646 | * knows it needs to keep your process around. |
| 647 | * </ol> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 648 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | * <p>Sometimes an Activity may need to do a long-running operation that exists |
| 650 | * independently of the activity lifecycle itself. An example may be a camera |
| 651 | * application that allows you to upload a picture to a web site. The upload |
| 652 | * may take a long time, and the application should allow the user to leave |
| 653 | * the application will it is executing. To accomplish this, your Activity |
| 654 | * should start a {@link Service} in which the upload takes place. This allows |
| 655 | * the system to properly prioritize your process (considering it to be more |
| 656 | * important than other non-visible applications) for the duration of the |
| 657 | * upload, independent of whether the original activity is paused, stopped, |
| 658 | * or finished. |
| 659 | */ |
| 660 | public class Activity extends ContextThemeWrapper |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 661 | implements LayoutInflater.Factory2, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 662 | Window.Callback, KeyEvent.Callback, |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 663 | OnCreateContextMenuListener, ComponentCallbacks2, |
| 664 | Window.OnWindowDismissedCallback { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 665 | private static final String TAG = "Activity"; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 666 | private static final boolean DEBUG_LIFECYCLE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | |
| 668 | /** Standard activity result: operation canceled. */ |
| 669 | public static final int RESULT_CANCELED = 0; |
| 670 | /** Standard activity result: operation succeeded. */ |
| 671 | public static final int RESULT_OK = -1; |
| 672 | /** Start of user-defined activity results. */ |
| 673 | public static final int RESULT_FIRST_USER = 1; |
| 674 | |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 675 | static final String FRAGMENTS_TAG = "android:fragments"; |
| 676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | private static final String WINDOW_HIERARCHY_TAG = "android:viewHierarchyState"; |
| 678 | private static final String SAVED_DIALOG_IDS_KEY = "android:savedDialogIds"; |
| 679 | private static final String SAVED_DIALOGS_TAG = "android:savedDialogs"; |
| 680 | private static final String SAVED_DIALOG_KEY_PREFIX = "android:dialog_"; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 681 | private static final String SAVED_DIALOG_ARGS_KEY_PREFIX = "android:dialog_args_"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 683 | private static class ManagedDialog { |
| 684 | Dialog mDialog; |
| 685 | Bundle mArgs; |
| 686 | } |
| 687 | private SparseArray<ManagedDialog> mManagedDialogs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 688 | |
| 689 | // set by the thread after the constructor and before onCreate(Bundle savedInstanceState) is called. |
| 690 | private Instrumentation mInstrumentation; |
| 691 | private IBinder mToken; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 692 | private int mIdent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | /*package*/ String mEmbeddedID; |
| 694 | private Application mApplication; |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 695 | /*package*/ Intent mIntent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 696 | /*package*/ String mReferrer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 | private ComponentName mComponent; |
| 698 | /*package*/ ActivityInfo mActivityInfo; |
| 699 | /*package*/ ActivityThread mMainThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 700 | Activity mParent; |
| 701 | boolean mCalled; |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 702 | boolean mCheckedForLoaderManager; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 703 | boolean mLoadersStarted; |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 704 | /*package*/ boolean mResumed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | private boolean mStopped; |
| 706 | boolean mFinished; |
| 707 | boolean mStartedActivity; |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 708 | private boolean mDestroyed; |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 709 | private boolean mDoReportFullyDrawn = true; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 710 | /** true if the activity is going through a transient pause */ |
| 711 | /*package*/ boolean mTemporaryPause = false; |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 712 | /** true if the activity is being destroyed in order to recreate it with a new configuration */ |
| 713 | /*package*/ boolean mChangingConfigurations = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 714 | /*package*/ int mConfigChangeFlags; |
| 715 | /*package*/ Configuration mCurrentConfig; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 716 | private SearchManager mSearchManager; |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 717 | private MenuInflater mMenuInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 718 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 719 | static final class NonConfigurationInstances { |
| 720 | Object activity; |
| 721 | HashMap<String, Object> children; |
| 722 | ArrayList<Fragment> fragments; |
Dianne Hackborn | 3e82ba1 | 2013-07-16 13:23:55 -0700 | [diff] [blame] | 723 | ArrayMap<String, LoaderManagerImpl> loaders; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 724 | VoiceInteractor voiceInteractor; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 725 | } |
| 726 | /* package */ NonConfigurationInstances mLastNonConfigurationInstances; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 727 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | private Window mWindow; |
| 729 | |
| 730 | private WindowManager mWindowManager; |
| 731 | /*package*/ View mDecor = null; |
| 732 | /*package*/ boolean mWindowAdded = false; |
| 733 | /*package*/ boolean mVisibleFromServer = false; |
| 734 | /*package*/ boolean mVisibleFromClient = true; |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 735 | /*package*/ ActionBar mActionBar = null; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 736 | private boolean mEnableDefaultActionBarUp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 738 | private VoiceInteractor mVoiceInteractor; |
| 739 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | private CharSequence mTitle; |
| 741 | private int mTitleColor = 0; |
| 742 | |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 743 | final FragmentManagerImpl mFragments = new FragmentManagerImpl(); |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 744 | final FragmentContainer mContainer = new FragmentContainer() { |
| 745 | @Override |
| 746 | public View findViewById(int id) { |
| 747 | return Activity.this.findViewById(id); |
| 748 | } |
George Mount | 0b26e4d | 2014-09-17 16:36:42 -0700 | [diff] [blame] | 749 | @Override |
| 750 | public boolean hasView() { |
| 751 | Window window = Activity.this.getWindow(); |
| 752 | return (window != null && window.peekDecorView() != null); |
| 753 | } |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 754 | }; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 755 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 756 | // Most recent call to requestVisibleBehind(). |
| 757 | boolean mVisibleBehind; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 758 | |
Dianne Hackborn | 3e82ba1 | 2013-07-16 13:23:55 -0700 | [diff] [blame] | 759 | ArrayMap<String, LoaderManagerImpl> mAllLoaderManagers; |
Dianne Hackborn | 4911b78 | 2010-07-15 12:54:39 -0700 | [diff] [blame] | 760 | LoaderManagerImpl mLoaderManager; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 761 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 762 | private static final class ManagedCursor { |
| 763 | ManagedCursor(Cursor cursor) { |
| 764 | mCursor = cursor; |
| 765 | mReleased = false; |
| 766 | mUpdated = false; |
| 767 | } |
| 768 | |
| 769 | private final Cursor mCursor; |
| 770 | private boolean mReleased; |
| 771 | private boolean mUpdated; |
| 772 | } |
| 773 | private final ArrayList<ManagedCursor> mManagedCursors = |
| 774 | new ArrayList<ManagedCursor>(); |
| 775 | |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 776 | // protected by synchronized (this) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 777 | int mResultCode = RESULT_CANCELED; |
| 778 | Intent mResultData = null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 779 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 780 | private TranslucentConversionListener mTranslucentCallback; |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 781 | private boolean mChangeCanvasToTranslucent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 782 | |
| 783 | private boolean mTitleReady = false; |
| 784 | |
| 785 | private int mDefaultKeyMode = DEFAULT_KEYS_DISABLE; |
| 786 | private SpannableStringBuilder mDefaultKeySsb = null; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 787 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | protected static final int[] FOCUSED_STATE_SET = {com.android.internal.R.attr.state_focused}; |
| 789 | |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 790 | @SuppressWarnings("unused") |
Jeff Brown | 7e44283 | 2011-06-10 18:00:16 -0700 | [diff] [blame] | 791 | private final Object mInstanceTracker = StrictMode.trackActivity(this); |
| 792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | private Thread mUiThread; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 794 | final Handler mHandler = new Handler(); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 795 | |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 796 | ActivityTransitionState mActivityTransitionState = new ActivityTransitionState(); |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 797 | SharedElementCallback mEnterTransitionListener = SharedElementCallback.NULL_CALLBACK; |
| 798 | SharedElementCallback mExitTransitionListener = SharedElementCallback.NULL_CALLBACK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | /** Return the intent that started this activity. */ |
| 801 | public Intent getIntent() { |
| 802 | return mIntent; |
| 803 | } |
| 804 | |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 805 | /** |
| 806 | * Change the intent returned by {@link #getIntent}. This holds a |
| 807 | * reference to the given intent; it does not copy it. Often used in |
| 808 | * conjunction with {@link #onNewIntent}. |
| 809 | * |
| 810 | * @param newIntent The new Intent object to return from getIntent |
| 811 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | * @see #getIntent |
| 813 | * @see #onNewIntent |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 814 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 815 | public void setIntent(Intent newIntent) { |
| 816 | mIntent = newIntent; |
| 817 | } |
| 818 | |
| 819 | /** Return the application that owns this activity. */ |
| 820 | public final Application getApplication() { |
| 821 | return mApplication; |
| 822 | } |
| 823 | |
| 824 | /** Is this activity embedded inside of another activity? */ |
| 825 | public final boolean isChild() { |
| 826 | return mParent != null; |
| 827 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 828 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 829 | /** Return the parent activity if this view is an embedded child. */ |
| 830 | public final Activity getParent() { |
| 831 | return mParent; |
| 832 | } |
| 833 | |
| 834 | /** Retrieve the window manager for showing custom windows. */ |
| 835 | public WindowManager getWindowManager() { |
| 836 | return mWindowManager; |
| 837 | } |
| 838 | |
| 839 | /** |
| 840 | * Retrieve the current {@link android.view.Window} for the activity. |
| 841 | * This can be used to directly access parts of the Window API that |
| 842 | * are not available through Activity/Screen. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 843 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | * @return Window The current window, or null if the activity is not |
| 845 | * visual. |
| 846 | */ |
| 847 | public Window getWindow() { |
| 848 | return mWindow; |
| 849 | } |
| 850 | |
| 851 | /** |
Mark Doliner | 9525f2a | 2014-01-02 11:17:47 -0800 | [diff] [blame] | 852 | * Return the LoaderManager for this activity, creating it if needed. |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 853 | */ |
| 854 | public LoaderManager getLoaderManager() { |
| 855 | if (mLoaderManager != null) { |
| 856 | return mLoaderManager; |
| 857 | } |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 858 | mCheckedForLoaderManager = true; |
Dianne Hackborn | 3e82ba1 | 2013-07-16 13:23:55 -0700 | [diff] [blame] | 859 | mLoaderManager = getLoaderManager("(root)", mLoadersStarted, true); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 860 | return mLoaderManager; |
| 861 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 862 | |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 863 | LoaderManagerImpl getLoaderManager(String who, boolean started, boolean create) { |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 864 | if (mAllLoaderManagers == null) { |
Dianne Hackborn | 3e82ba1 | 2013-07-16 13:23:55 -0700 | [diff] [blame] | 865 | mAllLoaderManagers = new ArrayMap<String, LoaderManagerImpl>(); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 866 | } |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 867 | LoaderManagerImpl lm = mAllLoaderManagers.get(who); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 868 | if (lm == null) { |
| 869 | if (create) { |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 870 | lm = new LoaderManagerImpl(who, this, started); |
| 871 | mAllLoaderManagers.put(who, lm); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 872 | } |
| 873 | } else { |
| 874 | lm.updateActivity(this); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 875 | } |
| 876 | return lm; |
| 877 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 878 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 879 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 880 | * Calls {@link android.view.Window#getCurrentFocus} on the |
| 881 | * Window of this Activity to return the currently focused view. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 882 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 883 | * @return View The current View with focus or null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 884 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 885 | * @see #getWindow |
| 886 | * @see android.view.Window#getCurrentFocus |
| 887 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 888 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 889 | public View getCurrentFocus() { |
| 890 | return mWindow != null ? mWindow.getCurrentFocus() : null; |
| 891 | } |
| 892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | /** |
| 894 | * Called when the activity is starting. This is where most initialization |
| 895 | * should go: calling {@link #setContentView(int)} to inflate the |
| 896 | * activity's UI, using {@link #findViewById} to programmatically interact |
| 897 | * with widgets in the UI, calling |
| 898 | * {@link #managedQuery(android.net.Uri , String[], String, String[], String)} to retrieve |
| 899 | * cursors for data being displayed, etc. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 900 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | * <p>You can call {@link #finish} from within this function, in |
| 902 | * which case onDestroy() will be immediately called without any of the rest |
| 903 | * of the activity lifecycle ({@link #onStart}, {@link #onResume}, |
| 904 | * {@link #onPause}, etc) executing. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 905 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | * <p><em>Derived classes must call through to the super class's |
| 907 | * implementation of this method. If they do not, an exception will be |
| 908 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 909 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | * @param savedInstanceState If the activity is being re-initialized after |
| 911 | * previously being shut down then this Bundle contains the data it most |
| 912 | * 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] | 913 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | * @see #onStart |
| 915 | * @see #onSaveInstanceState |
| 916 | * @see #onRestoreInstanceState |
| 917 | * @see #onPostCreate |
| 918 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 919 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 920 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 921 | if (mLastNonConfigurationInstances != null) { |
| 922 | mAllLoaderManagers = mLastNonConfigurationInstances.loaders; |
| 923 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 924 | if (mActivityInfo.parentActivityName != null) { |
| 925 | if (mActionBar == null) { |
| 926 | mEnableDefaultActionBarUp = true; |
| 927 | } else { |
| 928 | mActionBar.setDefaultDisplayHomeAsUpEnabled(true); |
| 929 | } |
| 930 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 931 | if (savedInstanceState != null) { |
| 932 | Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG); |
| 933 | mFragments.restoreAllState(p, mLastNonConfigurationInstances != null |
| 934 | ? mLastNonConfigurationInstances.fragments : null); |
| 935 | } |
| 936 | mFragments.dispatchCreate(); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 937 | getApplication().dispatchActivityCreated(this, savedInstanceState); |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 938 | if (mVoiceInteractor != null) { |
| 939 | mVoiceInteractor.attachActivity(this); |
| 940 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 941 | mCalled = true; |
| 942 | } |
| 943 | |
| 944 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 945 | * 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] | 946 | * the attribute {@link android.R.attr#persistableMode} set to |
| 947 | * <code>persistAcrossReboots</code>. |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 948 | * |
| 949 | * @param savedInstanceState if the activity is being re-initialized after |
| 950 | * previously being shut down then this Bundle contains the data it most |
| 951 | * recently supplied in {@link #onSaveInstanceState}. |
| 952 | * <b><i>Note: Otherwise it is null.</i></b> |
| 953 | * @param persistentState if the activity is being re-initialized after |
| 954 | * previously being shut down or powered off then this Bundle contains the data it most |
| 955 | * recently supplied to outPersistentState in {@link #onSaveInstanceState}. |
| 956 | * <b><i>Note: Otherwise it is null.</i></b> |
| 957 | * |
| 958 | * @see #onCreate(android.os.Bundle) |
| 959 | * @see #onStart |
| 960 | * @see #onSaveInstanceState |
| 961 | * @see #onRestoreInstanceState |
| 962 | * @see #onPostCreate |
| 963 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 964 | public void onCreate(@Nullable Bundle savedInstanceState, |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 965 | @Nullable PersistableBundle persistentState) { |
| 966 | onCreate(savedInstanceState); |
| 967 | } |
| 968 | |
| 969 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | * The hook for {@link ActivityThread} to restore the state of this activity. |
| 971 | * |
| 972 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} and |
| 973 | * {@link #restoreManagedDialogs(android.os.Bundle)}. |
| 974 | * |
| 975 | * @param savedInstanceState contains the saved state |
| 976 | */ |
| 977 | final void performRestoreInstanceState(Bundle savedInstanceState) { |
| 978 | onRestoreInstanceState(savedInstanceState); |
| 979 | restoreManagedDialogs(savedInstanceState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 983 | * The hook for {@link ActivityThread} to restore the state of this activity. |
| 984 | * |
| 985 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} and |
| 986 | * {@link #restoreManagedDialogs(android.os.Bundle)}. |
| 987 | * |
| 988 | * @param savedInstanceState contains the saved state |
| 989 | * @param persistentState contains the persistable saved state |
| 990 | */ |
| 991 | final void performRestoreInstanceState(Bundle savedInstanceState, |
| 992 | PersistableBundle persistentState) { |
| 993 | onRestoreInstanceState(savedInstanceState, persistentState); |
| 994 | if (savedInstanceState != null) { |
| 995 | restoreManagedDialogs(savedInstanceState); |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1000 | * This method is called after {@link #onStart} when the activity is |
| 1001 | * being re-initialized from a previously saved state, given here in |
Mike LeBeau | 305de9d | 2010-03-11 09:21:08 -0800 | [diff] [blame] | 1002 | * <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] | 1003 | * to restore their state, but it is sometimes convenient to do it here |
| 1004 | * after all of the initialization has been done or to allow subclasses to |
| 1005 | * decide whether to use your default implementation. The default |
| 1006 | * implementation of this method performs a restore of any view state that |
| 1007 | * had previously been frozen by {@link #onSaveInstanceState}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1008 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | * <p>This method is called between {@link #onStart} and |
| 1010 | * {@link #onPostCreate}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1011 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | * @param savedInstanceState the data most recently supplied in {@link #onSaveInstanceState}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1013 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1014 | * @see #onCreate |
| 1015 | * @see #onPostCreate |
| 1016 | * @see #onResume |
| 1017 | * @see #onSaveInstanceState |
| 1018 | */ |
| 1019 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 1020 | if (mWindow != null) { |
| 1021 | Bundle windowState = savedInstanceState.getBundle(WINDOW_HIERARCHY_TAG); |
| 1022 | if (windowState != null) { |
| 1023 | mWindow.restoreHierarchyState(windowState); |
| 1024 | } |
| 1025 | } |
| 1026 | } |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1027 | |
| 1028 | /** |
| 1029 | * 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] | 1030 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 1031 | * <code>persistAcrossReboots</code>. The {@link android.os.PersistableBundle} passed |
| 1032 | * came from the restored PersistableBundle first |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1033 | * saved in {@link #onSaveInstanceState(Bundle, PersistableBundle)}. |
| 1034 | * |
| 1035 | * <p>This method is called between {@link #onStart} and |
| 1036 | * {@link #onPostCreate}. |
| 1037 | * |
| 1038 | * <p>If this method is called {@link #onRestoreInstanceState(Bundle)} will not be called. |
| 1039 | * |
| 1040 | * @param savedInstanceState the data most recently supplied in {@link #onSaveInstanceState}. |
| 1041 | * @param persistentState the data most recently supplied in {@link #onSaveInstanceState}. |
| 1042 | * |
| 1043 | * @see #onRestoreInstanceState(Bundle) |
| 1044 | * @see #onCreate |
| 1045 | * @see #onPostCreate |
| 1046 | * @see #onResume |
| 1047 | * @see #onSaveInstanceState |
| 1048 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1049 | public void onRestoreInstanceState(Bundle savedInstanceState, |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1050 | PersistableBundle persistentState) { |
| 1051 | if (savedInstanceState != null) { |
| 1052 | onRestoreInstanceState(savedInstanceState); |
| 1053 | } |
| 1054 | } |
| 1055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | /** |
| 1057 | * Restore the state of any saved managed dialogs. |
| 1058 | * |
| 1059 | * @param savedInstanceState The bundle to restore from. |
| 1060 | */ |
| 1061 | private void restoreManagedDialogs(Bundle savedInstanceState) { |
| 1062 | final Bundle b = savedInstanceState.getBundle(SAVED_DIALOGS_TAG); |
| 1063 | if (b == null) { |
| 1064 | return; |
| 1065 | } |
| 1066 | |
| 1067 | final int[] ids = b.getIntArray(SAVED_DIALOG_IDS_KEY); |
| 1068 | final int numDialogs = ids.length; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1069 | mManagedDialogs = new SparseArray<ManagedDialog>(numDialogs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1070 | for (int i = 0; i < numDialogs; i++) { |
| 1071 | final Integer dialogId = ids[i]; |
| 1072 | Bundle dialogState = b.getBundle(savedDialogKeyFor(dialogId)); |
| 1073 | if (dialogState != null) { |
Romain Guy | e35c235 | 2009-06-19 13:18:12 -0700 | [diff] [blame] | 1074 | // Calling onRestoreInstanceState() below will invoke dispatchOnCreate |
| 1075 | // so tell createDialog() not to do it, otherwise we get an exception |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1076 | final ManagedDialog md = new ManagedDialog(); |
| 1077 | md.mArgs = b.getBundle(savedDialogArgsKeyFor(dialogId)); |
| 1078 | md.mDialog = createDialog(dialogId, dialogState, md.mArgs); |
| 1079 | if (md.mDialog != null) { |
| 1080 | mManagedDialogs.put(dialogId, md); |
| 1081 | onPrepareDialog(dialogId, md.mDialog, md.mArgs); |
| 1082 | md.mDialog.onRestoreInstanceState(dialogState); |
| 1083 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | } |
| 1087 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1088 | private Dialog createDialog(Integer dialogId, Bundle state, Bundle args) { |
| 1089 | final Dialog dialog = onCreateDialog(dialogId, args); |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1090 | if (dialog == null) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1091 | return null; |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1092 | } |
Romain Guy | 6de4aed | 2009-07-08 10:54:45 -0700 | [diff] [blame] | 1093 | dialog.dispatchOnCreate(state); |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1094 | return dialog; |
| 1095 | } |
| 1096 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1097 | private static String savedDialogKeyFor(int key) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1098 | return SAVED_DIALOG_KEY_PREFIX + key; |
| 1099 | } |
| 1100 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1101 | private static String savedDialogArgsKeyFor(int key) { |
| 1102 | return SAVED_DIALOG_ARGS_KEY_PREFIX + key; |
| 1103 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | |
| 1105 | /** |
| 1106 | * Called when activity start-up is complete (after {@link #onStart} |
| 1107 | * and {@link #onRestoreInstanceState} have been called). Applications will |
| 1108 | * generally not implement this method; it is intended for system |
| 1109 | * classes to do final initialization after application code has run. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1110 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | * <p><em>Derived classes must call through to the super class's |
| 1112 | * implementation of this method. If they do not, an exception will be |
| 1113 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1114 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | * @param savedInstanceState If the activity is being re-initialized after |
| 1116 | * previously being shut down then this Bundle contains the data it most |
| 1117 | * recently supplied in {@link #onSaveInstanceState}. <b><i>Note: Otherwise it is null.</i></b> |
| 1118 | * @see #onCreate |
| 1119 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1120 | protected void onPostCreate(@Nullable Bundle savedInstanceState) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | if (!isChild()) { |
| 1122 | mTitleReady = true; |
| 1123 | onTitleChanged(getTitle(), getTitleColor()); |
| 1124 | } |
| 1125 | mCalled = true; |
| 1126 | } |
| 1127 | |
| 1128 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1129 | * 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] | 1130 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 1131 | * <code>persistAcrossReboots</code>. |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1132 | * |
| 1133 | * @param savedInstanceState The data most recently supplied in {@link #onSaveInstanceState} |
| 1134 | * @param persistentState The data caming from the PersistableBundle first |
| 1135 | * saved in {@link #onSaveInstanceState(Bundle, PersistableBundle)}. |
| 1136 | * |
| 1137 | * @see #onCreate |
| 1138 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1139 | public void onPostCreate(@Nullable Bundle savedInstanceState, |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1140 | @Nullable PersistableBundle persistentState) { |
| 1141 | onPostCreate(savedInstanceState); |
| 1142 | } |
| 1143 | |
| 1144 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1145 | * Called after {@link #onCreate} — or after {@link #onRestart} when |
| 1146 | * 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] | 1147 | * user. It will be followed by {@link #onResume}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1148 | * |
| 1149 | * <p><em>Derived classes must call through to the super class's |
| 1150 | * implementation of this method. If they do not, an exception will be |
| 1151 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1152 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | * @see #onCreate |
| 1154 | * @see #onStop |
| 1155 | * @see #onResume |
| 1156 | */ |
| 1157 | protected void onStart() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1158 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onStart " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | mCalled = true; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1160 | |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 1161 | if (!mLoadersStarted) { |
| 1162 | mLoadersStarted = true; |
| 1163 | if (mLoaderManager != null) { |
| 1164 | mLoaderManager.doStart(); |
| 1165 | } else if (!mCheckedForLoaderManager) { |
Dianne Hackborn | 3e82ba1 | 2013-07-16 13:23:55 -0700 | [diff] [blame] | 1166 | mLoaderManager = getLoaderManager("(root)", mLoadersStarted, false); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 1167 | } |
| 1168 | mCheckedForLoaderManager = true; |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 1169 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 1170 | |
| 1171 | getApplication().dispatchActivityStarted(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | /** |
| 1175 | * Called after {@link #onStop} when the current activity is being |
| 1176 | * re-displayed to the user (the user has navigated back to it). It will |
| 1177 | * be followed by {@link #onStart} and then {@link #onResume}. |
| 1178 | * |
| 1179 | * <p>For activities that are using raw {@link Cursor} objects (instead of |
| 1180 | * creating them through |
| 1181 | * {@link #managedQuery(android.net.Uri , String[], String, String[], String)}, |
| 1182 | * this is usually the place |
| 1183 | * where the cursor should be requeried (because you had deactivated it in |
| 1184 | * {@link #onStop}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1185 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | * <p><em>Derived classes must call through to the super class's |
| 1187 | * implementation of this method. If they do not, an exception will be |
| 1188 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1189 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1190 | * @see #onStop |
| 1191 | * @see #onStart |
| 1192 | * @see #onResume |
| 1193 | */ |
| 1194 | protected void onRestart() { |
| 1195 | mCalled = true; |
| 1196 | } |
| 1197 | |
| 1198 | /** |
| 1199 | * Called after {@link #onRestoreInstanceState}, {@link #onRestart}, or |
| 1200 | * {@link #onPause}, for your activity to start interacting with the user. |
| 1201 | * This is a good place to begin animations, open exclusive-access devices |
| 1202 | * (such as the camera), etc. |
| 1203 | * |
| 1204 | * <p>Keep in mind that onResume is not the best indicator that your activity |
| 1205 | * is visible to the user; a system window such as the keyguard may be in |
| 1206 | * front. Use {@link #onWindowFocusChanged} to know for certain that your |
| 1207 | * activity is visible to the user (for example, to resume a game). |
| 1208 | * |
| 1209 | * <p><em>Derived classes must call through to the super class's |
| 1210 | * implementation of this method. If they do not, an exception will be |
| 1211 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1212 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1213 | * @see #onRestoreInstanceState |
| 1214 | * @see #onRestart |
| 1215 | * @see #onPostResume |
| 1216 | * @see #onPause |
| 1217 | */ |
| 1218 | protected void onResume() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1219 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onResume " + this); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 1220 | getApplication().dispatchActivityResumed(this); |
George Mount | 8cab50a | 2014-05-15 09:57:17 -0700 | [diff] [blame] | 1221 | mActivityTransitionState.onResume(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1222 | mCalled = true; |
| 1223 | } |
| 1224 | |
| 1225 | /** |
| 1226 | * Called when activity resume is complete (after {@link #onResume} has |
| 1227 | * been called). Applications will generally not implement this method; |
| 1228 | * it is intended for system classes to do final setup after application |
| 1229 | * resume code has run. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1230 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1231 | * <p><em>Derived classes must call through to the super class's |
| 1232 | * implementation of this method. If they do not, an exception will be |
| 1233 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1234 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | * @see #onResume |
| 1236 | */ |
| 1237 | protected void onPostResume() { |
| 1238 | final Window win = getWindow(); |
| 1239 | if (win != null) win.makeActive(); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 1240 | if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1241 | mCalled = true; |
| 1242 | } |
| 1243 | |
| 1244 | /** |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1245 | * Check whether this activity is running as part of a voice interaction with the user. |
| 1246 | * If true, it should perform its interaction with the user through the |
| 1247 | * {@link VoiceInteractor} returned by {@link #getVoiceInteractor}. |
| 1248 | */ |
| 1249 | public boolean isVoiceInteraction() { |
| 1250 | return mVoiceInteractor != null; |
| 1251 | } |
| 1252 | |
| 1253 | /** |
| 1254 | * Retrieve the active {@link VoiceInteractor} that the user is going through to |
| 1255 | * interact with this activity. |
| 1256 | */ |
| 1257 | public VoiceInteractor getVoiceInteractor() { |
| 1258 | return mVoiceInteractor; |
| 1259 | } |
| 1260 | |
| 1261 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1262 | * This is called for activities that set launchMode to "singleTop" in |
| 1263 | * their package, or if a client used the {@link Intent#FLAG_ACTIVITY_SINGLE_TOP} |
| 1264 | * flag when calling {@link #startActivity}. In either case, when the |
| 1265 | * activity is re-launched while at the top of the activity stack instead |
| 1266 | * of a new instance of the activity being started, onNewIntent() will be |
| 1267 | * called on the existing instance with the Intent that was used to |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1268 | * re-launch it. |
| 1269 | * |
| 1270 | * <p>An activity will always be paused before receiving a new intent, so |
| 1271 | * you can count on {@link #onResume} being called after this method. |
| 1272 | * |
| 1273 | * <p>Note that {@link #getIntent} still returns the original Intent. You |
| 1274 | * can use {@link #setIntent} to update it to this new Intent. |
| 1275 | * |
| 1276 | * @param intent The new intent that was started for the activity. |
| 1277 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | * @see #getIntent |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1279 | * @see #setIntent |
| 1280 | * @see #onResume |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1281 | */ |
| 1282 | protected void onNewIntent(Intent intent) { |
| 1283 | } |
| 1284 | |
| 1285 | /** |
| 1286 | * The hook for {@link ActivityThread} to save the state of this activity. |
| 1287 | * |
| 1288 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} |
| 1289 | * and {@link #saveManagedDialogs(android.os.Bundle)}. |
| 1290 | * |
| 1291 | * @param outState The bundle to save the state to. |
| 1292 | */ |
| 1293 | final void performSaveInstanceState(Bundle outState) { |
| 1294 | onSaveInstanceState(outState); |
| 1295 | saveManagedDialogs(outState); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1296 | mActivityTransitionState.saveState(outState); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1297 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onSaveInstanceState " + this + ": " + outState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1301 | * The hook for {@link ActivityThread} to save the state of this activity. |
| 1302 | * |
| 1303 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} |
| 1304 | * and {@link #saveManagedDialogs(android.os.Bundle)}. |
| 1305 | * |
| 1306 | * @param outState The bundle to save the state to. |
| 1307 | * @param outPersistentState The bundle to save persistent state to. |
| 1308 | */ |
| 1309 | final void performSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { |
| 1310 | onSaveInstanceState(outState, outPersistentState); |
| 1311 | saveManagedDialogs(outState); |
| 1312 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onSaveInstanceState " + this + ": " + outState + |
| 1313 | ", " + outPersistentState); |
| 1314 | } |
| 1315 | |
| 1316 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1317 | * Called to retrieve per-instance state from an activity before being killed |
| 1318 | * so that the state can be restored in {@link #onCreate} or |
| 1319 | * {@link #onRestoreInstanceState} (the {@link Bundle} populated by this method |
| 1320 | * will be passed to both). |
| 1321 | * |
| 1322 | * <p>This method is called before an activity may be killed so that when it |
| 1323 | * comes back some time in the future it can restore its state. For example, |
| 1324 | * if activity B is launched in front of activity A, and at some point activity |
| 1325 | * A is killed to reclaim resources, activity A will have a chance to save the |
| 1326 | * current state of its user interface via this method so that when the user |
| 1327 | * returns to activity A, the state of the user interface can be restored |
| 1328 | * via {@link #onCreate} or {@link #onRestoreInstanceState}. |
| 1329 | * |
| 1330 | * <p>Do not confuse this method with activity lifecycle callbacks such as |
| 1331 | * {@link #onPause}, which is always called when an activity is being placed |
| 1332 | * in the background or on its way to destruction, or {@link #onStop} which |
| 1333 | * is called before destruction. One example of when {@link #onPause} and |
| 1334 | * {@link #onStop} is called and not this method is when a user navigates back |
| 1335 | * from activity B to activity A: there is no need to call {@link #onSaveInstanceState} |
| 1336 | * on B because that particular instance will never be restored, so the |
| 1337 | * system avoids calling it. An example when {@link #onPause} is called and |
| 1338 | * not {@link #onSaveInstanceState} is when activity B is launched in front of activity A: |
| 1339 | * the system may avoid calling {@link #onSaveInstanceState} on activity A if it isn't |
| 1340 | * killed during the lifetime of B since the state of the user interface of |
| 1341 | * A will stay intact. |
| 1342 | * |
| 1343 | * <p>The default implementation takes care of most of the UI per-instance |
| 1344 | * state for you by calling {@link android.view.View#onSaveInstanceState()} on each |
| 1345 | * view in the hierarchy that has an id, and by saving the id of the currently |
| 1346 | * focused view (all of which is restored by the default implementation of |
| 1347 | * {@link #onRestoreInstanceState}). If you override this method to save additional |
| 1348 | * information not captured by each individual view, you will likely want to |
| 1349 | * call through to the default implementation, otherwise be prepared to save |
| 1350 | * all of the state of each view yourself. |
| 1351 | * |
| 1352 | * <p>If called, this method will occur before {@link #onStop}. There are |
| 1353 | * no guarantees about whether it will occur before or after {@link #onPause}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1354 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1355 | * @param outState Bundle in which to place your saved state. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1356 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1357 | * @see #onCreate |
| 1358 | * @see #onRestoreInstanceState |
| 1359 | * @see #onPause |
| 1360 | */ |
| 1361 | protected void onSaveInstanceState(Bundle outState) { |
| 1362 | outState.putBundle(WINDOW_HIERARCHY_TAG, mWindow.saveHierarchyState()); |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1363 | Parcelable p = mFragments.saveAllState(); |
| 1364 | if (p != null) { |
| 1365 | outState.putParcelable(FRAGMENTS_TAG, p); |
| 1366 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 1367 | getApplication().dispatchActivitySaveInstanceState(this, outState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1371 | * This is the same as {@link #onSaveInstanceState} but is called for activities |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 1372 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 1373 | * <code>persistAcrossReboots</code>. The {@link android.os.PersistableBundle} passed |
| 1374 | * in will be saved and presented in {@link #onCreate(Bundle, PersistableBundle)} |
| 1375 | * 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] | 1376 | * |
| 1377 | * @param outState Bundle in which to place your saved state. |
| 1378 | * @param outPersistentState State which will be saved across reboots. |
| 1379 | * |
| 1380 | * @see #onSaveInstanceState(Bundle) |
| 1381 | * @see #onCreate |
| 1382 | * @see #onRestoreInstanceState(Bundle, PersistableBundle) |
| 1383 | * @see #onPause |
| 1384 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1385 | public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1386 | onSaveInstanceState(outState); |
| 1387 | } |
| 1388 | |
| 1389 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1390 | * Save the state of any managed dialogs. |
| 1391 | * |
| 1392 | * @param outState place to store the saved state. |
| 1393 | */ |
| 1394 | private void saveManagedDialogs(Bundle outState) { |
| 1395 | if (mManagedDialogs == null) { |
| 1396 | return; |
| 1397 | } |
| 1398 | |
| 1399 | final int numDialogs = mManagedDialogs.size(); |
| 1400 | if (numDialogs == 0) { |
| 1401 | return; |
| 1402 | } |
| 1403 | |
| 1404 | Bundle dialogState = new Bundle(); |
| 1405 | |
| 1406 | int[] ids = new int[mManagedDialogs.size()]; |
| 1407 | |
| 1408 | // save each dialog's bundle, gather the ids |
| 1409 | for (int i = 0; i < numDialogs; i++) { |
| 1410 | final int key = mManagedDialogs.keyAt(i); |
| 1411 | ids[i] = key; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1412 | final ManagedDialog md = mManagedDialogs.valueAt(i); |
| 1413 | dialogState.putBundle(savedDialogKeyFor(key), md.mDialog.onSaveInstanceState()); |
| 1414 | if (md.mArgs != null) { |
| 1415 | dialogState.putBundle(savedDialogArgsKeyFor(key), md.mArgs); |
| 1416 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | dialogState.putIntArray(SAVED_DIALOG_IDS_KEY, ids); |
| 1420 | outState.putBundle(SAVED_DIALOGS_TAG, dialogState); |
| 1421 | } |
| 1422 | |
| 1423 | |
| 1424 | /** |
| 1425 | * Called as part of the activity lifecycle when an activity is going into |
| 1426 | * the background, but has not (yet) been killed. The counterpart to |
| 1427 | * {@link #onResume}. |
| 1428 | * |
| 1429 | * <p>When activity B is launched in front of activity A, this callback will |
| 1430 | * be invoked on A. B will not be created until A's {@link #onPause} returns, |
| 1431 | * so be sure to not do anything lengthy here. |
| 1432 | * |
| 1433 | * <p>This callback is mostly used for saving any persistent state the |
| 1434 | * activity is editing, to present a "edit in place" model to the user and |
| 1435 | * making sure nothing is lost if there are not enough resources to start |
| 1436 | * the new activity without first killing this one. This is also a good |
| 1437 | * 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] | 1438 | * 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] | 1439 | * as fast as possible, or to close resources that are exclusive access |
| 1440 | * such as the camera. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1441 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1442 | * <p>In situations where the system needs more memory it may kill paused |
| 1443 | * processes to reclaim resources. Because of this, you should be sure |
| 1444 | * that all of your state is saved by the time you return from |
| 1445 | * this function. In general {@link #onSaveInstanceState} is used to save |
| 1446 | * per-instance state in the activity and this method is used to store |
| 1447 | * global persistent data (in content providers, files, etc.) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1448 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1449 | * <p>After receiving this call you will usually receive a following call |
| 1450 | * to {@link #onStop} (after the next activity has been resumed and |
| 1451 | * displayed), however in some cases there will be a direct call back to |
| 1452 | * {@link #onResume} without going through the stopped state. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1453 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1454 | * <p><em>Derived classes must call through to the super class's |
| 1455 | * implementation of this method. If they do not, an exception will be |
| 1456 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1457 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1458 | * @see #onResume |
| 1459 | * @see #onSaveInstanceState |
| 1460 | * @see #onStop |
| 1461 | */ |
| 1462 | protected void onPause() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1463 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onPause " + this); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 1464 | getApplication().dispatchActivityPaused(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1465 | mCalled = true; |
| 1466 | } |
| 1467 | |
| 1468 | /** |
| 1469 | * Called as part of the activity lifecycle when an activity is about to go |
| 1470 | * into the background as the result of user choice. For example, when the |
| 1471 | * user presses the Home key, {@link #onUserLeaveHint} will be called, but |
| 1472 | * when an incoming phone call causes the in-call Activity to be automatically |
| 1473 | * brought to the foreground, {@link #onUserLeaveHint} will not be called on |
| 1474 | * the activity being interrupted. In cases when it is invoked, this method |
| 1475 | * is called right before the activity's {@link #onPause} callback. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1476 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1477 | * <p>This callback and {@link #onUserInteraction} are intended to help |
| 1478 | * activities manage status bar notifications intelligently; specifically, |
| 1479 | * for helping activities determine the proper time to cancel a notfication. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1480 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1481 | * @see #onUserInteraction() |
| 1482 | */ |
| 1483 | protected void onUserLeaveHint() { |
| 1484 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1486 | /** |
| 1487 | * Generate a new thumbnail for this activity. This method is called before |
| 1488 | * pausing the activity, and should draw into <var>outBitmap</var> the |
| 1489 | * imagery for the desired thumbnail in the dimensions of that bitmap. It |
| 1490 | * can use the given <var>canvas</var>, which is configured to draw into the |
| 1491 | * bitmap, for rendering if desired. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1492 | * |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 1493 | * <p>The default implementation returns fails and does not draw a thumbnail; |
| 1494 | * this will result in the platform creating its own thumbnail if needed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1495 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1496 | * @param outBitmap The bitmap to contain the thumbnail. |
| 1497 | * @param canvas Can be used to render into the bitmap. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1498 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1499 | * @return Return true if you have drawn into the bitmap; otherwise after |
| 1500 | * you return it will be filled with a default thumbnail. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1501 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1502 | * @see #onCreateDescription |
| 1503 | * @see #onSaveInstanceState |
| 1504 | * @see #onPause |
| 1505 | */ |
| 1506 | public boolean onCreateThumbnail(Bitmap outBitmap, Canvas canvas) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 1507 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | /** |
| 1511 | * Generate a new description for this activity. This method is called |
| 1512 | * before pausing the activity and can, if desired, return some textual |
| 1513 | * description of its current state to be displayed to the user. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1514 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1515 | * <p>The default implementation returns null, which will cause you to |
| 1516 | * inherit the description from the previous activity. If all activities |
| 1517 | * return null, generally the label of the top activity will be used as the |
| 1518 | * description. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1519 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | * @return A description of what the user is doing. It should be short and |
| 1521 | * sweet (only a few words). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1522 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | * @see #onCreateThumbnail |
| 1524 | * @see #onSaveInstanceState |
| 1525 | * @see #onPause |
| 1526 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1527 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | public CharSequence onCreateDescription() { |
| 1529 | return null; |
| 1530 | } |
| 1531 | |
| 1532 | /** |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1533 | * This is called when the user is requesting an assist, to build a full |
| 1534 | * {@link Intent#ACTION_ASSIST} Intent with all of the context of the current |
| 1535 | * application. You can override this method to place into the bundle anything |
| 1536 | * you would like to appear in the {@link Intent#EXTRA_ASSIST_CONTEXT} part |
Dianne Hackborn | a7bb6fb | 2015-02-03 18:13:40 -0800 | [diff] [blame] | 1537 | * of the assist Intent. The default implementation automatically generates a |
| 1538 | * {@link AssistData} from your activity and places it in to the Bundle; if you |
| 1539 | * don't want your UI reported to the assistant, don't call this default |
| 1540 | * implementation. |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1541 | * |
| 1542 | * <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] | 1543 | * been registered with {@link Application#registerOnProvideAssistDataListener |
| 1544 | * Application.registerOnProvideAssistDataListener}. |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1545 | */ |
| 1546 | public void onProvideAssistData(Bundle data) { |
Dianne Hackborn | a7bb6fb | 2015-02-03 18:13:40 -0800 | [diff] [blame] | 1547 | data.putParcelable(AssistData.ASSIST_KEY, new AssistData(this)); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1551 | * Called when you are no longer visible to the user. You will next |
| 1552 | * receive either {@link #onRestart}, {@link #onDestroy}, or nothing, |
| 1553 | * depending on later user activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1554 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1555 | * <p>Note that this method may never be called, in low memory situations |
| 1556 | * where the system does not have enough memory to keep your activity's |
| 1557 | * process running after its {@link #onPause} method is called. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1558 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1559 | * <p><em>Derived classes must call through to the super class's |
| 1560 | * implementation of this method. If they do not, an exception will be |
| 1561 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1562 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1563 | * @see #onRestart |
| 1564 | * @see #onResume |
| 1565 | * @see #onSaveInstanceState |
| 1566 | * @see #onDestroy |
| 1567 | */ |
| 1568 | protected void onStop() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1569 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onStop " + this); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 1570 | if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(false); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1571 | mActivityTransitionState.onStop(); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 1572 | getApplication().dispatchActivityStopped(this); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1573 | mTranslucentCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | mCalled = true; |
| 1575 | } |
| 1576 | |
| 1577 | /** |
| 1578 | * Perform any final cleanup before an activity is destroyed. This can |
| 1579 | * happen either because the activity is finishing (someone called |
| 1580 | * {@link #finish} on it, or because the system is temporarily destroying |
| 1581 | * this instance of the activity to save space. You can distinguish |
| 1582 | * between these two scenarios with the {@link #isFinishing} method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1583 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1584 | * <p><em>Note: do not count on this method being called as a place for |
| 1585 | * saving data! For example, if an activity is editing data in a content |
| 1586 | * provider, those edits should be committed in either {@link #onPause} or |
| 1587 | * {@link #onSaveInstanceState}, not here.</em> This method is usually implemented to |
| 1588 | * free resources like threads that are associated with an activity, so |
| 1589 | * that a destroyed activity does not leave such things around while the |
| 1590 | * rest of its application is still running. There are situations where |
| 1591 | * the system will simply kill the activity's hosting process without |
| 1592 | * calling this method (or any others) in it, so it should not be used to |
| 1593 | * do things that are intended to remain around after the process goes |
| 1594 | * away. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1595 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1596 | * <p><em>Derived classes must call through to the super class's |
| 1597 | * implementation of this method. If they do not, an exception will be |
| 1598 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1599 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1600 | * @see #onPause |
| 1601 | * @see #onStop |
| 1602 | * @see #finish |
| 1603 | * @see #isFinishing |
| 1604 | */ |
| 1605 | protected void onDestroy() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1606 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onDestroy " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1607 | mCalled = true; |
| 1608 | |
| 1609 | // dismiss any dialogs we are managing. |
| 1610 | if (mManagedDialogs != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1611 | final int numDialogs = mManagedDialogs.size(); |
| 1612 | for (int i = 0; i < numDialogs; i++) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1613 | final ManagedDialog md = mManagedDialogs.valueAt(i); |
| 1614 | if (md.mDialog.isShowing()) { |
| 1615 | md.mDialog.dismiss(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1616 | } |
| 1617 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1618 | mManagedDialogs = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1619 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1620 | |
| 1621 | // close any cursors we are managing. |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 1622 | synchronized (mManagedCursors) { |
| 1623 | int numCursors = mManagedCursors.size(); |
| 1624 | for (int i = 0; i < numCursors; i++) { |
| 1625 | ManagedCursor c = mManagedCursors.get(i); |
| 1626 | if (c != null) { |
| 1627 | c.mCursor.close(); |
| 1628 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1629 | } |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 1630 | mManagedCursors.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1631 | } |
Amith Yamasani | 4986044 | 2010-03-17 20:54:10 -0700 | [diff] [blame] | 1632 | |
| 1633 | // Close any open search dialog |
| 1634 | if (mSearchManager != null) { |
| 1635 | mSearchManager.stopSearch(); |
| 1636 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 1637 | |
| 1638 | getApplication().dispatchActivityDestroyed(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | /** |
Dianne Hackborn | ebc15ef | 2013-10-09 17:36:57 -0700 | [diff] [blame] | 1642 | * Report to the system that your app is now fully drawn, purely for diagnostic |
| 1643 | * purposes (calling it does not impact the visible behavior of the activity). |
| 1644 | * This is only used to help instrument application launch times, so that the |
| 1645 | * app can report when it is fully in a usable state; without this, the only thing |
| 1646 | * the system itself can determine is the point at which the activity's window |
| 1647 | * 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] | 1648 | * measurement, you should always call this method after first launch (when |
Dianne Hackborn | ebc15ef | 2013-10-09 17:36:57 -0700 | [diff] [blame] | 1649 | * {@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] | 1650 | * entirely drawn your UI and populated with all of the significant data. You |
| 1651 | * can safely call this method any time after first launch as well, in which case |
| 1652 | * it will simply be ignored. |
| 1653 | */ |
| 1654 | public void reportFullyDrawn() { |
| 1655 | if (mDoReportFullyDrawn) { |
| 1656 | mDoReportFullyDrawn = false; |
| 1657 | try { |
| 1658 | ActivityManagerNative.getDefault().reportActivityFullyDrawn(mToken); |
| 1659 | } catch (RemoteException e) { |
| 1660 | } |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1665 | * Called by the system when the device configuration changes while your |
| 1666 | * activity is running. Note that this will <em>only</em> be called if |
| 1667 | * you have selected configurations you would like to handle with the |
| 1668 | * {@link android.R.attr#configChanges} attribute in your manifest. If |
| 1669 | * any configuration change occurs that is not selected to be reported |
| 1670 | * by that attribute, then instead of reporting it the system will stop |
| 1671 | * and restart the activity (to have it launched with the new |
| 1672 | * configuration). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1673 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1674 | * <p>At the time that this function has been called, your Resources |
| 1675 | * object will have been updated to return resource values matching the |
| 1676 | * new configuration. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1677 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | * @param newConfig The new device configuration. |
| 1679 | */ |
| 1680 | public void onConfigurationChanged(Configuration newConfig) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1681 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onConfigurationChanged " + this + ": " + newConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1682 | mCalled = true; |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 1683 | |
Dianne Hackborn | 9d07180 | 2010-12-08 14:49:15 -0800 | [diff] [blame] | 1684 | mFragments.dispatchConfigurationChanged(newConfig); |
| 1685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1686 | if (mWindow != null) { |
| 1687 | // Pass the configuration changed event to the window |
| 1688 | mWindow.onConfigurationChanged(newConfig); |
| 1689 | } |
Adam Powell | 45c0b19 | 2011-07-28 15:11:57 -0700 | [diff] [blame] | 1690 | |
| 1691 | if (mActionBar != null) { |
| 1692 | // Do this last; the action bar will need to access |
| 1693 | // view changes from above. |
| 1694 | mActionBar.onConfigurationChanged(newConfig); |
| 1695 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1696 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1697 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1698 | /** |
| 1699 | * If this activity is being destroyed because it can not handle a |
| 1700 | * configuration parameter being changed (and thus its |
| 1701 | * {@link #onConfigurationChanged(Configuration)} method is |
| 1702 | * <em>not</em> being called), then you can use this method to discover |
| 1703 | * the set of changes that have occurred while in the process of being |
| 1704 | * destroyed. Note that there is no guarantee that these will be |
| 1705 | * accurate (other changes could have happened at any time), so you should |
| 1706 | * only use this as an optimization hint. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1707 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1708 | * @return Returns a bit field of the configuration parameters that are |
| 1709 | * changing, as defined by the {@link android.content.res.Configuration} |
| 1710 | * class. |
| 1711 | */ |
| 1712 | public int getChangingConfigurations() { |
| 1713 | return mConfigChangeFlags; |
| 1714 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1716 | /** |
| 1717 | * Retrieve the non-configuration instance data that was previously |
| 1718 | * returned by {@link #onRetainNonConfigurationInstance()}. This will |
| 1719 | * be available from the initial {@link #onCreate} and |
| 1720 | * {@link #onStart} calls to the new instance, allowing you to extract |
| 1721 | * any useful dynamic state from the previous instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1722 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | * <p>Note that the data you retrieve here should <em>only</em> be used |
| 1724 | * as an optimization for handling configuration changes. You should always |
| 1725 | * be able to handle getting a null pointer back, and an activity must |
| 1726 | * still be able to restore itself to its previous state (through the |
| 1727 | * normal {@link #onSaveInstanceState(Bundle)} mechanism) even if this |
| 1728 | * function returns null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1729 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1730 | * @return Returns the object previously returned by |
| 1731 | * {@link #onRetainNonConfigurationInstance()}. |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 1732 | * |
| 1733 | * @deprecated Use the new {@link Fragment} API |
| 1734 | * {@link Fragment#setRetainInstance(boolean)} instead; this is also |
| 1735 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1736 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1737 | @Nullable |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 1738 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1739 | public Object getLastNonConfigurationInstance() { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1740 | return mLastNonConfigurationInstances != null |
| 1741 | ? mLastNonConfigurationInstances.activity : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1742 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1743 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1744 | /** |
| 1745 | * Called by the system, as part of destroying an |
| 1746 | * activity due to a configuration change, when it is known that a new |
| 1747 | * instance will immediately be created for the new configuration. You |
| 1748 | * can return any object you like here, including the activity instance |
| 1749 | * itself, which can later be retrieved by calling |
| 1750 | * {@link #getLastNonConfigurationInstance()} in the new activity |
| 1751 | * instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1752 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 1753 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 1754 | * or later, consider instead using a {@link Fragment} with |
| 1755 | * {@link Fragment#setRetainInstance(boolean) |
| 1756 | * Fragment.setRetainInstance(boolean}.</em> |
| 1757 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1758 | * <p>This function is called purely as an optimization, and you must |
| 1759 | * not rely on it being called. When it is called, a number of guarantees |
| 1760 | * will be made to help optimize configuration switching: |
| 1761 | * <ul> |
| 1762 | * <li> The function will be called between {@link #onStop} and |
| 1763 | * {@link #onDestroy}. |
| 1764 | * <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] | 1765 | * created after this one's {@link #onDestroy()} is called. In particular, |
| 1766 | * <em>no</em> messages will be dispatched during this time (when the returned |
| 1767 | * 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] | 1768 | * <li> The object you return here will <em>always</em> be available from |
| 1769 | * the {@link #getLastNonConfigurationInstance()} method of the following |
| 1770 | * activity instance as described there. |
| 1771 | * </ul> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1772 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1773 | * <p>These guarantees are designed so that an activity can use this API |
| 1774 | * to propagate extensive state from the old to new activity instance, from |
| 1775 | * loaded bitmaps, to network connections, to evenly actively running |
| 1776 | * threads. Note that you should <em>not</em> propagate any data that |
| 1777 | * may change based on the configuration, including any data loaded from |
| 1778 | * resources such as strings, layouts, or drawables. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1779 | * |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1780 | * <p>The guarantee of no message handling during the switch to the next |
| 1781 | * activity simplifies use with active objects. For example if your retained |
| 1782 | * state is an {@link android.os.AsyncTask} you are guaranteed that its |
| 1783 | * call back functions (like {@link android.os.AsyncTask#onPostExecute}) will |
| 1784 | * not be called from the call here until you execute the next instance's |
| 1785 | * {@link #onCreate(Bundle)}. (Note however that there is of course no such |
| 1786 | * guarantee for {@link android.os.AsyncTask#doInBackground} since that is |
| 1787 | * running in a separate thread.) |
| 1788 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1789 | * @return Return any Object holding the desired state to propagate to the |
| 1790 | * next activity instance. |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 1791 | * |
| 1792 | * @deprecated Use the new {@link Fragment} API |
| 1793 | * {@link Fragment#setRetainInstance(boolean)} instead; this is also |
| 1794 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1795 | */ |
| 1796 | public Object onRetainNonConfigurationInstance() { |
| 1797 | return null; |
| 1798 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1800 | /** |
| 1801 | * Retrieve the non-configuration instance data that was previously |
| 1802 | * returned by {@link #onRetainNonConfigurationChildInstances()}. This will |
| 1803 | * be available from the initial {@link #onCreate} and |
| 1804 | * {@link #onStart} calls to the new instance, allowing you to extract |
| 1805 | * any useful dynamic state from the previous instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1806 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1807 | * <p>Note that the data you retrieve here should <em>only</em> be used |
| 1808 | * as an optimization for handling configuration changes. You should always |
| 1809 | * be able to handle getting a null pointer back, and an activity must |
| 1810 | * still be able to restore itself to its previous state (through the |
| 1811 | * normal {@link #onSaveInstanceState(Bundle)} mechanism) even if this |
| 1812 | * function returns null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1813 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1814 | * @return Returns the object previously returned by |
| 1815 | * {@link #onRetainNonConfigurationChildInstances()} |
| 1816 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1817 | @Nullable |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1818 | HashMap<String, Object> getLastNonConfigurationChildInstances() { |
| 1819 | return mLastNonConfigurationInstances != null |
| 1820 | ? mLastNonConfigurationInstances.children : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1821 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1822 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1823 | /** |
| 1824 | * This method is similar to {@link #onRetainNonConfigurationInstance()} except that |
| 1825 | * it should return either a mapping from child activity id strings to arbitrary objects, |
| 1826 | * or null. This method is intended to be used by Activity framework subclasses that control a |
| 1827 | * set of child activities, such as ActivityGroup. The same guarantees and restrictions apply |
| 1828 | * as for {@link #onRetainNonConfigurationInstance()}. The default implementation returns null. |
| 1829 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1830 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1831 | HashMap<String,Object> onRetainNonConfigurationChildInstances() { |
| 1832 | return null; |
| 1833 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1834 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1835 | NonConfigurationInstances retainNonConfigurationInstances() { |
| 1836 | Object activity = onRetainNonConfigurationInstance(); |
| 1837 | HashMap<String, Object> children = onRetainNonConfigurationChildInstances(); |
| 1838 | ArrayList<Fragment> fragments = mFragments.retainNonConfig(); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 1839 | boolean retainLoaders = false; |
| 1840 | if (mAllLoaderManagers != null) { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 1841 | // prune out any loader managers that were already stopped and so |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 1842 | // have nothing useful to retain. |
Dianne Hackborn | 3e82ba1 | 2013-07-16 13:23:55 -0700 | [diff] [blame] | 1843 | final int N = mAllLoaderManagers.size(); |
| 1844 | LoaderManagerImpl loaders[] = new LoaderManagerImpl[N]; |
| 1845 | for (int i=N-1; i>=0; i--) { |
| 1846 | loaders[i] = mAllLoaderManagers.valueAt(i); |
| 1847 | } |
| 1848 | for (int i=0; i<N; i++) { |
| 1849 | LoaderManagerImpl lm = loaders[i]; |
| 1850 | if (lm.mRetaining) { |
| 1851 | retainLoaders = true; |
| 1852 | } else { |
| 1853 | lm.doDestroy(); |
| 1854 | mAllLoaderManagers.remove(lm.mWho); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 1855 | } |
| 1856 | } |
| 1857 | } |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 1858 | if (activity == null && children == null && fragments == null && !retainLoaders |
| 1859 | && mVoiceInteractor == null) { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1860 | return null; |
| 1861 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1862 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1863 | NonConfigurationInstances nci = new NonConfigurationInstances(); |
| 1864 | nci.activity = activity; |
| 1865 | nci.children = children; |
| 1866 | nci.fragments = fragments; |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 1867 | nci.loaders = mAllLoaderManagers; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 1868 | nci.voiceInteractor = mVoiceInteractor; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1869 | return nci; |
| 1870 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 1871 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1872 | public void onLowMemory() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1873 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onLowMemory " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1874 | mCalled = true; |
Dianne Hackborn | 9d07180 | 2010-12-08 14:49:15 -0800 | [diff] [blame] | 1875 | mFragments.dispatchLowMemory(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1876 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 1877 | |
| 1878 | public void onTrimMemory(int level) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1879 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onTrimMemory " + this + ": " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 1880 | mCalled = true; |
| 1881 | mFragments.dispatchTrimMemory(level); |
| 1882 | } |
| 1883 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1884 | /** |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 1885 | * Return the FragmentManager for interacting with fragments associated |
| 1886 | * with this activity. |
| 1887 | */ |
| 1888 | public FragmentManager getFragmentManager() { |
| 1889 | return mFragments; |
| 1890 | } |
| 1891 | |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 1892 | void invalidateFragment(String who) { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 1893 | //Log.v(TAG, "invalidateFragmentIndex: index=" + index); |
Dianne Hackborn | 9e14e9f3 | 2010-07-14 11:07:38 -0700 | [diff] [blame] | 1894 | if (mAllLoaderManagers != null) { |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 1895 | LoaderManagerImpl lm = mAllLoaderManagers.get(who); |
Dianne Hackborn | d04ad54 | 2011-07-25 16:16:15 -0700 | [diff] [blame] | 1896 | if (lm != null && !lm.mRetaining) { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 1897 | lm.doDestroy(); |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 1898 | mAllLoaderManagers.remove(who); |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 1899 | } |
Dianne Hackborn | 9e14e9f3 | 2010-07-14 11:07:38 -0700 | [diff] [blame] | 1900 | } |
| 1901 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1902 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 1903 | /** |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 1904 | * Called when a Fragment is being attached to this activity, immediately |
| 1905 | * after the call to its {@link Fragment#onAttach Fragment.onAttach()} |
| 1906 | * method and before {@link Fragment#onCreate Fragment.onCreate()}. |
| 1907 | */ |
| 1908 | public void onAttachFragment(Fragment fragment) { |
| 1909 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1910 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 1911 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1912 | * Wrapper around |
| 1913 | * {@link ContentResolver#query(android.net.Uri , String[], String, String[], String)} |
| 1914 | * that gives the resulting {@link Cursor} to call |
| 1915 | * {@link #startManagingCursor} so that the activity will manage its |
| 1916 | * lifecycle for you. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1917 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 1918 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 1919 | * or later, consider instead using {@link LoaderManager} instead, available |
| 1920 | * via {@link #getLoaderManager()}.</em> |
| 1921 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 1922 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on a cursor obtained using |
| 1923 | * this method, because the activity will do that for you at the appropriate time. However, if |
| 1924 | * you call {@link #stopManagingCursor} on a cursor from a managed query, the system <em>will |
| 1925 | * not</em> automatically close the cursor and, in that case, you must call |
| 1926 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1927 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1928 | * @param uri The URI of the content provider to query. |
| 1929 | * @param projection List of columns to return. |
| 1930 | * @param selection SQL WHERE clause. |
| 1931 | * @param sortOrder SQL ORDER BY clause. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1932 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1933 | * @return The Cursor that was returned by query(). |
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 ContentResolver#query(android.net.Uri , String[], String, String[], String) |
| 1936 | * @see #startManagingCursor |
| 1937 | * @hide |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 1938 | * |
| 1939 | * @deprecated Use {@link CursorLoader} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1940 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 1941 | @Deprecated |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 1942 | public final Cursor managedQuery(Uri uri, String[] projection, String selection, |
| 1943 | String sortOrder) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1944 | Cursor c = getContentResolver().query(uri, projection, selection, null, sortOrder); |
| 1945 | if (c != null) { |
| 1946 | startManagingCursor(c); |
| 1947 | } |
| 1948 | return c; |
| 1949 | } |
| 1950 | |
| 1951 | /** |
| 1952 | * Wrapper around |
| 1953 | * {@link ContentResolver#query(android.net.Uri , String[], String, String[], String)} |
| 1954 | * that gives the resulting {@link Cursor} to call |
| 1955 | * {@link #startManagingCursor} so that the activity will manage its |
| 1956 | * lifecycle for you. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1957 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 1958 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 1959 | * or later, consider instead using {@link LoaderManager} instead, available |
| 1960 | * via {@link #getLoaderManager()}.</em> |
| 1961 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 1962 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on a cursor obtained using |
| 1963 | * this method, because the activity will do that for you at the appropriate time. However, if |
| 1964 | * you call {@link #stopManagingCursor} on a cursor from a managed query, the system <em>will |
| 1965 | * not</em> automatically close the cursor and, in that case, you must call |
| 1966 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1967 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1968 | * @param uri The URI of the content provider to query. |
| 1969 | * @param projection List of columns to return. |
| 1970 | * @param selection SQL WHERE clause. |
| 1971 | * @param selectionArgs The arguments to selection, if any ?s are pesent |
| 1972 | * @param sortOrder SQL ORDER BY clause. |
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 | * @return The Cursor that was returned by query(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1975 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1976 | * @see ContentResolver#query(android.net.Uri , String[], String, String[], String) |
| 1977 | * @see #startManagingCursor |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 1978 | * |
| 1979 | * @deprecated Use {@link CursorLoader} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1980 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 1981 | @Deprecated |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 1982 | public final Cursor managedQuery(Uri uri, String[] projection, String selection, |
| 1983 | String[] selectionArgs, String sortOrder) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1984 | Cursor c = getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder); |
| 1985 | if (c != null) { |
| 1986 | startManagingCursor(c); |
| 1987 | } |
| 1988 | return c; |
| 1989 | } |
| 1990 | |
| 1991 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1992 | * This method allows the activity to take care of managing the given |
| 1993 | * {@link Cursor}'s lifecycle for you based on the activity's lifecycle. |
| 1994 | * That is, when the activity is stopped it will automatically call |
| 1995 | * {@link Cursor#deactivate} on the given Cursor, and when it is later restarted |
| 1996 | * it will call {@link Cursor#requery} for you. When the activity is |
| 1997 | * destroyed, all managed Cursors will be closed automatically. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1998 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 1999 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 2000 | * or later, consider instead using {@link LoaderManager} instead, available |
| 2001 | * via {@link #getLoaderManager()}.</em> |
| 2002 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 2003 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on cursor obtained from |
| 2004 | * {@link #managedQuery}, because the activity will do that for you at the appropriate time. |
| 2005 | * However, if you call {@link #stopManagingCursor} on a cursor from a managed query, the system |
| 2006 | * <em>will not</em> automatically close the cursor and, in that case, you must call |
| 2007 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2008 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2009 | * @param c The Cursor to be managed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2010 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2011 | * @see #managedQuery(android.net.Uri , String[], String, String[], String) |
| 2012 | * @see #stopManagingCursor |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 2013 | * |
| 2014 | * @deprecated Use the new {@link android.content.CursorLoader} class with |
| 2015 | * {@link LoaderManager} instead; this is also |
| 2016 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2017 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2018 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2019 | public void startManagingCursor(Cursor c) { |
| 2020 | synchronized (mManagedCursors) { |
| 2021 | mManagedCursors.add(new ManagedCursor(c)); |
| 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | /** |
| 2026 | * Given a Cursor that was previously given to |
| 2027 | * {@link #startManagingCursor}, stop the activity's management of that |
| 2028 | * cursor. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2029 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 2030 | * <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] | 2031 | * 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] | 2032 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2033 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2034 | * @param c The Cursor that was being managed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2035 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2036 | * @see #startManagingCursor |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 2037 | * |
| 2038 | * @deprecated Use the new {@link android.content.CursorLoader} class with |
| 2039 | * {@link LoaderManager} instead; this is also |
| 2040 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2041 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2042 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2043 | public void stopManagingCursor(Cursor c) { |
| 2044 | synchronized (mManagedCursors) { |
| 2045 | final int N = mManagedCursors.size(); |
| 2046 | for (int i=0; i<N; i++) { |
| 2047 | ManagedCursor mc = mManagedCursors.get(i); |
| 2048 | if (mc.mCursor == c) { |
| 2049 | mManagedCursors.remove(i); |
| 2050 | break; |
| 2051 | } |
| 2052 | } |
| 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | /** |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 2057 | * @deprecated As of {@link android.os.Build.VERSION_CODES#GINGERBREAD} |
| 2058 | * this is a no-op. |
Dianne Hackborn | 4f3867e | 2010-12-14 22:09:51 -0800 | [diff] [blame] | 2059 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2060 | */ |
Dianne Hackborn | d3efa39 | 2010-09-01 17:34:12 -0700 | [diff] [blame] | 2061 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2062 | public void setPersistent(boolean isPersistent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | /** |
| 2066 | * Finds a view that was identified by the id attribute from the XML that |
| 2067 | * was processed in {@link #onCreate}. |
| 2068 | * |
| 2069 | * @return The view if found or null otherwise. |
| 2070 | */ |
| 2071 | public View findViewById(int id) { |
| 2072 | return getWindow().findViewById(id); |
| 2073 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2074 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2075 | /** |
| 2076 | * Retrieve a reference to this activity's ActionBar. |
Adam Powell | 42c0fe8 | 2010-08-10 16:36:56 -0700 | [diff] [blame] | 2077 | * |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2078 | * @return The Activity's ActionBar, or null if it does not have one. |
| 2079 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2080 | @Nullable |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2081 | public ActionBar getActionBar() { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2082 | initWindowDecorActionBar(); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2083 | return mActionBar; |
| 2084 | } |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2085 | |
| 2086 | /** |
| 2087 | * Set a {@link android.widget.Toolbar Toolbar} to act as the {@link ActionBar} for this |
| 2088 | * Activity window. |
| 2089 | * |
| 2090 | * <p>When set to a non-null value the {@link #getActionBar()} method will return |
| 2091 | * an {@link ActionBar} object that can be used to control the given toolbar as if it were |
| 2092 | * a traditional window decor action bar. The toolbar's menu will be populated with the |
| 2093 | * Activity's options menu and the navigation button will be wired through the standard |
| 2094 | * {@link android.R.id#home home} menu select action.</p> |
| 2095 | * |
| 2096 | * <p>In order to use a Toolbar within the Activity's window content the application |
| 2097 | * must not request the window feature {@link Window#FEATURE_ACTION_BAR FEATURE_ACTION_BAR}.</p> |
| 2098 | * |
Adam Powell | 3778014 | 2014-06-01 13:31:00 -0700 | [diff] [blame] | 2099 | * @param toolbar Toolbar to set as the Activity's action bar |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2100 | */ |
Adam Powell | 3778014 | 2014-06-01 13:31:00 -0700 | [diff] [blame] | 2101 | public void setActionBar(@Nullable Toolbar toolbar) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2102 | if (getActionBar() instanceof WindowDecorActionBar) { |
| 2103 | throw new IllegalStateException("This Activity already has an action bar supplied " + |
| 2104 | "by the window decor. Do not request Window.FEATURE_ACTION_BAR and set " + |
| 2105 | "android:windowActionBar to false in your theme to use a Toolbar instead."); |
| 2106 | } |
Adam Powell | 14e1afe | 2014-08-18 15:58:23 -0700 | [diff] [blame] | 2107 | ToolbarActionBar tbab = new ToolbarActionBar(toolbar, getTitle(), this); |
| 2108 | mActionBar = tbab; |
| 2109 | mWindow.setCallback(tbab.getWrappedWindowCallback()); |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 2110 | mActionBar.invalidateOptionsMenu(); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2111 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2113 | /** |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2114 | * Creates a new ActionBar, locates the inflated ActionBarView, |
| 2115 | * initializes the ActionBar with the view, and sets mActionBar. |
| 2116 | */ |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2117 | private void initWindowDecorActionBar() { |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 2118 | Window window = getWindow(); |
Adam Powell | a593d98 | 2011-05-13 14:09:54 -0700 | [diff] [blame] | 2119 | |
| 2120 | // Initializing the window decor can change window feature flags. |
| 2121 | // Make sure that we have the correct set before performing the test below. |
| 2122 | window.getDecorView(); |
| 2123 | |
Adam Powell | 9b4c804 | 2010-08-10 15:36:44 -0700 | [diff] [blame] | 2124 | if (isChild() || !window.hasFeature(Window.FEATURE_ACTION_BAR) || mActionBar != null) { |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2125 | return; |
| 2126 | } |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2127 | |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2128 | mActionBar = new WindowDecorActionBar(this); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 2129 | mActionBar.setDefaultDisplayHomeAsUpEnabled(mEnableDefaultActionBarUp); |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2130 | |
| 2131 | mWindow.setDefaultIcon(mActivityInfo.getIconResource()); |
| 2132 | mWindow.setDefaultLogo(mActivityInfo.getLogoResource()); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2133 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2134 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2135 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | * Set the activity content from a layout resource. The resource will be |
| 2137 | * inflated, adding all top-level views to the activity. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 2138 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2139 | * @param layoutResID Resource ID to be inflated. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2140 | * |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 2141 | * @see #setContentView(android.view.View) |
| 2142 | * @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2143 | */ |
| 2144 | public void setContentView(int layoutResID) { |
| 2145 | getWindow().setContentView(layoutResID); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2146 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | /** |
| 2150 | * Set the activity content to an explicit view. This view is placed |
| 2151 | * 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] | 2152 | * view hierarchy. When calling this method, the layout parameters of the |
| 2153 | * specified view are ignored. Both the width and the height of the view are |
| 2154 | * set by default to {@link ViewGroup.LayoutParams#MATCH_PARENT}. To use |
| 2155 | * your own layout parameters, invoke |
| 2156 | * {@link #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)} |
| 2157 | * instead. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2158 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2159 | * @param view The desired content to display. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 2160 | * |
| 2161 | * @see #setContentView(int) |
| 2162 | * @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2163 | */ |
| 2164 | public void setContentView(View view) { |
| 2165 | getWindow().setContentView(view); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2166 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2167 | } |
| 2168 | |
| 2169 | /** |
| 2170 | * Set the activity content to an explicit view. This view is placed |
| 2171 | * 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] | 2172 | * view hierarchy. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2173 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2174 | * @param view The desired content to display. |
| 2175 | * @param params Layout parameters for the view. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 2176 | * |
| 2177 | * @see #setContentView(android.view.View) |
| 2178 | * @see #setContentView(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2179 | */ |
| 2180 | public void setContentView(View view, ViewGroup.LayoutParams params) { |
| 2181 | getWindow().setContentView(view, params); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2182 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | /** |
| 2186 | * Add an additional content view to the activity. Added after any existing |
| 2187 | * ones in the activity -- existing views are NOT removed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2188 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2189 | * @param view The desired content to display. |
| 2190 | * @param params Layout parameters for the view. |
| 2191 | */ |
| 2192 | public void addContentView(View view, ViewGroup.LayoutParams params) { |
| 2193 | getWindow().addContentView(view, params); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2194 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | /** |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2198 | * Retrieve the {@link TransitionManager} responsible for default transitions in this window. |
| 2199 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 2200 | * |
| 2201 | * <p>This method will return non-null after content has been initialized (e.g. by using |
| 2202 | * {@link #setContentView}) if {@link Window#FEATURE_CONTENT_TRANSITIONS} has been granted.</p> |
| 2203 | * |
| 2204 | * @return This window's content TransitionManager or null if none is set. |
| 2205 | */ |
| 2206 | public TransitionManager getContentTransitionManager() { |
| 2207 | return getWindow().getTransitionManager(); |
| 2208 | } |
| 2209 | |
| 2210 | /** |
| 2211 | * Set the {@link TransitionManager} to use for default transitions in this window. |
| 2212 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 2213 | * |
| 2214 | * @param tm The TransitionManager to use for scene changes. |
| 2215 | */ |
| 2216 | public void setContentTransitionManager(TransitionManager tm) { |
| 2217 | getWindow().setTransitionManager(tm); |
| 2218 | } |
| 2219 | |
| 2220 | /** |
| 2221 | * Retrieve the {@link Scene} representing this window's current content. |
| 2222 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 2223 | * |
| 2224 | * <p>This method will return null if the current content is not represented by a Scene.</p> |
| 2225 | * |
| 2226 | * @return Current Scene being shown or null |
| 2227 | */ |
| 2228 | public Scene getContentScene() { |
| 2229 | return getWindow().getContentScene(); |
| 2230 | } |
| 2231 | |
| 2232 | /** |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 2233 | * Sets whether this activity is finished when touched outside its window's |
| 2234 | * bounds. |
| 2235 | */ |
| 2236 | public void setFinishOnTouchOutside(boolean finish) { |
| 2237 | mWindow.setCloseOnTouchOutside(finish); |
| 2238 | } |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2239 | |
| 2240 | /** @hide */ |
| 2241 | @IntDef({ |
| 2242 | DEFAULT_KEYS_DISABLE, |
| 2243 | DEFAULT_KEYS_DIALER, |
| 2244 | DEFAULT_KEYS_SHORTCUT, |
| 2245 | DEFAULT_KEYS_SEARCH_LOCAL, |
| 2246 | DEFAULT_KEYS_SEARCH_GLOBAL}) |
| 2247 | @Retention(RetentionPolicy.SOURCE) |
| 2248 | @interface DefaultKeyMode {} |
| 2249 | |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 2250 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2251 | * Use with {@link #setDefaultKeyMode} to turn off default handling of |
| 2252 | * keys. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2253 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2254 | * @see #setDefaultKeyMode |
| 2255 | */ |
| 2256 | static public final int DEFAULT_KEYS_DISABLE = 0; |
| 2257 | /** |
| 2258 | * Use with {@link #setDefaultKeyMode} to launch the dialer during default |
| 2259 | * key handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2260 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2261 | * @see #setDefaultKeyMode |
| 2262 | */ |
| 2263 | static public final int DEFAULT_KEYS_DIALER = 1; |
| 2264 | /** |
| 2265 | * Use with {@link #setDefaultKeyMode} to execute a menu shortcut in |
| 2266 | * default key handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2267 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2268 | * <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] | 2269 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2270 | * @see #setDefaultKeyMode |
| 2271 | */ |
| 2272 | static public final int DEFAULT_KEYS_SHORTCUT = 2; |
| 2273 | /** |
| 2274 | * Use with {@link #setDefaultKeyMode} to specify that unhandled keystrokes |
| 2275 | * will start an application-defined search. (If the application or activity does not |
| 2276 | * actually define a search, the the keys will be ignored.) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2277 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2278 | * <p>See {@link android.app.SearchManager android.app.SearchManager} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2279 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2280 | * @see #setDefaultKeyMode |
| 2281 | */ |
| 2282 | static public final int DEFAULT_KEYS_SEARCH_LOCAL = 3; |
| 2283 | |
| 2284 | /** |
| 2285 | * Use with {@link #setDefaultKeyMode} to specify that unhandled keystrokes |
| 2286 | * will start a global search (typically web search, but some platforms may define alternate |
| 2287 | * methods for global search) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2288 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2289 | * <p>See {@link android.app.SearchManager android.app.SearchManager} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2290 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2291 | * @see #setDefaultKeyMode |
| 2292 | */ |
| 2293 | static public final int DEFAULT_KEYS_SEARCH_GLOBAL = 4; |
| 2294 | |
| 2295 | /** |
| 2296 | * Select the default key handling for this activity. This controls what |
| 2297 | * will happen to key events that are not otherwise handled. The default |
| 2298 | * mode ({@link #DEFAULT_KEYS_DISABLE}) will simply drop them on the |
| 2299 | * floor. Other modes allow you to launch the dialer |
| 2300 | * ({@link #DEFAULT_KEYS_DIALER}), execute a shortcut in your options |
| 2301 | * menu without requiring the menu key be held down |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2302 | * ({@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] | 2303 | * and {@link #DEFAULT_KEYS_SEARCH_GLOBAL}). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2304 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2305 | * <p>Note that the mode selected here does not impact the default |
| 2306 | * handling of system keys, such as the "back" and "menu" keys, and your |
| 2307 | * activity and its views always get a first chance to receive and handle |
| 2308 | * all application keys. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2309 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2310 | * @param mode The desired default key mode constant. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2311 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2312 | * @see #DEFAULT_KEYS_DISABLE |
| 2313 | * @see #DEFAULT_KEYS_DIALER |
| 2314 | * @see #DEFAULT_KEYS_SHORTCUT |
| 2315 | * @see #DEFAULT_KEYS_SEARCH_LOCAL |
| 2316 | * @see #DEFAULT_KEYS_SEARCH_GLOBAL |
| 2317 | * @see #onKeyDown |
| 2318 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2319 | public final void setDefaultKeyMode(@DefaultKeyMode int mode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2320 | mDefaultKeyMode = mode; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | // Some modes use a SpannableStringBuilder to track & dispatch input events |
| 2323 | // This list must remain in sync with the switch in onKeyDown() |
| 2324 | switch (mode) { |
| 2325 | case DEFAULT_KEYS_DISABLE: |
| 2326 | case DEFAULT_KEYS_SHORTCUT: |
| 2327 | mDefaultKeySsb = null; // not used in these modes |
| 2328 | break; |
| 2329 | case DEFAULT_KEYS_DIALER: |
| 2330 | case DEFAULT_KEYS_SEARCH_LOCAL: |
| 2331 | case DEFAULT_KEYS_SEARCH_GLOBAL: |
| 2332 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 2333 | Selection.setSelection(mDefaultKeySsb,0); |
| 2334 | break; |
| 2335 | default: |
| 2336 | throw new IllegalArgumentException(); |
| 2337 | } |
| 2338 | } |
| 2339 | |
| 2340 | /** |
| 2341 | * 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] | 2342 | * 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] | 2343 | * is inside a TextView will not trigger the event (unless it is a navigation |
| 2344 | * to another object) because TextView handles its own key presses. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2345 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2346 | * <p>If the focused view didn't want this event, this method is called. |
| 2347 | * |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2348 | * <p>The default implementation takes care of {@link KeyEvent#KEYCODE_BACK} |
| 2349 | * by calling {@link #onBackPressed()}, though the behavior varies based |
| 2350 | * on the application compatibility mode: for |
| 2351 | * {@link android.os.Build.VERSION_CODES#ECLAIR} or later applications, |
| 2352 | * it will set up the dispatch to call {@link #onKeyUp} where the action |
| 2353 | * will be performed; for earlier applications, it will perform the |
| 2354 | * action immediately in on-down, as those versions of the platform |
| 2355 | * behaved. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2356 | * |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2357 | * <p>Other additional default key handling may be performed |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2358 | * if configured with {@link #setDefaultKeyMode}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2359 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2360 | * @return Return <code>true</code> to prevent this event from being propagated |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2361 | * 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] | 2362 | * this event and it should continue to be propagated. |
| 2363 | * @see #onKeyUp |
| 2364 | * @see android.view.KeyEvent |
| 2365 | */ |
| 2366 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2367 | if (keyCode == KeyEvent.KEYCODE_BACK) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2368 | if (getApplicationInfo().targetSdkVersion |
| 2369 | >= Build.VERSION_CODES.ECLAIR) { |
| 2370 | event.startTracking(); |
| 2371 | } else { |
| 2372 | onBackPressed(); |
| 2373 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2374 | return true; |
| 2375 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2377 | if (mDefaultKeyMode == DEFAULT_KEYS_DISABLE) { |
| 2378 | return false; |
| 2379 | } else if (mDefaultKeyMode == DEFAULT_KEYS_SHORTCUT) { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 2380 | Window w = getWindow(); |
| 2381 | if (w.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 2382 | w.performPanelShortcut(Window.FEATURE_OPTIONS_PANEL, keyCode, event, |
| 2383 | Menu.FLAG_ALWAYS_PERFORM_CLOSE)) { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2384 | return true; |
| 2385 | } |
| 2386 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2387 | } else { |
| 2388 | // Common code for DEFAULT_KEYS_DIALER & DEFAULT_KEYS_SEARCH_* |
| 2389 | boolean clearSpannable = false; |
| 2390 | boolean handled; |
| 2391 | if ((event.getRepeatCount() != 0) || event.isSystem()) { |
| 2392 | clearSpannable = true; |
| 2393 | handled = false; |
| 2394 | } else { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2395 | handled = TextKeyListener.getInstance().onKeyDown( |
| 2396 | null, mDefaultKeySsb, keyCode, event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2397 | if (handled && mDefaultKeySsb.length() > 0) { |
| 2398 | // something useable has been typed - dispatch it now. |
| 2399 | |
| 2400 | final String str = mDefaultKeySsb.toString(); |
| 2401 | clearSpannable = true; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2402 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2403 | switch (mDefaultKeyMode) { |
| 2404 | case DEFAULT_KEYS_DIALER: |
| 2405 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + str)); |
| 2406 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2407 | startActivity(intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2408 | break; |
| 2409 | case DEFAULT_KEYS_SEARCH_LOCAL: |
| 2410 | startSearch(str, false, null, false); |
| 2411 | break; |
| 2412 | case DEFAULT_KEYS_SEARCH_GLOBAL: |
| 2413 | startSearch(str, false, null, true); |
| 2414 | break; |
| 2415 | } |
| 2416 | } |
| 2417 | } |
| 2418 | if (clearSpannable) { |
| 2419 | mDefaultKeySsb.clear(); |
| 2420 | mDefaultKeySsb.clearSpans(); |
| 2421 | Selection.setSelection(mDefaultKeySsb,0); |
| 2422 | } |
| 2423 | return handled; |
| 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2428 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 2429 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 2430 | * the event). |
| 2431 | */ |
| 2432 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 2433 | return false; |
| 2434 | } |
| 2435 | |
| 2436 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2437 | * 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] | 2438 | * 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] | 2439 | * is inside a TextView will not trigger the event (unless it is a navigation |
| 2440 | * to another object) because TextView handles its own key presses. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2441 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2442 | * <p>The default implementation handles KEYCODE_BACK to stop the activity |
| 2443 | * and go back. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2444 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2445 | * @return Return <code>true</code> to prevent this event from being propagated |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2446 | * further, or <code>false</code> to indicate that you have not handled |
| 2447 | * this event and it should continue to be propagated. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2448 | * @see #onKeyDown |
| 2449 | * @see KeyEvent |
| 2450 | */ |
| 2451 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2452 | if (getApplicationInfo().targetSdkVersion |
| 2453 | >= Build.VERSION_CODES.ECLAIR) { |
| 2454 | if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() |
| 2455 | && !event.isCanceled()) { |
| 2456 | onBackPressed(); |
| 2457 | return true; |
| 2458 | } |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2459 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2460 | return false; |
| 2461 | } |
| 2462 | |
| 2463 | /** |
| 2464 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 2465 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 2466 | * the event). |
| 2467 | */ |
| 2468 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 2469 | return false; |
| 2470 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2471 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2472 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2473 | * Called when the activity has detected the user's press of the back |
| 2474 | * key. The default implementation simply finishes the current activity, |
| 2475 | * but you can override this to do whatever you want. |
| 2476 | */ |
| 2477 | public void onBackPressed() { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 2478 | if (mActionBar != null && mActionBar.collapseActionView()) { |
| 2479 | return; |
| 2480 | } |
| 2481 | |
Dianne Hackborn | 3a57fb9 | 2010-11-15 17:58:52 -0800 | [diff] [blame] | 2482 | if (!mFragments.popBackStackImmediate()) { |
Craig Mautner | 73f843d | 2014-05-19 09:42:28 -0700 | [diff] [blame] | 2483 | finishAfterTransition(); |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 2484 | } |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2485 | } |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 2486 | |
| 2487 | /** |
| 2488 | * Called when a key shortcut event is not handled by any of the views in the Activity. |
| 2489 | * Override this method to implement global key shortcuts for the Activity. |
| 2490 | * Key shortcuts can also be implemented by setting the |
| 2491 | * {@link MenuItem#setShortcut(char, char) shortcut} property of menu items. |
| 2492 | * |
| 2493 | * @param keyCode The value in event.getKeyCode(). |
| 2494 | * @param event Description of the key event. |
| 2495 | * @return True if the key shortcut was handled. |
| 2496 | */ |
| 2497 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 2498 | return false; |
| 2499 | } |
| 2500 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2501 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | * Called when a touch screen event was not handled by any of the views |
| 2503 | * under it. This is most useful to process touch events that happen |
| 2504 | * outside of your window bounds, where there is no view to receive it. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2505 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2506 | * @param event The touch screen event being processed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2507 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2508 | * @return Return true if you have consumed the event, false if you haven't. |
| 2509 | * The default implementation always returns false. |
| 2510 | */ |
| 2511 | public boolean onTouchEvent(MotionEvent event) { |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 2512 | if (mWindow.shouldCloseOnTouch(this, event)) { |
| 2513 | finish(); |
| 2514 | return true; |
| 2515 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2516 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2517 | return false; |
| 2518 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2520 | /** |
| 2521 | * Called when the trackball was moved and not handled by any of the |
| 2522 | * views inside of the activity. So, for example, if the trackball moves |
| 2523 | * while focus is on a button, you will receive a call here because |
| 2524 | * buttons do not normally do anything with trackball events. The call |
| 2525 | * here happens <em>before</em> trackball movements are converted to |
| 2526 | * DPAD key events, which then get sent back to the view hierarchy, and |
| 2527 | * will be processed at the point for things like focus navigation. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2528 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2529 | * @param event The trackball event being processed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2530 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2531 | * @return Return true if you have consumed the event, false if you haven't. |
| 2532 | * The default implementation always returns false. |
| 2533 | */ |
| 2534 | public boolean onTrackballEvent(MotionEvent event) { |
| 2535 | return false; |
| 2536 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 2537 | |
| 2538 | /** |
| 2539 | * Called when a generic motion event was not handled by any of the |
| 2540 | * views inside of the activity. |
| 2541 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2542 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 2543 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 2544 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 2545 | * the class of input that was received. Implementations of this method |
| 2546 | * must examine the bits in the source before processing the event. |
| 2547 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2548 | * </p><p> |
| 2549 | * Generic motion events with source class |
| 2550 | * {@link android.view.InputDevice#SOURCE_CLASS_POINTER} |
| 2551 | * are delivered to the view under the pointer. All other generic motion events are |
| 2552 | * delivered to the focused view. |
| 2553 | * </p><p> |
| 2554 | * See {@link View#onGenericMotionEvent(MotionEvent)} for an example of how to |
| 2555 | * handle this event. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 2556 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 2557 | * |
| 2558 | * @param event The generic motion event being processed. |
| 2559 | * |
| 2560 | * @return Return true if you have consumed the event, false if you haven't. |
| 2561 | * The default implementation always returns false. |
| 2562 | */ |
| 2563 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 2564 | return false; |
| 2565 | } |
| 2566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2567 | /** |
| 2568 | * Called whenever a key, touch, or trackball event is dispatched to the |
| 2569 | * activity. Implement this method if you wish to know that the user has |
| 2570 | * interacted with the device in some way while your activity is running. |
| 2571 | * This callback and {@link #onUserLeaveHint} are intended to help |
| 2572 | * activities manage status bar notifications intelligently; specifically, |
| 2573 | * for helping activities determine the proper time to cancel a notfication. |
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 | * <p>All calls to your activity's {@link #onUserLeaveHint} callback will |
| 2576 | * be accompanied by calls to {@link #onUserInteraction}. This |
| 2577 | * ensures that your activity will be told of relevant user activity such |
| 2578 | * as pulling down the notification pane and touching an item there. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2579 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2580 | * <p>Note that this callback will be invoked for the touch down action |
| 2581 | * that begins a touch gesture, but may not be invoked for the touch-moved |
| 2582 | * and touch-up actions that follow. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2583 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2584 | * @see #onUserLeaveHint() |
| 2585 | */ |
| 2586 | public void onUserInteraction() { |
| 2587 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2589 | public void onWindowAttributesChanged(WindowManager.LayoutParams params) { |
| 2590 | // Update window manager if: we have a view, that view is |
| 2591 | // attached to its parent (which will be a RootView), and |
| 2592 | // this activity is not embedded. |
| 2593 | if (mParent == null) { |
| 2594 | View decor = mDecor; |
| 2595 | if (decor != null && decor.getParent() != null) { |
| 2596 | getWindowManager().updateViewLayout(decor, params); |
| 2597 | } |
| 2598 | } |
| 2599 | } |
| 2600 | |
| 2601 | public void onContentChanged() { |
| 2602 | } |
| 2603 | |
| 2604 | /** |
| 2605 | * Called when the current {@link Window} of the activity gains or loses |
| 2606 | * focus. This is the best indicator of whether this activity is visible |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2607 | * to the user. The default implementation clears the key tracking |
| 2608 | * state, so should always be called. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2609 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2610 | * <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] | 2611 | * is managed independently of activity lifecycles. As such, while focus |
| 2612 | * changes will generally have some relation to lifecycle changes (an |
| 2613 | * activity that is stopped will not generally get window focus), you |
| 2614 | * should not rely on any particular order between the callbacks here and |
| 2615 | * those in the other lifecycle methods such as {@link #onResume}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2616 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | * <p>As a general rule, however, a resumed activity will have window |
| 2618 | * focus... unless it has displayed other dialogs or popups that take |
| 2619 | * input focus, in which case the activity itself will not have focus |
| 2620 | * when the other windows have it. Likewise, the system may display |
| 2621 | * system-level windows (such as the status bar notification panel or |
| 2622 | * a system alert) which will temporarily take window input focus without |
| 2623 | * pausing the foreground activity. |
| 2624 | * |
| 2625 | * @param hasFocus Whether the window of this activity has focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2626 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2627 | * @see #hasWindowFocus() |
| 2628 | * @see #onResume |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 2629 | * @see View#onWindowFocusChanged(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2630 | */ |
| 2631 | public void onWindowFocusChanged(boolean hasFocus) { |
| 2632 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2634 | /** |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 2635 | * Called when the main window associated with the activity has been |
| 2636 | * attached to the window manager. |
| 2637 | * See {@link View#onAttachedToWindow() View.onAttachedToWindow()} |
| 2638 | * for more information. |
| 2639 | * @see View#onAttachedToWindow |
| 2640 | */ |
| 2641 | public void onAttachedToWindow() { |
| 2642 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2643 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 2644 | /** |
| 2645 | * Called when the main window associated with the activity has been |
| 2646 | * detached from the window manager. |
| 2647 | * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()} |
| 2648 | * for more information. |
| 2649 | * @see View#onDetachedFromWindow |
| 2650 | */ |
| 2651 | public void onDetachedFromWindow() { |
| 2652 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2653 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 2654 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2655 | * Returns true if this activity's <em>main</em> window currently has window focus. |
| 2656 | * Note that this is not the same as the view itself having focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2657 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2658 | * @return True if this activity's main window currently has window focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2659 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2660 | * @see #onWindowAttributesChanged(android.view.WindowManager.LayoutParams) |
| 2661 | */ |
| 2662 | public boolean hasWindowFocus() { |
| 2663 | Window w = getWindow(); |
| 2664 | if (w != null) { |
| 2665 | View d = w.getDecorView(); |
| 2666 | if (d != null) { |
| 2667 | return d.hasWindowFocus(); |
| 2668 | } |
| 2669 | } |
| 2670 | return false; |
| 2671 | } |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 2672 | |
| 2673 | /** |
| 2674 | * Called when the main window associated with the activity has been dismissed. |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 2675 | * @hide |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 2676 | */ |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 2677 | @Override |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 2678 | public void onWindowDismissed() { |
| 2679 | finish(); |
| 2680 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2682 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2683 | * Called to process key events. You can override this to intercept all |
| 2684 | * 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] | 2685 | * this implementation for key events that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2686 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2687 | * @param event The key event. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2688 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2689 | * @return boolean Return true if this event was consumed. |
| 2690 | */ |
| 2691 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 2692 | onUserInteraction(); |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 2693 | |
| 2694 | // Let action bars open menus in response to the menu key prioritized over |
| 2695 | // the window handling it |
| 2696 | if (event.getKeyCode() == KeyEvent.KEYCODE_MENU && |
| 2697 | mActionBar != null && mActionBar.onMenuKeyEvent(event)) { |
| 2698 | return true; |
| 2699 | } |
| 2700 | |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2701 | Window win = getWindow(); |
| 2702 | if (win.superDispatchKeyEvent(event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2703 | return true; |
| 2704 | } |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2705 | View decor = mDecor; |
| 2706 | if (decor == null) decor = win.getDecorView(); |
| 2707 | return event.dispatch(this, decor != null |
| 2708 | ? decor.getKeyDispatcherState() : null, this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 2712 | * Called to process a key shortcut event. |
| 2713 | * You can override this to intercept all key shortcut events before they are |
| 2714 | * dispatched to the window. Be sure to call this implementation for key shortcut |
| 2715 | * events that should be handled normally. |
| 2716 | * |
| 2717 | * @param event The key shortcut event. |
| 2718 | * @return True if this event was consumed. |
| 2719 | */ |
| 2720 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 2721 | onUserInteraction(); |
| 2722 | if (getWindow().superDispatchKeyShortcutEvent(event)) { |
| 2723 | return true; |
| 2724 | } |
| 2725 | return onKeyShortcut(event.getKeyCode(), event); |
| 2726 | } |
| 2727 | |
| 2728 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2729 | * Called to process touch screen events. You can override this to |
| 2730 | * intercept all touch screen events before they are dispatched to the |
| 2731 | * window. Be sure to call this implementation for touch screen events |
| 2732 | * that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2733 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2734 | * @param ev The touch screen event. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2735 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2736 | * @return boolean Return true if this event was consumed. |
| 2737 | */ |
| 2738 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 2739 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 2740 | onUserInteraction(); |
| 2741 | } |
| 2742 | if (getWindow().superDispatchTouchEvent(ev)) { |
| 2743 | return true; |
| 2744 | } |
| 2745 | return onTouchEvent(ev); |
| 2746 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2747 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2748 | /** |
| 2749 | * Called to process trackball events. You can override this to |
| 2750 | * intercept all trackball events before they are dispatched to the |
| 2751 | * window. Be sure to call this implementation for trackball events |
| 2752 | * that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2753 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2754 | * @param ev The trackball event. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2755 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2756 | * @return boolean Return true if this event was consumed. |
| 2757 | */ |
| 2758 | public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 2759 | onUserInteraction(); |
| 2760 | if (getWindow().superDispatchTrackballEvent(ev)) { |
| 2761 | return true; |
| 2762 | } |
| 2763 | return onTrackballEvent(ev); |
| 2764 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2765 | |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 2766 | /** |
| 2767 | * Called to process generic motion events. You can override this to |
| 2768 | * intercept all generic motion events before they are dispatched to the |
| 2769 | * window. Be sure to call this implementation for generic motion events |
| 2770 | * that should be handled normally. |
| 2771 | * |
| 2772 | * @param ev The generic motion event. |
| 2773 | * |
| 2774 | * @return boolean Return true if this event was consumed. |
| 2775 | */ |
| 2776 | public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 2777 | onUserInteraction(); |
| 2778 | if (getWindow().superDispatchGenericMotionEvent(ev)) { |
| 2779 | return true; |
| 2780 | } |
| 2781 | return onGenericMotionEvent(ev); |
| 2782 | } |
| 2783 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2784 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 2785 | event.setClassName(getClass().getName()); |
| 2786 | event.setPackageName(getPackageName()); |
| 2787 | |
| 2788 | LayoutParams params = getWindow().getAttributes(); |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 2789 | boolean isFullScreen = (params.width == LayoutParams.MATCH_PARENT) && |
| 2790 | (params.height == LayoutParams.MATCH_PARENT); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2791 | event.setFullScreen(isFullScreen); |
| 2792 | |
| 2793 | CharSequence title = getTitle(); |
| 2794 | if (!TextUtils.isEmpty(title)) { |
| 2795 | event.getText().add(title); |
| 2796 | } |
| 2797 | |
| 2798 | return true; |
| 2799 | } |
| 2800 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2801 | /** |
| 2802 | * Default implementation of |
| 2803 | * {@link android.view.Window.Callback#onCreatePanelView} |
| 2804 | * for activities. This |
| 2805 | * simply returns null so that all panel sub-windows will have the default |
| 2806 | * menu behavior. |
| 2807 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2808 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2809 | public View onCreatePanelView(int featureId) { |
| 2810 | return null; |
| 2811 | } |
| 2812 | |
| 2813 | /** |
| 2814 | * Default implementation of |
| 2815 | * {@link android.view.Window.Callback#onCreatePanelMenu} |
| 2816 | * for activities. This calls through to the new |
| 2817 | * {@link #onCreateOptionsMenu} method for the |
| 2818 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} panel, |
| 2819 | * so that subclasses of Activity don't need to deal with feature codes. |
| 2820 | */ |
| 2821 | public boolean onCreatePanelMenu(int featureId, Menu menu) { |
| 2822 | if (featureId == Window.FEATURE_OPTIONS_PANEL) { |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 2823 | boolean show = onCreateOptionsMenu(menu); |
| 2824 | show |= mFragments.dispatchCreateOptionsMenu(menu, getMenuInflater()); |
| 2825 | return show; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2826 | } |
| 2827 | return false; |
| 2828 | } |
| 2829 | |
| 2830 | /** |
| 2831 | * Default implementation of |
| 2832 | * {@link android.view.Window.Callback#onPreparePanel} |
| 2833 | * for activities. This |
| 2834 | * calls through to the new {@link #onPrepareOptionsMenu} method for the |
| 2835 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} |
| 2836 | * panel, so that subclasses of |
| 2837 | * Activity don't need to deal with feature codes. |
| 2838 | */ |
| 2839 | public boolean onPreparePanel(int featureId, View view, Menu menu) { |
| 2840 | if (featureId == Window.FEATURE_OPTIONS_PANEL && menu != null) { |
| 2841 | boolean goforit = onPrepareOptionsMenu(menu); |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 2842 | goforit |= mFragments.dispatchPrepareOptionsMenu(menu); |
Adam Powell | ef31e7c | 2012-05-08 09:59:40 -0700 | [diff] [blame] | 2843 | return goforit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2844 | } |
| 2845 | return true; |
| 2846 | } |
| 2847 | |
| 2848 | /** |
| 2849 | * {@inheritDoc} |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2850 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2851 | * @return The default implementation returns true. |
| 2852 | */ |
| 2853 | public boolean onMenuOpened(int featureId, Menu menu) { |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 2854 | if (featureId == Window.FEATURE_ACTION_BAR) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2855 | initWindowDecorActionBar(); |
Adam Powell | 049dd3d | 2010-12-02 13:43:59 -0800 | [diff] [blame] | 2856 | if (mActionBar != null) { |
| 2857 | mActionBar.dispatchMenuVisibilityChanged(true); |
| 2858 | } else { |
| 2859 | Log.e(TAG, "Tried to open action bar menu with no action bar"); |
| 2860 | } |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 2861 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2862 | return true; |
| 2863 | } |
| 2864 | |
| 2865 | /** |
| 2866 | * Default implementation of |
| 2867 | * {@link android.view.Window.Callback#onMenuItemSelected} |
| 2868 | * for activities. This calls through to the new |
| 2869 | * {@link #onOptionsItemSelected} method for the |
| 2870 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} |
| 2871 | * panel, so that subclasses of |
| 2872 | * Activity don't need to deal with feature codes. |
| 2873 | */ |
| 2874 | public boolean onMenuItemSelected(int featureId, MenuItem item) { |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 2875 | CharSequence titleCondensed = item.getTitleCondensed(); |
| 2876 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2877 | switch (featureId) { |
| 2878 | case Window.FEATURE_OPTIONS_PANEL: |
| 2879 | // Put event logging here so it gets called even if subclass |
| 2880 | // doesn't call through to superclass's implmeentation of each |
| 2881 | // of these methods below |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 2882 | if(titleCondensed != null) { |
| 2883 | EventLog.writeEvent(50000, 0, titleCondensed.toString()); |
| 2884 | } |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 2885 | if (onOptionsItemSelected(item)) { |
| 2886 | return true; |
| 2887 | } |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 2888 | if (mFragments.dispatchOptionsItemSelected(item)) { |
| 2889 | return true; |
| 2890 | } |
| 2891 | if (item.getItemId() == android.R.id.home && mActionBar != null && |
| 2892 | (mActionBar.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) != 0) { |
| 2893 | if (mParent == null) { |
Adam Powell | 07304f529 | 2012-05-07 17:32:44 -0700 | [diff] [blame] | 2894 | return onNavigateUp(); |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 2895 | } else { |
Adam Powell | 07304f529 | 2012-05-07 17:32:44 -0700 | [diff] [blame] | 2896 | return mParent.onNavigateUpFromChild(this); |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 2897 | } |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 2898 | } |
| 2899 | return false; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | case Window.FEATURE_CONTEXT_MENU: |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 2902 | if(titleCondensed != null) { |
| 2903 | EventLog.writeEvent(50000, 1, titleCondensed.toString()); |
| 2904 | } |
Dianne Hackborn | 5ddd127 | 2010-06-12 10:15:28 -0700 | [diff] [blame] | 2905 | if (onContextItemSelected(item)) { |
| 2906 | return true; |
| 2907 | } |
| 2908 | return mFragments.dispatchContextItemSelected(item); |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 2909 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2910 | default: |
| 2911 | return false; |
| 2912 | } |
| 2913 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2914 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2915 | /** |
| 2916 | * Default implementation of |
| 2917 | * {@link android.view.Window.Callback#onPanelClosed(int, Menu)} for |
| 2918 | * activities. This calls through to {@link #onOptionsMenuClosed(Menu)} |
| 2919 | * method for the {@link android.view.Window#FEATURE_OPTIONS_PANEL} panel, |
| 2920 | * so that subclasses of Activity don't need to deal with feature codes. |
| 2921 | * For context menus ({@link Window#FEATURE_CONTEXT_MENU}), the |
| 2922 | * {@link #onContextMenuClosed(Menu)} will be called. |
| 2923 | */ |
| 2924 | public void onPanelClosed(int featureId, Menu menu) { |
| 2925 | switch (featureId) { |
| 2926 | case Window.FEATURE_OPTIONS_PANEL: |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 2927 | mFragments.dispatchOptionsMenuClosed(menu); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2928 | onOptionsMenuClosed(menu); |
| 2929 | break; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2931 | case Window.FEATURE_CONTEXT_MENU: |
| 2932 | onContextMenuClosed(menu); |
| 2933 | break; |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 2934 | |
| 2935 | case Window.FEATURE_ACTION_BAR: |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2936 | initWindowDecorActionBar(); |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 2937 | mActionBar.dispatchMenuVisibilityChanged(false); |
| 2938 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2939 | } |
| 2940 | } |
| 2941 | |
| 2942 | /** |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 2943 | * Declare that the options menu has changed, so should be recreated. |
| 2944 | * The {@link #onCreateOptionsMenu(Menu)} method will be called the next |
| 2945 | * time it needs to be displayed. |
| 2946 | */ |
| 2947 | public void invalidateOptionsMenu() { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 2948 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 2949 | (mActionBar == null || !mActionBar.invalidateOptionsMenu())) { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 2950 | mWindow.invalidatePanelMenu(Window.FEATURE_OPTIONS_PANEL); |
| 2951 | } |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 2952 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2953 | |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 2954 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2955 | * Initialize the contents of the Activity's standard options menu. You |
| 2956 | * should place your menu items in to <var>menu</var>. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2957 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2958 | * <p>This is only called once, the first time the options menu is |
| 2959 | * displayed. To update the menu every time it is displayed, see |
| 2960 | * {@link #onPrepareOptionsMenu}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2961 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2962 | * <p>The default implementation populates the menu with standard system |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2963 | * menu items. These are placed in the {@link Menu#CATEGORY_SYSTEM} group so that |
| 2964 | * they will be correctly ordered with application-defined menu items. |
| 2965 | * Deriving classes should always call through to the base implementation. |
| 2966 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2967 | * <p>You can safely hold on to <var>menu</var> (and any items created |
| 2968 | * from it), making modifications to it as desired, until the next |
| 2969 | * time onCreateOptionsMenu() is called. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2970 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | * <p>When you add items to the menu, you can implement the Activity's |
| 2972 | * {@link #onOptionsItemSelected} method to handle them there. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2973 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2974 | * @param menu The options menu in which you place your items. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2975 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2976 | * @return You must return true for the menu to be displayed; |
| 2977 | * if you return false it will not be shown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2978 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2979 | * @see #onPrepareOptionsMenu |
| 2980 | * @see #onOptionsItemSelected |
| 2981 | */ |
| 2982 | public boolean onCreateOptionsMenu(Menu menu) { |
| 2983 | if (mParent != null) { |
| 2984 | return mParent.onCreateOptionsMenu(menu); |
| 2985 | } |
| 2986 | return true; |
| 2987 | } |
| 2988 | |
| 2989 | /** |
| 2990 | * Prepare the Screen's standard options menu to be displayed. This is |
| 2991 | * called right before the menu is shown, every time it is shown. You can |
| 2992 | * use this method to efficiently enable/disable items or otherwise |
| 2993 | * dynamically modify the contents. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2994 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2995 | * <p>The default implementation updates the system menu items based on the |
| 2996 | * activity's state. Deriving classes should always call through to the |
| 2997 | * base class implementation. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2998 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2999 | * @param menu The options menu as last shown or first initialized by |
| 3000 | * onCreateOptionsMenu(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3001 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3002 | * @return You must return true for the menu to be displayed; |
| 3003 | * if you return false it will not be shown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3004 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3005 | * @see #onCreateOptionsMenu |
| 3006 | */ |
| 3007 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 3008 | if (mParent != null) { |
| 3009 | return mParent.onPrepareOptionsMenu(menu); |
| 3010 | } |
| 3011 | return true; |
| 3012 | } |
| 3013 | |
| 3014 | /** |
| 3015 | * This hook is called whenever an item in your options menu is selected. |
| 3016 | * The default implementation simply returns false to have the normal |
| 3017 | * processing happen (calling the item's Runnable or sending a message to |
| 3018 | * its Handler as appropriate). You can use this method for any items |
| 3019 | * for which you would like to do processing without those other |
| 3020 | * facilities. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3021 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3022 | * <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] | 3023 | * perform the default menu handling.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3024 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3025 | * @param item The menu item that was selected. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3026 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3027 | * @return boolean Return false to allow normal menu processing to |
| 3028 | * proceed, true to consume it here. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3029 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3030 | * @see #onCreateOptionsMenu |
| 3031 | */ |
| 3032 | public boolean onOptionsItemSelected(MenuItem item) { |
| 3033 | if (mParent != null) { |
| 3034 | return mParent.onOptionsItemSelected(item); |
| 3035 | } |
| 3036 | return false; |
| 3037 | } |
| 3038 | |
| 3039 | /** |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3040 | * This method is called whenever the user chooses to navigate Up within your application's |
| 3041 | * activity hierarchy from the action bar. |
| 3042 | * |
| 3043 | * <p>If the attribute {@link android.R.attr#parentActivityName parentActivityName} |
| 3044 | * was specified in the manifest for this activity or an activity-alias to it, |
| 3045 | * default Up navigation will be handled automatically. If any activity |
| 3046 | * along the parent chain requires extra Intent arguments, the Activity subclass |
| 3047 | * should override the method {@link #onPrepareNavigateUpTaskStack(TaskStackBuilder)} |
| 3048 | * to supply those arguments.</p> |
| 3049 | * |
| 3050 | * <p>See <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back Stack</a> |
| 3051 | * from the developer guide and <a href="{@docRoot}design/patterns/navigation.html">Navigation</a> |
| 3052 | * from the design guide for more information about navigating within your app.</p> |
| 3053 | * |
| 3054 | * <p>See the {@link TaskStackBuilder} class and the Activity methods |
| 3055 | * {@link #getParentActivityIntent()}, {@link #shouldUpRecreateTask(Intent)}, and |
| 3056 | * {@link #navigateUpTo(Intent)} for help implementing custom Up navigation. |
| 3057 | * The AppNavigation sample application in the Android SDK is also available for reference.</p> |
| 3058 | * |
| 3059 | * @return true if Up navigation completed successfully and this Activity was finished, |
| 3060 | * false otherwise. |
| 3061 | */ |
| 3062 | public boolean onNavigateUp() { |
| 3063 | // Automatically handle hierarchical Up navigation if the proper |
| 3064 | // metadata is available. |
| 3065 | Intent upIntent = getParentActivityIntent(); |
| 3066 | if (upIntent != null) { |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 3067 | if (mActivityInfo.taskAffinity == null) { |
| 3068 | // Activities with a null affinity are special; they really shouldn't |
| 3069 | // specify a parent activity intent in the first place. Just finish |
| 3070 | // the current activity and call it a day. |
| 3071 | finish(); |
| 3072 | } else if (shouldUpRecreateTask(upIntent)) { |
Adam Powell | f78a844 | 2012-05-01 18:09:32 -0700 | [diff] [blame] | 3073 | TaskStackBuilder b = TaskStackBuilder.create(this); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3074 | onCreateNavigateUpTaskStack(b); |
| 3075 | onPrepareNavigateUpTaskStack(b); |
| 3076 | b.startActivities(); |
Adam Powell | 3d193d9 | 2012-05-15 16:51:55 -0700 | [diff] [blame] | 3077 | |
| 3078 | // We can't finishAffinity if we have a result. |
| 3079 | // Fall back and simply finish the current activity instead. |
| 3080 | if (mResultCode != RESULT_CANCELED || mResultData != null) { |
| 3081 | // Tell the developer what's going on to avoid hair-pulling. |
| 3082 | Log.i(TAG, "onNavigateUp only finishing topmost activity to return a result"); |
| 3083 | finish(); |
| 3084 | } else { |
| 3085 | finishAffinity(); |
| 3086 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3087 | } else { |
| 3088 | navigateUpTo(upIntent); |
| 3089 | } |
| 3090 | return true; |
| 3091 | } |
| 3092 | return false; |
| 3093 | } |
| 3094 | |
| 3095 | /** |
| 3096 | * This is called when a child activity of this one attempts to navigate up. |
| 3097 | * The default implementation simply calls onNavigateUp() on this activity (the parent). |
| 3098 | * |
| 3099 | * @param child The activity making the call. |
| 3100 | */ |
| 3101 | public boolean onNavigateUpFromChild(Activity child) { |
| 3102 | return onNavigateUp(); |
| 3103 | } |
| 3104 | |
| 3105 | /** |
| 3106 | * Define the synthetic task stack that will be generated during Up navigation from |
| 3107 | * a different task. |
| 3108 | * |
| 3109 | * <p>The default implementation of this method adds the parent chain of this activity |
| 3110 | * as specified in the manifest to the supplied {@link TaskStackBuilder}. Applications |
| 3111 | * may choose to override this method to construct the desired task stack in a different |
| 3112 | * way.</p> |
| 3113 | * |
Adam Powell | f019595 | 2012-05-02 21:38:54 -0700 | [diff] [blame] | 3114 | * <p>This method will be invoked by the default implementation of {@link #onNavigateUp()} |
| 3115 | * if {@link #shouldUpRecreateTask(Intent)} returns true when supplied with the intent |
| 3116 | * returned by {@link #getParentActivityIntent()}.</p> |
| 3117 | * |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3118 | * <p>Applications that wish to supply extra Intent parameters to the parent stack defined |
| 3119 | * by the manifest should override {@link #onPrepareNavigateUpTaskStack(TaskStackBuilder)}.</p> |
| 3120 | * |
| 3121 | * @param builder An empty TaskStackBuilder - the application should add intents representing |
| 3122 | * the desired task stack |
| 3123 | */ |
| 3124 | public void onCreateNavigateUpTaskStack(TaskStackBuilder builder) { |
| 3125 | builder.addParentStack(this); |
| 3126 | } |
| 3127 | |
| 3128 | /** |
| 3129 | * Prepare the synthetic task stack that will be generated during Up navigation |
| 3130 | * from a different task. |
| 3131 | * |
| 3132 | * <p>This method receives the {@link TaskStackBuilder} with the constructed series of |
| 3133 | * Intents as generated by {@link #onCreateNavigateUpTaskStack(TaskStackBuilder)}. |
| 3134 | * If any extra data should be added to these intents before launching the new task, |
| 3135 | * the application should override this method and add that data here.</p> |
| 3136 | * |
| 3137 | * @param builder A TaskStackBuilder that has been populated with Intents by |
| 3138 | * onCreateNavigateUpTaskStack. |
| 3139 | */ |
| 3140 | public void onPrepareNavigateUpTaskStack(TaskStackBuilder builder) { |
| 3141 | } |
| 3142 | |
| 3143 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3144 | * This hook is called whenever the options menu is being closed (either by the user canceling |
| 3145 | * the menu with the back/menu button, or when an item is selected). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3146 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3147 | * @param menu The options menu as last shown or first initialized by |
| 3148 | * onCreateOptionsMenu(). |
| 3149 | */ |
| 3150 | public void onOptionsMenuClosed(Menu menu) { |
| 3151 | if (mParent != null) { |
| 3152 | mParent.onOptionsMenuClosed(menu); |
| 3153 | } |
| 3154 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3155 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3156 | /** |
| 3157 | * Programmatically opens the options menu. If the options menu is already |
| 3158 | * open, this method does nothing. |
| 3159 | */ |
| 3160 | public void openOptionsMenu() { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 3161 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 3162 | (mActionBar == null || !mActionBar.openOptionsMenu())) { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3163 | mWindow.openPanel(Window.FEATURE_OPTIONS_PANEL, null); |
| 3164 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3165 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3167 | /** |
| 3168 | * Progammatically closes the options menu. If the options menu is already |
| 3169 | * closed, this method does nothing. |
| 3170 | */ |
| 3171 | public void closeOptionsMenu() { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 3172 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL)) { |
| 3173 | mWindow.closePanel(Window.FEATURE_OPTIONS_PANEL); |
| 3174 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | /** |
| 3178 | * Called when a context menu for the {@code view} is about to be shown. |
| 3179 | * Unlike {@link #onCreateOptionsMenu(Menu)}, this will be called every |
| 3180 | * time the context menu is about to be shown and should be populated for |
| 3181 | * the view (or item inside the view for {@link AdapterView} subclasses, |
| 3182 | * this can be found in the {@code menuInfo})). |
| 3183 | * <p> |
| 3184 | * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an |
| 3185 | * item has been selected. |
| 3186 | * <p> |
| 3187 | * 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] | 3188 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3189 | */ |
| 3190 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { |
| 3191 | } |
| 3192 | |
| 3193 | /** |
| 3194 | * Registers a context menu to be shown for the given view (multiple views |
| 3195 | * can show the context menu). This method will set the |
| 3196 | * {@link OnCreateContextMenuListener} on the view to this activity, so |
| 3197 | * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be |
| 3198 | * called when it is time to show the context menu. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3199 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3200 | * @see #unregisterForContextMenu(View) |
| 3201 | * @param view The view that should show a context menu. |
| 3202 | */ |
| 3203 | public void registerForContextMenu(View view) { |
| 3204 | view.setOnCreateContextMenuListener(this); |
| 3205 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3206 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3207 | /** |
| 3208 | * Prevents a context menu to be shown for the given view. This method will remove the |
| 3209 | * {@link OnCreateContextMenuListener} on the view. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3210 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3211 | * @see #registerForContextMenu(View) |
| 3212 | * @param view The view that should stop showing a context menu. |
| 3213 | */ |
| 3214 | public void unregisterForContextMenu(View view) { |
| 3215 | view.setOnCreateContextMenuListener(null); |
| 3216 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3218 | /** |
| 3219 | * Programmatically opens the context menu for a particular {@code view}. |
| 3220 | * The {@code view} should have been added via |
| 3221 | * {@link #registerForContextMenu(View)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3222 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3223 | * @param view The view to show the context menu for. |
| 3224 | */ |
| 3225 | public void openContextMenu(View view) { |
| 3226 | view.showContextMenu(); |
| 3227 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3229 | /** |
| 3230 | * Programmatically closes the most recently opened context menu, if showing. |
| 3231 | */ |
| 3232 | public void closeContextMenu() { |
Jose Lima | bd769a1 | 2015-01-28 10:43:15 -0800 | [diff] [blame] | 3233 | if (mWindow.hasFeature(Window.FEATURE_CONTEXT_MENU)) { |
| 3234 | mWindow.closePanel(Window.FEATURE_CONTEXT_MENU); |
| 3235 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | } |
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 | /** |
| 3239 | * This hook is called whenever an item in a context menu is selected. The |
| 3240 | * default implementation simply returns false to have the normal processing |
| 3241 | * happen (calling the item's Runnable or sending a message to its Handler |
| 3242 | * as appropriate). You can use this method for any items for which you |
| 3243 | * would like to do processing without those other facilities. |
| 3244 | * <p> |
| 3245 | * Use {@link MenuItem#getMenuInfo()} to get extra information set by the |
| 3246 | * View that added this menu item. |
| 3247 | * <p> |
| 3248 | * Derived classes should call through to the base class for it to perform |
| 3249 | * the default menu handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3250 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3251 | * @param item The context menu item that was selected. |
| 3252 | * @return boolean Return false to allow normal context menu processing to |
| 3253 | * proceed, true to consume it here. |
| 3254 | */ |
| 3255 | public boolean onContextItemSelected(MenuItem item) { |
| 3256 | if (mParent != null) { |
| 3257 | return mParent.onContextItemSelected(item); |
| 3258 | } |
| 3259 | return false; |
| 3260 | } |
| 3261 | |
| 3262 | /** |
| 3263 | * This hook is called whenever the context menu is being closed (either by |
| 3264 | * the user canceling the menu with the back/menu button, or when an item is |
| 3265 | * selected). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3266 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3267 | * @param menu The context menu that is being closed. |
| 3268 | */ |
| 3269 | public void onContextMenuClosed(Menu menu) { |
| 3270 | if (mParent != null) { |
| 3271 | mParent.onContextMenuClosed(menu); |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3276 | * @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] | 3277 | */ |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3278 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3279 | protected Dialog onCreateDialog(int id) { |
| 3280 | return null; |
| 3281 | } |
| 3282 | |
| 3283 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3284 | * Callback for creating dialogs that are managed (saved and restored) for you |
| 3285 | * by the activity. The default implementation calls through to |
| 3286 | * {@link #onCreateDialog(int)} for compatibility. |
| 3287 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 3288 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 3289 | * or later, consider instead using a {@link DialogFragment} instead.</em> |
| 3290 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3291 | * <p>If you use {@link #showDialog(int)}, the activity will call through to |
| 3292 | * this method the first time, and hang onto it thereafter. Any dialog |
| 3293 | * that is created by this method will automatically be saved and restored |
| 3294 | * for you, including whether it is showing. |
| 3295 | * |
| 3296 | * <p>If you would like the activity to manage saving and restoring dialogs |
| 3297 | * for you, you should override this method and handle any ids that are |
| 3298 | * passed to {@link #showDialog}. |
| 3299 | * |
| 3300 | * <p>If you would like an opportunity to prepare your dialog before it is shown, |
| 3301 | * override {@link #onPrepareDialog(int, Dialog, Bundle)}. |
| 3302 | * |
| 3303 | * @param id The id of the dialog. |
| 3304 | * @param args The dialog arguments provided to {@link #showDialog(int, Bundle)}. |
| 3305 | * @return The dialog. If you return null, the dialog will not be created. |
| 3306 | * |
| 3307 | * @see #onPrepareDialog(int, Dialog, Bundle) |
| 3308 | * @see #showDialog(int, Bundle) |
| 3309 | * @see #dismissDialog(int) |
| 3310 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3311 | * |
| 3312 | * @deprecated Use the new {@link DialogFragment} class with |
| 3313 | * {@link FragmentManager} instead; this is also |
| 3314 | * available on older platforms through the Android compatibility package. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3315 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3316 | @Nullable |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 3317 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3318 | protected Dialog onCreateDialog(int id, Bundle args) { |
| 3319 | return onCreateDialog(id); |
| 3320 | } |
| 3321 | |
| 3322 | /** |
| 3323 | * @deprecated Old no-arguments version of |
| 3324 | * {@link #onPrepareDialog(int, Dialog, Bundle)}. |
| 3325 | */ |
| 3326 | @Deprecated |
| 3327 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 3328 | dialog.setOwnerActivity(this); |
| 3329 | } |
| 3330 | |
| 3331 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3332 | * Provides an opportunity to prepare a managed dialog before it is being |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3333 | * shown. The default implementation calls through to |
| 3334 | * {@link #onPrepareDialog(int, Dialog)} for compatibility. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3335 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3336 | * <p> |
| 3337 | * Override this if you need to update a managed dialog based on the state |
| 3338 | * of the application each time it is shown. For example, a time picker |
| 3339 | * dialog might want to be updated with the current time. You should call |
| 3340 | * through to the superclass's implementation. The default implementation |
| 3341 | * will set this Activity as the owner activity on the Dialog. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3342 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | * @param id The id of the managed dialog. |
| 3344 | * @param dialog The dialog. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3345 | * @param args The dialog arguments provided to {@link #showDialog(int, Bundle)}. |
| 3346 | * @see #onCreateDialog(int, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3347 | * @see #showDialog(int) |
| 3348 | * @see #dismissDialog(int) |
| 3349 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3350 | * |
| 3351 | * @deprecated Use the new {@link DialogFragment} class with |
| 3352 | * {@link FragmentManager} instead; this is also |
| 3353 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3354 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 3355 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3356 | protected void onPrepareDialog(int id, Dialog dialog, Bundle args) { |
| 3357 | onPrepareDialog(id, dialog); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3361 | * Simple version of {@link #showDialog(int, Bundle)} that does not |
| 3362 | * take any arguments. Simply calls {@link #showDialog(int, Bundle)} |
| 3363 | * with null arguments. |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3364 | * |
| 3365 | * @deprecated Use the new {@link DialogFragment} class with |
| 3366 | * {@link FragmentManager} instead; this is also |
| 3367 | * available on older platforms through the Android compatibility package. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3368 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 3369 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3370 | public final void showDialog(int id) { |
| 3371 | showDialog(id, null); |
| 3372 | } |
| 3373 | |
| 3374 | /** |
| 3375 | * 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] | 3376 | * will be made with the same id the first time this is called for a given |
| 3377 | * id. From thereafter, the dialog will be automatically saved and restored. |
| 3378 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 3379 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 3380 | * or later, consider instead using a {@link DialogFragment} instead.</em> |
| 3381 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3382 | * <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] | 3383 | * be made to provide an opportunity to do any timely preparation. |
| 3384 | * |
| 3385 | * @param id The id of the managed dialog. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3386 | * @param args Arguments to pass through to the dialog. These will be saved |
| 3387 | * and restored for you. Note that if the dialog is already created, |
| 3388 | * {@link #onCreateDialog(int, Bundle)} will not be called with the new |
| 3389 | * arguments but {@link #onPrepareDialog(int, Dialog, Bundle)} will be. |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 3390 | * If you need to rebuild the dialog, call {@link #removeDialog(int)} first. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3391 | * @return Returns true if the Dialog was created; false is returned if |
| 3392 | * it is not created because {@link #onCreateDialog(int, Bundle)} returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3393 | * |
Joe Onorato | 37296dc | 2009-07-31 17:58:55 -0700 | [diff] [blame] | 3394 | * @see Dialog |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3395 | * @see #onCreateDialog(int, Bundle) |
| 3396 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3397 | * @see #dismissDialog(int) |
| 3398 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3399 | * |
| 3400 | * @deprecated Use the new {@link DialogFragment} class with |
| 3401 | * {@link FragmentManager} instead; this is also |
| 3402 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3403 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3404 | @Nullable |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 3405 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3406 | public final boolean showDialog(int id, Bundle args) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3407 | if (mManagedDialogs == null) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3408 | mManagedDialogs = new SparseArray<ManagedDialog>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3409 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3410 | ManagedDialog md = mManagedDialogs.get(id); |
| 3411 | if (md == null) { |
| 3412 | md = new ManagedDialog(); |
| 3413 | md.mDialog = createDialog(id, null, args); |
| 3414 | if (md.mDialog == null) { |
| 3415 | return false; |
| 3416 | } |
| 3417 | mManagedDialogs.put(id, md); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3418 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3419 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3420 | md.mArgs = args; |
| 3421 | onPrepareDialog(id, md.mDialog, args); |
| 3422 | md.mDialog.show(); |
| 3423 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | /** |
| 3427 | * Dismiss a dialog that was previously shown via {@link #showDialog(int)}. |
| 3428 | * |
| 3429 | * @param id The id of the managed dialog. |
| 3430 | * |
| 3431 | * @throws IllegalArgumentException if the id was not previously shown via |
| 3432 | * {@link #showDialog(int)}. |
| 3433 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3434 | * @see #onCreateDialog(int, Bundle) |
| 3435 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3436 | * @see #showDialog(int) |
| 3437 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3438 | * |
| 3439 | * @deprecated Use the new {@link DialogFragment} class with |
| 3440 | * {@link FragmentManager} instead; this is also |
| 3441 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3442 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 3443 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3444 | public final void dismissDialog(int id) { |
| 3445 | if (mManagedDialogs == null) { |
| 3446 | throw missingDialog(id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3447 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3448 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3449 | final ManagedDialog md = mManagedDialogs.get(id); |
| 3450 | if (md == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3451 | throw missingDialog(id); |
| 3452 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3453 | md.mDialog.dismiss(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3454 | } |
| 3455 | |
| 3456 | /** |
| 3457 | * Creates an exception to throw if a user passed in a dialog id that is |
| 3458 | * unexpected. |
| 3459 | */ |
| 3460 | private IllegalArgumentException missingDialog(int id) { |
| 3461 | return new IllegalArgumentException("no dialog with id " + id + " was ever " |
| 3462 | + "shown via Activity#showDialog"); |
| 3463 | } |
| 3464 | |
| 3465 | /** |
| 3466 | * Removes any internal references to a dialog managed by this Activity. |
| 3467 | * If the dialog is showing, it will dismiss it as part of the clean up. |
| 3468 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3469 | * <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] | 3470 | * want to avoid the overhead of saving and restoring it in the future. |
| 3471 | * |
Dianne Hackborn | d2ce8bbb | 2010-10-06 16:46:05 -0700 | [diff] [blame] | 3472 | * <p>As of {@link android.os.Build.VERSION_CODES#GINGERBREAD}, this function |
| 3473 | * will not throw an exception if you try to remove an ID that does not |
| 3474 | * currently have an associated dialog.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3475 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3476 | * @param id The id of the managed dialog. |
| 3477 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3478 | * @see #onCreateDialog(int, Bundle) |
| 3479 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3480 | * @see #showDialog(int) |
| 3481 | * @see #dismissDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3482 | * |
| 3483 | * @deprecated Use the new {@link DialogFragment} class with |
| 3484 | * {@link FragmentManager} instead; this is also |
| 3485 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3486 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 3487 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3488 | public final void removeDialog(int id) { |
Dianne Hackborn | d2ce8bbb | 2010-10-06 16:46:05 -0700 | [diff] [blame] | 3489 | if (mManagedDialogs != null) { |
| 3490 | final ManagedDialog md = mManagedDialogs.get(id); |
| 3491 | if (md != null) { |
| 3492 | md.mDialog.dismiss(); |
| 3493 | mManagedDialogs.remove(id); |
| 3494 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3495 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3496 | } |
| 3497 | |
| 3498 | /** |
| 3499 | * 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] | 3500 | * |
Bjorn Bringert | 6266e40 | 2009-09-25 14:25:41 +0100 | [diff] [blame] | 3501 | * <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] | 3502 | * menu item, search button, or other widgets within your activity. Unless overidden, |
Bjorn Bringert | 6266e40 | 2009-09-25 14:25:41 +0100 | [diff] [blame] | 3503 | * calling this function is the same as calling |
| 3504 | * {@link #startSearch startSearch(null, false, null, false)}, which launches |
| 3505 | * search for the current activity as specified in its manifest, see {@link SearchManager}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3506 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3507 | * <p>You can override this function to force global search, e.g. in response to a dedicated |
| 3508 | * search key, or to block search entirely (by simply returning false). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3509 | * |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 3510 | * <p>Note: when running in a {@link Configuration#UI_MODE_TYPE_TELEVISION}, the default |
| 3511 | * implementation changes to simply return false and you must supply your own custom |
| 3512 | * implementation if you want to support search.</p> |
| 3513 | * |
| 3514 | * @return Returns {@code true} if search launched, and {@code false} if the activity does |
| 3515 | * not respond to search. The default implementation always returns {@code true}, except |
| 3516 | * when in {@link Configuration#UI_MODE_TYPE_TELEVISION} mode where it returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3517 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3518 | * @see android.app.SearchManager |
| 3519 | */ |
| 3520 | public boolean onSearchRequested() { |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 3521 | if ((getResources().getConfiguration().uiMode&Configuration.UI_MODE_TYPE_MASK) |
| 3522 | != Configuration.UI_MODE_TYPE_TELEVISION) { |
| 3523 | startSearch(null, false, null, false); |
| 3524 | return true; |
| 3525 | } else { |
| 3526 | return false; |
| 3527 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3528 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3530 | /** |
| 3531 | * This hook is called to launch the search UI. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3532 | * |
| 3533 | * <p>It is typically called from onSearchRequested(), either directly from |
| 3534 | * 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] | 3535 | * 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] | 3536 | * 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] | 3537 | * is to inject specific data such as context data, it is preferred to <i>override</i> |
| 3538 | * onSearchRequested(), so that any callers to it will benefit from the override. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3539 | * |
| 3540 | * @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] | 3541 | * pre-entered text in the search query box. |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3542 | * @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] | 3543 | * any further typing will replace it. This is useful for cases where an entire pre-formed |
| 3544 | * query is being inserted. If false, the selection point will be placed at the end of the |
| 3545 | * inserted query. This is useful when the inserted query is text that the user entered, |
| 3546 | * and the user would expect to be able to keep typing. <i>This parameter is only meaningful |
| 3547 | * if initialQuery is a non-empty string.</i> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3548 | * @param appSearchData An application can insert application-specific |
| 3549 | * 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] | 3550 | * searches. This data will be returned with SEARCH intent(s). Null if |
| 3551 | * no extra data is required. |
| 3552 | * @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] | 3553 | * 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] | 3554 | * 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] | 3555 | * 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] | 3556 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3557 | * @see android.app.SearchManager |
| 3558 | * @see #onSearchRequested |
| 3559 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3560 | public void startSearch(@Nullable String initialQuery, boolean selectInitialQuery, |
| 3561 | @Nullable Bundle appSearchData, boolean globalSearch) { |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 3562 | ensureSearchManager(); |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 3563 | mSearchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3564 | appSearchData, globalSearch); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | /** |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 3568 | * Similar to {@link #startSearch}, but actually fires off the search query after invoking |
| 3569 | * the search dialog. Made available for testing purposes. |
| 3570 | * |
| 3571 | * @param query The query to trigger. If empty, the request will be ignored. |
| 3572 | * @param appSearchData An application can insert application-specific |
| 3573 | * context here, in order to improve quality or specificity of its own |
| 3574 | * searches. This data will be returned with SEARCH intent(s). Null if |
| 3575 | * no extra data is required. |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 3576 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3577 | public void triggerSearch(String query, @Nullable Bundle appSearchData) { |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 3578 | ensureSearchManager(); |
Bjorn Bringert | b782a2f | 2009-10-01 09:57:33 +0100 | [diff] [blame] | 3579 | mSearchManager.triggerSearch(query, getComponentName(), appSearchData); |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
| 3582 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3583 | * Request that key events come to this activity. Use this if your |
| 3584 | * activity has no views with focus, but the activity still wants |
| 3585 | * a chance to process key events. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3586 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3587 | * @see android.view.Window#takeKeyEvents |
| 3588 | */ |
| 3589 | public void takeKeyEvents(boolean get) { |
| 3590 | getWindow().takeKeyEvents(get); |
| 3591 | } |
| 3592 | |
| 3593 | /** |
| 3594 | * Enable extended window features. This is a convenience for calling |
| 3595 | * {@link android.view.Window#requestFeature getWindow().requestFeature()}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3596 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3597 | * @param featureId The desired feature as defined in |
| 3598 | * {@link android.view.Window}. |
| 3599 | * @return Returns true if the requested feature is supported and now |
| 3600 | * enabled. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3601 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3602 | * @see android.view.Window#requestFeature |
| 3603 | */ |
| 3604 | public final boolean requestWindowFeature(int featureId) { |
| 3605 | return getWindow().requestFeature(featureId); |
| 3606 | } |
| 3607 | |
| 3608 | /** |
| 3609 | * Convenience for calling |
| 3610 | * {@link android.view.Window#setFeatureDrawableResource}. |
| 3611 | */ |
| 3612 | public final void setFeatureDrawableResource(int featureId, int resId) { |
| 3613 | getWindow().setFeatureDrawableResource(featureId, resId); |
| 3614 | } |
| 3615 | |
| 3616 | /** |
| 3617 | * Convenience for calling |
| 3618 | * {@link android.view.Window#setFeatureDrawableUri}. |
| 3619 | */ |
| 3620 | public final void setFeatureDrawableUri(int featureId, Uri uri) { |
| 3621 | getWindow().setFeatureDrawableUri(featureId, uri); |
| 3622 | } |
| 3623 | |
| 3624 | /** |
| 3625 | * Convenience for calling |
| 3626 | * {@link android.view.Window#setFeatureDrawable(int, Drawable)}. |
| 3627 | */ |
| 3628 | public final void setFeatureDrawable(int featureId, Drawable drawable) { |
| 3629 | getWindow().setFeatureDrawable(featureId, drawable); |
| 3630 | } |
| 3631 | |
| 3632 | /** |
| 3633 | * Convenience for calling |
| 3634 | * {@link android.view.Window#setFeatureDrawableAlpha}. |
| 3635 | */ |
| 3636 | public final void setFeatureDrawableAlpha(int featureId, int alpha) { |
| 3637 | getWindow().setFeatureDrawableAlpha(featureId, alpha); |
| 3638 | } |
| 3639 | |
| 3640 | /** |
| 3641 | * Convenience for calling |
| 3642 | * {@link android.view.Window#getLayoutInflater}. |
| 3643 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3644 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3645 | public LayoutInflater getLayoutInflater() { |
| 3646 | return getWindow().getLayoutInflater(); |
| 3647 | } |
| 3648 | |
| 3649 | /** |
| 3650 | * Returns a {@link MenuInflater} with this context. |
| 3651 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3652 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3653 | public MenuInflater getMenuInflater() { |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 3654 | // Make sure that action views can get an appropriate theme. |
| 3655 | if (mMenuInflater == null) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3656 | initWindowDecorActionBar(); |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 3657 | if (mActionBar != null) { |
Dianne Hackborn | 9275197 | 2012-05-18 19:22:14 -0700 | [diff] [blame] | 3658 | mMenuInflater = new MenuInflater(mActionBar.getThemedContext(), this); |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 3659 | } else { |
| 3660 | mMenuInflater = new MenuInflater(this); |
| 3661 | } |
| 3662 | } |
| 3663 | return mMenuInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | @Override |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 3667 | protected void onApplyThemeResource(Resources.Theme theme, int resid, |
| 3668 | boolean first) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3669 | if (mParent == null) { |
| 3670 | super.onApplyThemeResource(theme, resid, first); |
| 3671 | } else { |
| 3672 | try { |
| 3673 | theme.setTo(mParent.getTheme()); |
| 3674 | } catch (Exception e) { |
| 3675 | // Empty |
| 3676 | } |
| 3677 | theme.applyStyle(resid, false); |
| 3678 | } |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 3679 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 3680 | // Get the primary color and update the TaskDescription for this activity |
Winson Chung | 4d1a434 | 2014-05-09 16:42:00 -0700 | [diff] [blame] | 3681 | if (theme != null) { |
| 3682 | TypedArray a = theme.obtainStyledAttributes(com.android.internal.R.styleable.Theme); |
Winson Chung | aca9602 | 2014-05-09 15:04:08 -0700 | [diff] [blame] | 3683 | int colorPrimary = a.getColor(com.android.internal.R.styleable.Theme_colorPrimary, 0); |
| 3684 | a.recycle(); |
| 3685 | if (colorPrimary != 0) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 3686 | ActivityManager.TaskDescription v = new ActivityManager.TaskDescription(null, null, |
| 3687 | colorPrimary); |
| 3688 | setTaskDescription(v); |
Winson Chung | aca9602 | 2014-05-09 15:04:08 -0700 | [diff] [blame] | 3689 | } |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 3690 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3691 | } |
| 3692 | |
| 3693 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3694 | * Same as calling {@link #startActivityForResult(Intent, int, Bundle)} |
| 3695 | * with no options. |
| 3696 | * |
| 3697 | * @param intent The intent to start. |
| 3698 | * @param requestCode If >= 0, this code will be returned in |
| 3699 | * onActivityResult() when the activity exits. |
| 3700 | * |
| 3701 | * @throws android.content.ActivityNotFoundException |
| 3702 | * |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 3703 | * @see #startActivity |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3704 | */ |
| 3705 | public void startActivityForResult(Intent intent, int requestCode) { |
George Mount | abb63cb | 2014-06-23 11:17:58 -0700 | [diff] [blame] | 3706 | startActivityForResult(intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
| 3709 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | * Launch an activity for which you would like a result when it finished. |
| 3711 | * When this activity exits, your |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 3712 | * onActivityResult() method will be called with the given requestCode. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3713 | * Using a negative requestCode is the same as calling |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3714 | * {@link #startActivity} (the activity is not launched as a sub-activity). |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3715 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3716 | * <p>Note that this method should only be used with Intent protocols |
| 3717 | * that are defined to return a result. In other protocols (such as |
| 3718 | * {@link Intent#ACTION_MAIN} or {@link Intent#ACTION_VIEW}), you may |
| 3719 | * not get the result when you expect. For example, if the activity you |
| 3720 | * are launching uses the singleTask launch mode, it will not run in your |
| 3721 | * task and thus you will immediately receive a cancel result. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3722 | * |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3723 | * <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] | 3724 | * >= 0 during the initial onCreate(Bundle savedInstanceState)/onResume() of your |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 3725 | * activity, then your window will not be displayed until a result is |
| 3726 | * returned back from the started activity. This is to avoid visible |
| 3727 | * flickering when redirecting to another activity. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3728 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3729 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 3730 | * if there was no Activity found to run the given Intent. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3731 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3732 | * @param intent The intent to start. |
| 3733 | * @param requestCode If >= 0, this code will be returned in |
| 3734 | * onActivityResult() when the activity exits. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3735 | * @param options Additional options for how the Activity should be started. |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 3736 | * See {@link android.content.Context#startActivity(Intent, Bundle) |
| 3737 | * Context.startActivity(Intent, Bundle)} for more details. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3738 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3739 | * @throws android.content.ActivityNotFoundException |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3740 | * |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 3741 | * @see #startActivity |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3742 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3743 | public void startActivityForResult(Intent intent, int requestCode, @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3744 | if (mParent == null) { |
| 3745 | Instrumentation.ActivityResult ar = |
| 3746 | mInstrumentation.execStartActivity( |
| 3747 | this, mMainThread.getApplicationThread(), mToken, this, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3748 | intent, requestCode, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3749 | if (ar != null) { |
| 3750 | mMainThread.sendActivityResult( |
| 3751 | mToken, mEmbeddedID, requestCode, ar.getResultCode(), |
| 3752 | ar.getResultData()); |
| 3753 | } |
| 3754 | if (requestCode >= 0) { |
| 3755 | // If this start is requesting a result, we can avoid making |
| 3756 | // the activity visible until the result is received. Setting |
| 3757 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 3758 | // activity hidden during this time, to avoid flickering. |
| 3759 | // This can only be done when a result is requested because |
| 3760 | // that guarantees we will get information back when the |
| 3761 | // activity is finished, no matter what happens to it. |
| 3762 | mStartedActivity = true; |
| 3763 | } |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 3764 | |
| 3765 | final View decor = mWindow != null ? mWindow.peekDecorView() : null; |
| 3766 | if (decor != null) { |
| 3767 | decor.cancelPendingInputEvents(); |
| 3768 | } |
| 3769 | // 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] | 3770 | } else { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3771 | if (options != null) { |
| 3772 | mParent.startActivityFromChild(this, intent, requestCode, options); |
| 3773 | } else { |
| 3774 | // Note we want to go through this method for compatibility with |
| 3775 | // existing applications that may have overridden it. |
| 3776 | mParent.startActivityFromChild(this, intent, requestCode); |
| 3777 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3778 | } |
George Mount | ff24328 | 2014-07-07 16:12:07 -0700 | [diff] [blame] | 3779 | if (options != null && !isTopOfTask()) { |
| 3780 | mActivityTransitionState.startExitOutTransition(this, options); |
| 3781 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | /** |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 3785 | * @hide Implement to provide correct calling token. |
| 3786 | */ |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 3787 | public void startActivityForResultAsUser(Intent intent, int requestCode, UserHandle user) { |
| 3788 | startActivityForResultAsUser(intent, requestCode, null, user); |
| 3789 | } |
| 3790 | |
| 3791 | /** |
| 3792 | * @hide Implement to provide correct calling token. |
| 3793 | */ |
| 3794 | public void startActivityForResultAsUser(Intent intent, int requestCode, |
| 3795 | @Nullable Bundle options, UserHandle user) { |
| 3796 | if (options != null) { |
| 3797 | mActivityTransitionState.startExitOutTransition(this, options); |
| 3798 | } |
| 3799 | if (mParent != null) { |
| 3800 | throw new RuntimeException("Can't be called from a child"); |
| 3801 | } |
| 3802 | Instrumentation.ActivityResult ar = mInstrumentation.execStartActivity( |
| 3803 | this, mMainThread.getApplicationThread(), mToken, this, intent, requestCode, |
| 3804 | options, user); |
| 3805 | if (ar != null) { |
| 3806 | mMainThread.sendActivityResult( |
| 3807 | mToken, mEmbeddedID, requestCode, ar.getResultCode(), ar.getResultData()); |
| 3808 | } |
| 3809 | if (requestCode >= 0) { |
| 3810 | // If this start is requesting a result, we can avoid making |
| 3811 | // the activity visible until the result is received. Setting |
| 3812 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 3813 | // activity hidden during this time, to avoid flickering. |
| 3814 | // This can only be done when a result is requested because |
| 3815 | // that guarantees we will get information back when the |
| 3816 | // activity is finished, no matter what happens to it. |
| 3817 | mStartedActivity = true; |
| 3818 | } |
| 3819 | |
| 3820 | final View decor = mWindow != null ? mWindow.peekDecorView() : null; |
| 3821 | if (decor != null) { |
| 3822 | decor.cancelPendingInputEvents(); |
| 3823 | } |
| 3824 | } |
| 3825 | |
| 3826 | /** |
| 3827 | * @hide Implement to provide correct calling token. |
| 3828 | */ |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 3829 | public void startActivityAsUser(Intent intent, UserHandle user) { |
| 3830 | startActivityAsUser(intent, null, user); |
| 3831 | } |
| 3832 | |
| 3833 | /** |
| 3834 | * @hide Implement to provide correct calling token. |
| 3835 | */ |
| 3836 | public void startActivityAsUser(Intent intent, Bundle options, UserHandle user) { |
| 3837 | if (mParent != null) { |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 3838 | throw new RuntimeException("Can't be called from a child"); |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 3839 | } |
| 3840 | Instrumentation.ActivityResult ar = |
| 3841 | mInstrumentation.execStartActivity( |
| 3842 | this, mMainThread.getApplicationThread(), mToken, this, |
| 3843 | intent, -1, options, user); |
| 3844 | if (ar != null) { |
| 3845 | mMainThread.sendActivityResult( |
| 3846 | mToken, mEmbeddedID, -1, ar.getResultCode(), |
| 3847 | ar.getResultData()); |
| 3848 | } |
| 3849 | } |
| 3850 | |
| 3851 | /** |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 3852 | * Start a new activity as if it was started by the activity that started our |
| 3853 | * current activity. This is for the resolver and chooser activities, which operate |
| 3854 | * as intermediaries that dispatch their intent to the target the user selects -- to |
| 3855 | * do this, they must perform all security checks including permission grants as if |
| 3856 | * their launch had come from the original activity. |
| 3857 | * @hide |
| 3858 | */ |
Jeff Sharkey | 9797880 | 2014-10-14 10:48:18 -0700 | [diff] [blame] | 3859 | public void startActivityAsCaller(Intent intent, @Nullable Bundle options, int userId) { |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 3860 | if (mParent != null) { |
| 3861 | throw new RuntimeException("Can't be called from a child"); |
| 3862 | } |
| 3863 | Instrumentation.ActivityResult ar = |
| 3864 | mInstrumentation.execStartActivityAsCaller( |
| 3865 | this, mMainThread.getApplicationThread(), mToken, this, |
Jeff Sharkey | 9797880 | 2014-10-14 10:48:18 -0700 | [diff] [blame] | 3866 | intent, -1, options, userId); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 3867 | if (ar != null) { |
| 3868 | mMainThread.sendActivityResult( |
| 3869 | mToken, mEmbeddedID, -1, ar.getResultCode(), |
| 3870 | ar.getResultData()); |
| 3871 | } |
| 3872 | } |
| 3873 | |
| 3874 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3875 | * Same as calling {@link #startIntentSenderForResult(IntentSender, int, |
| 3876 | * Intent, int, int, int, Bundle)} with no options. |
| 3877 | * |
| 3878 | * @param intent The IntentSender to launch. |
| 3879 | * @param requestCode If >= 0, this code will be returned in |
| 3880 | * onActivityResult() when the activity exits. |
| 3881 | * @param fillInIntent If non-null, this will be provided as the |
| 3882 | * intent parameter to {@link IntentSender#sendIntent}. |
| 3883 | * @param flagsMask Intent flags in the original IntentSender that you |
| 3884 | * would like to change. |
| 3885 | * @param flagsValues Desired values for any bits set in |
| 3886 | * <var>flagsMask</var> |
| 3887 | * @param extraFlags Always set to 0. |
| 3888 | */ |
| 3889 | public void startIntentSenderForResult(IntentSender intent, int requestCode, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3890 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3891 | throws IntentSender.SendIntentException { |
| 3892 | startIntentSenderForResult(intent, requestCode, fillInIntent, flagsMask, |
| 3893 | flagsValues, extraFlags, null); |
| 3894 | } |
| 3895 | |
| 3896 | /** |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 3897 | * Like {@link #startActivityForResult(Intent, int)}, but allowing you |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 3898 | * to use a IntentSender to describe the activity to be started. If |
| 3899 | * the IntentSender is for an activity, that activity will be started |
| 3900 | * as if you had called the regular {@link #startActivityForResult(Intent, int)} |
| 3901 | * here; otherwise, its associated action will be executed (such as |
| 3902 | * sending a broadcast) as if you had called |
| 3903 | * {@link IntentSender#sendIntent IntentSender.sendIntent} on it. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3904 | * |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 3905 | * @param intent The IntentSender to launch. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 3906 | * @param requestCode If >= 0, this code will be returned in |
| 3907 | * onActivityResult() when the activity exits. |
| 3908 | * @param fillInIntent If non-null, this will be provided as the |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 3909 | * intent parameter to {@link IntentSender#sendIntent}. |
| 3910 | * @param flagsMask Intent flags in the original IntentSender that you |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 3911 | * would like to change. |
| 3912 | * @param flagsValues Desired values for any bits set in |
| 3913 | * <var>flagsMask</var> |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 3914 | * @param extraFlags Always set to 0. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3915 | * @param options Additional options for how the Activity should be started. |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 3916 | * See {@link android.content.Context#startActivity(Intent, Bundle) |
| 3917 | * Context.startActivity(Intent, Bundle)} for more details. If options |
| 3918 | * have also been supplied by the IntentSender, options given here will |
| 3919 | * override any that conflict with those given by the IntentSender. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 3920 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 3921 | public void startIntentSenderForResult(IntentSender intent, int requestCode, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3922 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3923 | Bundle options) throws IntentSender.SendIntentException { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 3924 | if (mParent == null) { |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 3925 | startIntentSenderForResultInner(intent, requestCode, fillInIntent, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3926 | flagsMask, flagsValues, this, options); |
| 3927 | } else if (options != null) { |
| 3928 | mParent.startIntentSenderFromChild(this, intent, requestCode, |
| 3929 | fillInIntent, flagsMask, flagsValues, extraFlags, options); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 3930 | } else { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3931 | // Note we want to go through this call for compatibility with |
| 3932 | // existing applications that may have overridden the method. |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 3933 | mParent.startIntentSenderFromChild(this, intent, requestCode, |
| 3934 | fillInIntent, flagsMask, flagsValues, extraFlags); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 3935 | } |
| 3936 | } |
| 3937 | |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 3938 | private void startIntentSenderForResultInner(IntentSender intent, int requestCode, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3939 | Intent fillInIntent, int flagsMask, int flagsValues, Activity activity, |
| 3940 | Bundle options) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 3941 | throws IntentSender.SendIntentException { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 3942 | try { |
| 3943 | String resolvedType = null; |
| 3944 | if (fillInIntent != null) { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 3945 | fillInIntent.migrateExtraStreamToClipData(); |
| 3946 | fillInIntent.prepareToLeaveProcess(); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 3947 | resolvedType = fillInIntent.resolveTypeIfNeeded(getContentResolver()); |
| 3948 | } |
| 3949 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 3950 | .startActivityIntentSender(mMainThread.getApplicationThread(), intent, |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 3951 | fillInIntent, resolvedType, mToken, activity.mEmbeddedID, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3952 | requestCode, flagsMask, flagsValues, options); |
| 3953 | if (result == ActivityManager.START_CANCELED) { |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 3954 | throw new IntentSender.SendIntentException(); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 3955 | } |
| 3956 | Instrumentation.checkStartActivityResult(result, null); |
| 3957 | } catch (RemoteException e) { |
| 3958 | } |
| 3959 | if (requestCode >= 0) { |
| 3960 | // If this start is requesting a result, we can avoid making |
| 3961 | // the activity visible until the result is received. Setting |
| 3962 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 3963 | // activity hidden during this time, to avoid flickering. |
| 3964 | // This can only be done when a result is requested because |
| 3965 | // that guarantees we will get information back when the |
| 3966 | // activity is finished, no matter what happens to it. |
| 3967 | mStartedActivity = true; |
| 3968 | } |
| 3969 | } |
| 3970 | |
| 3971 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3972 | * Same as {@link #startActivity(Intent, Bundle)} with no options |
| 3973 | * specified. |
| 3974 | * |
| 3975 | * @param intent The intent to start. |
| 3976 | * |
| 3977 | * @throws android.content.ActivityNotFoundException |
| 3978 | * |
| 3979 | * @see {@link #startActivity(Intent, Bundle)} |
| 3980 | * @see #startActivityForResult |
| 3981 | */ |
| 3982 | @Override |
| 3983 | public void startActivity(Intent intent) { |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 3984 | this.startActivity(intent, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3985 | } |
| 3986 | |
| 3987 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3988 | * Launch a new activity. You will not receive any information about when |
| 3989 | * the activity exits. This implementation overrides the base version, |
| 3990 | * providing information about |
| 3991 | * the activity performing the launch. Because of this additional |
| 3992 | * information, the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag is not |
| 3993 | * required; if not specified, the new activity will be added to the |
| 3994 | * task of the caller. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3995 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3996 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 3997 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3998 | * |
| 3999 | * @param intent The intent to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4000 | * @param options Additional options for how the Activity should be started. |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4001 | * See {@link android.content.Context#startActivity(Intent, Bundle) |
| 4002 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4003 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4004 | * @throws android.content.ActivityNotFoundException |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4005 | * |
| 4006 | * @see {@link #startActivity(Intent)} |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4007 | * @see #startActivityForResult |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4008 | */ |
| 4009 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4010 | public void startActivity(Intent intent, @Nullable Bundle options) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4011 | if (options != null) { |
| 4012 | startActivityForResult(intent, -1, options); |
| 4013 | } else { |
| 4014 | // Note we want to go through this call for compatibility with |
| 4015 | // applications that may have overridden the method. |
| 4016 | startActivityForResult(intent, -1); |
| 4017 | } |
| 4018 | } |
| 4019 | |
| 4020 | /** |
| 4021 | * Same as {@link #startActivities(Intent[], Bundle)} with no options |
| 4022 | * specified. |
| 4023 | * |
| 4024 | * @param intents The intents to start. |
| 4025 | * |
| 4026 | * @throws android.content.ActivityNotFoundException |
| 4027 | * |
| 4028 | * @see {@link #startActivities(Intent[], Bundle)} |
| 4029 | * @see #startActivityForResult |
| 4030 | */ |
| 4031 | @Override |
| 4032 | public void startActivities(Intent[] intents) { |
| 4033 | startActivities(intents, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4034 | } |
| 4035 | |
| 4036 | /** |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4037 | * Launch a new activity. You will not receive any information about when |
| 4038 | * the activity exits. This implementation overrides the base version, |
| 4039 | * providing information about |
| 4040 | * the activity performing the launch. Because of this additional |
| 4041 | * information, the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag is not |
| 4042 | * required; if not specified, the new activity will be added to the |
| 4043 | * task of the caller. |
| 4044 | * |
| 4045 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 4046 | * if there was no Activity found to run the given Intent. |
| 4047 | * |
| 4048 | * @param intents The intents to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4049 | * @param options Additional options for how the Activity should be started. |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4050 | * See {@link android.content.Context#startActivity(Intent, Bundle) |
| 4051 | * Context.startActivity(Intent, Bundle)} for more details. |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4052 | * |
| 4053 | * @throws android.content.ActivityNotFoundException |
| 4054 | * |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4055 | * @see {@link #startActivities(Intent[])} |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4056 | * @see #startActivityForResult |
| 4057 | */ |
| 4058 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4059 | public void startActivities(Intent[] intents, @Nullable Bundle options) { |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4060 | mInstrumentation.execStartActivities(this, mMainThread.getApplicationThread(), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4061 | mToken, this, intents, options); |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4062 | } |
| 4063 | |
| 4064 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4065 | * Same as calling {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)} |
| 4066 | * with no options. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4067 | * |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4068 | * @param intent The IntentSender to launch. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4069 | * @param fillInIntent If non-null, this will be provided as the |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4070 | * intent parameter to {@link IntentSender#sendIntent}. |
| 4071 | * @param flagsMask Intent flags in the original IntentSender that you |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4072 | * would like to change. |
| 4073 | * @param flagsValues Desired values for any bits set in |
| 4074 | * <var>flagsMask</var> |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4075 | * @param extraFlags Always set to 0. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4076 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4077 | public void startIntentSender(IntentSender intent, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4078 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4079 | throws IntentSender.SendIntentException { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4080 | startIntentSender(intent, fillInIntent, flagsMask, flagsValues, |
| 4081 | extraFlags, null); |
| 4082 | } |
| 4083 | |
| 4084 | /** |
| 4085 | * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender |
| 4086 | * to start; see |
| 4087 | * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int, Bundle)} |
| 4088 | * for more information. |
| 4089 | * |
| 4090 | * @param intent The IntentSender to launch. |
| 4091 | * @param fillInIntent If non-null, this will be provided as the |
| 4092 | * intent parameter to {@link IntentSender#sendIntent}. |
| 4093 | * @param flagsMask Intent flags in the original IntentSender that you |
| 4094 | * would like to change. |
| 4095 | * @param flagsValues Desired values for any bits set in |
| 4096 | * <var>flagsMask</var> |
| 4097 | * @param extraFlags Always set to 0. |
| 4098 | * @param options Additional options for how the Activity should be started. |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4099 | * See {@link android.content.Context#startActivity(Intent, Bundle) |
| 4100 | * Context.startActivity(Intent, Bundle)} for more details. If options |
| 4101 | * have also been supplied by the IntentSender, options given here will |
| 4102 | * override any that conflict with those given by the IntentSender. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4103 | */ |
| 4104 | public void startIntentSender(IntentSender intent, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4105 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4106 | Bundle options) throws IntentSender.SendIntentException { |
| 4107 | if (options != null) { |
| 4108 | startIntentSenderForResult(intent, -1, fillInIntent, flagsMask, |
| 4109 | flagsValues, extraFlags, options); |
| 4110 | } else { |
| 4111 | // Note we want to go through this call for compatibility with |
| 4112 | // applications that may have overridden the method. |
| 4113 | startIntentSenderForResult(intent, -1, fillInIntent, flagsMask, |
| 4114 | flagsValues, extraFlags); |
| 4115 | } |
| 4116 | } |
| 4117 | |
| 4118 | /** |
| 4119 | * Same as calling {@link #startActivityIfNeeded(Intent, int, Bundle)} |
| 4120 | * with no options. |
| 4121 | * |
| 4122 | * @param intent The intent to start. |
| 4123 | * @param requestCode If >= 0, this code will be returned in |
| 4124 | * onActivityResult() when the activity exits, as described in |
| 4125 | * {@link #startActivityForResult}. |
| 4126 | * |
| 4127 | * @return If a new activity was launched then true is returned; otherwise |
| 4128 | * false is returned and you must handle the Intent yourself. |
| 4129 | * |
| 4130 | * @see #startActivity |
| 4131 | * @see #startActivityForResult |
| 4132 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4133 | public boolean startActivityIfNeeded(@NonNull Intent intent, int requestCode) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4134 | return startActivityIfNeeded(intent, requestCode, null); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4135 | } |
| 4136 | |
| 4137 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4138 | * A special variation to launch an activity only if a new activity |
| 4139 | * instance is needed to handle the given Intent. In other words, this is |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4140 | * 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] | 4141 | * using the {@link Intent#FLAG_ACTIVITY_SINGLE_TOP} flag, or |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4142 | * singleTask or singleTop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4143 | * {@link android.R.styleable#AndroidManifestActivity_launchMode launchMode}, |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4144 | * and the activity |
| 4145 | * that handles <var>intent</var> is the same as your currently running |
| 4146 | * activity, then a new instance is not needed. In this case, instead of |
| 4147 | * the normal behavior of calling {@link #onNewIntent} this function will |
| 4148 | * return and you can handle the Intent yourself. |
| 4149 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4150 | * <p>This function can only be called from a top-level activity; if it is |
| 4151 | * called from a child activity, a runtime exception will be thrown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4152 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4153 | * @param intent The intent to start. |
| 4154 | * @param requestCode If >= 0, this code will be returned in |
| 4155 | * onActivityResult() when the activity exits, as described in |
| 4156 | * {@link #startActivityForResult}. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4157 | * @param options Additional options for how the Activity should be started. |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4158 | * See {@link android.content.Context#startActivity(Intent, Bundle) |
| 4159 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4160 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4161 | * @return If a new activity was launched then true is returned; otherwise |
| 4162 | * false is returned and you must handle the Intent yourself. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4163 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4164 | * @see #startActivity |
| 4165 | * @see #startActivityForResult |
| 4166 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4167 | public boolean startActivityIfNeeded(@NonNull Intent intent, int requestCode, |
| 4168 | @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4169 | if (mParent == null) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4170 | int result = ActivityManager.START_RETURN_INTENT_TO_CALLER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4171 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 4172 | intent.migrateExtraStreamToClipData(); |
| 4173 | intent.prepareToLeaveProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4174 | result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4175 | .startActivity(mMainThread.getApplicationThread(), getBasePackageName(), |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4176 | intent, intent.resolveTypeIfNeeded(getContentResolver()), mToken, |
| 4177 | mEmbeddedID, requestCode, ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
| 4178 | null, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4179 | } catch (RemoteException e) { |
| 4180 | // Empty |
| 4181 | } |
Siva Velusamy | 92a8b22 | 2012-03-09 16:24:04 -0800 | [diff] [blame] | 4182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4183 | Instrumentation.checkStartActivityResult(result, intent); |
Siva Velusamy | 92a8b22 | 2012-03-09 16:24:04 -0800 | [diff] [blame] | 4184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | if (requestCode >= 0) { |
| 4186 | // If this start is requesting a result, we can avoid making |
| 4187 | // the activity visible until the result is received. Setting |
| 4188 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 4189 | // activity hidden during this time, to avoid flickering. |
| 4190 | // This can only be done when a result is requested because |
| 4191 | // that guarantees we will get information back when the |
| 4192 | // activity is finished, no matter what happens to it. |
| 4193 | mStartedActivity = true; |
| 4194 | } |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4195 | return result != ActivityManager.START_RETURN_INTENT_TO_CALLER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4196 | } |
| 4197 | |
| 4198 | throw new UnsupportedOperationException( |
| 4199 | "startActivityIfNeeded can only be called from a top-level activity"); |
| 4200 | } |
| 4201 | |
| 4202 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4203 | * Same as calling {@link #startNextMatchingActivity(Intent, Bundle)} with |
| 4204 | * no options. |
| 4205 | * |
| 4206 | * @param intent The intent to dispatch to the next activity. For |
| 4207 | * correct behavior, this must be the same as the Intent that started |
| 4208 | * your own activity; the only changes you can make are to the extras |
| 4209 | * inside of it. |
| 4210 | * |
| 4211 | * @return Returns a boolean indicating whether there was another Activity |
| 4212 | * to start: true if there was a next activity to start, false if there |
| 4213 | * wasn't. In general, if true is returned you will then want to call |
| 4214 | * finish() on yourself. |
| 4215 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4216 | public boolean startNextMatchingActivity(@NonNull Intent intent) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4217 | return startNextMatchingActivity(intent, null); |
| 4218 | } |
| 4219 | |
| 4220 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4221 | * Special version of starting an activity, for use when you are replacing |
| 4222 | * other activity components. You can use this to hand the Intent off |
| 4223 | * to the next Activity that can handle it. You typically call this in |
| 4224 | * {@link #onCreate} with the Intent returned by {@link #getIntent}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4225 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | * @param intent The intent to dispatch to the next activity. For |
| 4227 | * correct behavior, this must be the same as the Intent that started |
| 4228 | * your own activity; the only changes you can make are to the extras |
| 4229 | * inside of it. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4230 | * @param options Additional options for how the Activity should be started. |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4231 | * See {@link android.content.Context#startActivity(Intent, Bundle) |
| 4232 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4233 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4234 | * @return Returns a boolean indicating whether there was another Activity |
| 4235 | * to start: true if there was a next activity to start, false if there |
| 4236 | * wasn't. In general, if true is returned you will then want to call |
| 4237 | * finish() on yourself. |
| 4238 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4239 | public boolean startNextMatchingActivity(@NonNull Intent intent, @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4240 | if (mParent == null) { |
| 4241 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 4242 | intent.migrateExtraStreamToClipData(); |
| 4243 | intent.prepareToLeaveProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4244 | return ActivityManagerNative.getDefault() |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4245 | .startNextMatchingActivity(mToken, intent, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4246 | } catch (RemoteException e) { |
| 4247 | // Empty |
| 4248 | } |
| 4249 | return false; |
| 4250 | } |
| 4251 | |
| 4252 | throw new UnsupportedOperationException( |
| 4253 | "startNextMatchingActivity can only be called from a top-level activity"); |
| 4254 | } |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4255 | |
| 4256 | /** |
| 4257 | * Same as calling {@link #startActivityFromChild(Activity, Intent, int, Bundle)} |
| 4258 | * with no options. |
| 4259 | * |
| 4260 | * @param child The activity making the call. |
| 4261 | * @param intent The intent to start. |
| 4262 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 4263 | * |
| 4264 | * @throws android.content.ActivityNotFoundException |
| 4265 | * |
| 4266 | * @see #startActivity |
| 4267 | * @see #startActivityForResult |
| 4268 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4269 | public void startActivityFromChild(@NonNull Activity child, Intent intent, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4270 | int requestCode) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4271 | startActivityFromChild(child, intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4272 | } |
| 4273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4274 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4275 | * 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] | 4276 | * {@link #startActivity} or {@link #startActivityForResult} method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4277 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4278 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 4279 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4280 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4281 | * @param child The activity making the call. |
| 4282 | * @param intent The intent to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4283 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 4284 | * @param options Additional options for how the Activity should be started. |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4285 | * See {@link android.content.Context#startActivity(Intent, Bundle) |
| 4286 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4287 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4288 | * @throws android.content.ActivityNotFoundException |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4289 | * |
| 4290 | * @see #startActivity |
| 4291 | * @see #startActivityForResult |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4292 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4293 | public void startActivityFromChild(@NonNull Activity child, Intent intent, |
| 4294 | int requestCode, @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4295 | Instrumentation.ActivityResult ar = |
| 4296 | mInstrumentation.execStartActivity( |
| 4297 | this, mMainThread.getApplicationThread(), mToken, child, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4298 | intent, requestCode, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4299 | if (ar != null) { |
| 4300 | mMainThread.sendActivityResult( |
| 4301 | mToken, child.mEmbeddedID, requestCode, |
| 4302 | ar.getResultCode(), ar.getResultData()); |
| 4303 | } |
| 4304 | } |
| 4305 | |
| 4306 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4307 | * Same as calling {@link #startActivityFromFragment(Fragment, Intent, int, Bundle)} |
| 4308 | * with no options. |
| 4309 | * |
| 4310 | * @param fragment The fragment making the call. |
| 4311 | * @param intent The intent to start. |
| 4312 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 4313 | * |
| 4314 | * @throws android.content.ActivityNotFoundException |
| 4315 | * |
| 4316 | * @see Fragment#startActivity |
| 4317 | * @see Fragment#startActivityForResult |
| 4318 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4319 | public void startActivityFromFragment(@NonNull Fragment fragment, Intent intent, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4320 | int requestCode) { |
George Mount | abb63cb | 2014-06-23 11:17:58 -0700 | [diff] [blame] | 4321 | startActivityFromFragment(fragment, intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4322 | } |
| 4323 | |
| 4324 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4325 | * This is called when a Fragment in this activity calls its |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 4326 | * {@link Fragment#startActivity} or {@link Fragment#startActivityForResult} |
| 4327 | * method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4328 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 4329 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 4330 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4331 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 4332 | * @param fragment The fragment making the call. |
| 4333 | * @param intent The intent to start. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4334 | * @param requestCode Reply request code. < 0 if reply is not requested. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4335 | * @param options Additional options for how the Activity should be started. |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4336 | * See {@link android.content.Context#startActivity(Intent, Bundle) |
| 4337 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4338 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 4339 | * @throws android.content.ActivityNotFoundException |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4340 | * |
| 4341 | * @see Fragment#startActivity |
| 4342 | * @see Fragment#startActivityForResult |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 4343 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4344 | public void startActivityFromFragment(@NonNull Fragment fragment, Intent intent, |
| 4345 | int requestCode, @Nullable Bundle options) { |
George Mount | a8bd929 | 2014-05-21 10:54:17 -0700 | [diff] [blame] | 4346 | if (options != null) { |
| 4347 | mActivityTransitionState.startExitOutTransition(this, options); |
| 4348 | } |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 4349 | Instrumentation.ActivityResult ar = |
| 4350 | mInstrumentation.execStartActivity( |
| 4351 | this, mMainThread.getApplicationThread(), mToken, fragment, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4352 | intent, requestCode, options); |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 4353 | if (ar != null) { |
| 4354 | mMainThread.sendActivityResult( |
| 4355 | mToken, fragment.mWho, requestCode, |
| 4356 | ar.getResultCode(), ar.getResultData()); |
| 4357 | } |
| 4358 | } |
| 4359 | |
| 4360 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4361 | * Same as calling {@link #startIntentSenderFromChild(Activity, IntentSender, |
| 4362 | * int, Intent, int, int, int, Bundle)} with no options. |
| 4363 | */ |
| 4364 | public void startIntentSenderFromChild(Activity child, IntentSender intent, |
| 4365 | int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, |
| 4366 | int extraFlags) |
| 4367 | throws IntentSender.SendIntentException { |
| 4368 | startIntentSenderFromChild(child, intent, requestCode, fillInIntent, |
| 4369 | flagsMask, flagsValues, extraFlags, null); |
| 4370 | } |
| 4371 | |
| 4372 | /** |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4373 | * Like {@link #startActivityFromChild(Activity, Intent, int)}, but |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4374 | * taking a IntentSender; see |
Dianne Hackborn | ae22c05 | 2009-09-17 18:46:22 -0700 | [diff] [blame] | 4375 | * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int)} |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4376 | * for more information. |
| 4377 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4378 | public void startIntentSenderFromChild(Activity child, IntentSender intent, |
| 4379 | int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4380 | int extraFlags, @Nullable Bundle options) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4381 | throws IntentSender.SendIntentException { |
| 4382 | startIntentSenderForResultInner(intent, requestCode, fillInIntent, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4383 | flagsMask, flagsValues, child, options); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4384 | } |
| 4385 | |
| 4386 | /** |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4387 | * Call immediately after one of the flavors of {@link #startActivity(Intent)} |
| 4388 | * or {@link #finish} to specify an explicit transition animation to |
| 4389 | * perform next. |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4390 | * |
| 4391 | * <p>As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN} an alternative |
| 4392 | * to using this with starting activities is to supply the desired animation |
| 4393 | * information through a {@link ActivityOptions} bundle to |
| 4394 | * {@link #startActivity(Intent, Bundle) or a related function. This allows |
| 4395 | * you to specify a custom animation even when starting an activity from |
| 4396 | * outside the context of the current top activity. |
| 4397 | * |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4398 | * @param enterAnim A resource ID of the animation resource to use for |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 4399 | * the incoming activity. Use 0 for no animation. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4400 | * @param exitAnim A resource ID of the animation resource to use for |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 4401 | * the outgoing activity. Use 0 for no animation. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4402 | */ |
| 4403 | public void overridePendingTransition(int enterAnim, int exitAnim) { |
| 4404 | try { |
| 4405 | ActivityManagerNative.getDefault().overridePendingTransition( |
| 4406 | mToken, getPackageName(), enterAnim, exitAnim); |
| 4407 | } catch (RemoteException e) { |
| 4408 | } |
| 4409 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4410 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4411 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4412 | * Call this to set the result that your activity will return to its |
| 4413 | * caller. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4414 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4415 | * @param resultCode The result code to propagate back to the originating |
| 4416 | * activity, often RESULT_CANCELED or RESULT_OK |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4417 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4418 | * @see #RESULT_CANCELED |
| 4419 | * @see #RESULT_OK |
| 4420 | * @see #RESULT_FIRST_USER |
| 4421 | * @see #setResult(int, Intent) |
| 4422 | */ |
| 4423 | public final void setResult(int resultCode) { |
| 4424 | synchronized (this) { |
| 4425 | mResultCode = resultCode; |
| 4426 | mResultData = null; |
| 4427 | } |
| 4428 | } |
| 4429 | |
| 4430 | /** |
| 4431 | * Call this to set the result that your activity will return to its |
| 4432 | * caller. |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 4433 | * |
| 4434 | * <p>As of {@link android.os.Build.VERSION_CODES#GINGERBREAD}, the Intent |
| 4435 | * you supply here can have {@link Intent#FLAG_GRANT_READ_URI_PERMISSION |
| 4436 | * Intent.FLAG_GRANT_READ_URI_PERMISSION} and/or {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 4437 | * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} set. This will grant the |
| 4438 | * Activity receiving the result access to the specific URIs in the Intent. |
| 4439 | * Access will remain until the Activity has finished (it will remain across the hosting |
| 4440 | * process being killed and other temporary destruction) and will be added |
| 4441 | * to any existing set of URI permissions it already holds. |
| 4442 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4443 | * @param resultCode The result code to propagate back to the originating |
| 4444 | * activity, often RESULT_CANCELED or RESULT_OK |
| 4445 | * @param data The data to propagate back to the originating activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4446 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4447 | * @see #RESULT_CANCELED |
| 4448 | * @see #RESULT_OK |
| 4449 | * @see #RESULT_FIRST_USER |
| 4450 | * @see #setResult(int) |
| 4451 | */ |
| 4452 | public final void setResult(int resultCode, Intent data) { |
| 4453 | synchronized (this) { |
| 4454 | mResultCode = resultCode; |
| 4455 | mResultData = data; |
| 4456 | } |
| 4457 | } |
| 4458 | |
| 4459 | /** |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4460 | * Return information about who launched this activity. If the launching Intent |
| 4461 | * contains an {@link android.content.Intent#EXTRA_REFERRER Intent.EXTRA_REFERRER}, |
| 4462 | * that will be returned as-is; otherwise, if known, an |
| 4463 | * {@link Intent#URI_ANDROID_APP_SCHEME android-app:} referrer URI containing the |
| 4464 | * package name that started the Intent will be returned. This may return null if no |
| 4465 | * referrer can be identified -- it is neither explicitly specified, nor is it known which |
| 4466 | * application package was involved. |
| 4467 | * |
| 4468 | * <p>If called while inside the handling of {@link #onNewIntent}, this function will |
| 4469 | * return the referrer that submitted that new intent to the activity. Otherwise, it |
| 4470 | * always returns the referrer of the original Intent.</p> |
| 4471 | * |
| 4472 | * <p>Note that this is <em>not</em> a security feature -- you can not trust the |
| 4473 | * referrer information, applications can spoof it.</p> |
| 4474 | */ |
| 4475 | @Nullable |
| 4476 | public Uri getReferrer() { |
| 4477 | Intent intent = getIntent(); |
| 4478 | Uri referrer = intent.getParcelableExtra(Intent.EXTRA_REFERRER); |
| 4479 | if (referrer != null) { |
| 4480 | return referrer; |
| 4481 | } |
| 4482 | String referrerName = intent.getStringExtra(Intent.EXTRA_REFERRER_NAME); |
| 4483 | if (referrerName != null) { |
| 4484 | return Uri.parse(referrerName); |
| 4485 | } |
| 4486 | if (mReferrer != null) { |
| 4487 | return new Uri.Builder().scheme("android-app").authority(mReferrer).build(); |
| 4488 | } |
| 4489 | return null; |
| 4490 | } |
| 4491 | |
| 4492 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4493 | * Return the name of the package that invoked this activity. This is who |
| 4494 | * the data in {@link #setResult setResult()} will be sent to. You can |
| 4495 | * use this information to validate that the recipient is allowed to |
| 4496 | * receive the data. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4497 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 4498 | * <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] | 4499 | * did not use the {@link #startActivityForResult} |
| 4500 | * form that includes a request code), then the calling package will be |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 4501 | * null.</p> |
| 4502 | * |
| 4503 | * <p class="note">Note: prior to {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, |
| 4504 | * the result from this method was unstable. If the process hosting the calling |
| 4505 | * package was no longer running, it would return null instead of the proper package |
| 4506 | * name. You can use {@link #getCallingActivity()} and retrieve the package name |
| 4507 | * from that instead.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4508 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4509 | * @return The package of the activity that will receive your |
| 4510 | * reply, or null if none. |
| 4511 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4512 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4513 | public String getCallingPackage() { |
| 4514 | try { |
| 4515 | return ActivityManagerNative.getDefault().getCallingPackage(mToken); |
| 4516 | } catch (RemoteException e) { |
| 4517 | return null; |
| 4518 | } |
| 4519 | } |
| 4520 | |
| 4521 | /** |
| 4522 | * Return the name of the activity that invoked this activity. This is |
| 4523 | * who the data in {@link #setResult setResult()} will be sent to. You |
| 4524 | * can use this information to validate that the recipient is allowed to |
| 4525 | * receive the data. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4526 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 4527 | * <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] | 4528 | * did not use the {@link #startActivityForResult} |
| 4529 | * form that includes a request code), then the calling package will be |
| 4530 | * null. |
| 4531 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 4532 | * @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] | 4533 | * reply, or null if none. |
| 4534 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4535 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4536 | public ComponentName getCallingActivity() { |
| 4537 | try { |
| 4538 | return ActivityManagerNative.getDefault().getCallingActivity(mToken); |
| 4539 | } catch (RemoteException e) { |
| 4540 | return null; |
| 4541 | } |
| 4542 | } |
| 4543 | |
| 4544 | /** |
| 4545 | * Control whether this activity's main window is visible. This is intended |
| 4546 | * only for the special case of an activity that is not going to show a |
| 4547 | * UI itself, but can't just finish prior to onResume() because it needs |
| 4548 | * to wait for a service binding or such. Setting this to false allows |
| 4549 | * you to prevent your UI from being shown during that time. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4550 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4551 | * <p>The default value for this is taken from the |
| 4552 | * {@link android.R.attr#windowNoDisplay} attribute of the activity's theme. |
| 4553 | */ |
| 4554 | public void setVisible(boolean visible) { |
| 4555 | if (mVisibleFromClient != visible) { |
| 4556 | mVisibleFromClient = visible; |
| 4557 | if (mVisibleFromServer) { |
| 4558 | if (visible) makeVisible(); |
| 4559 | else mDecor.setVisibility(View.INVISIBLE); |
| 4560 | } |
| 4561 | } |
| 4562 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4564 | void makeVisible() { |
| 4565 | if (!mWindowAdded) { |
| 4566 | ViewManager wm = getWindowManager(); |
| 4567 | wm.addView(mDecor, getWindow().getAttributes()); |
| 4568 | mWindowAdded = true; |
| 4569 | } |
| 4570 | mDecor.setVisibility(View.VISIBLE); |
| 4571 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4573 | /** |
| 4574 | * Check to see whether this activity is in the process of finishing, |
| 4575 | * either because you called {@link #finish} on it or someone else |
| 4576 | * has requested that it finished. This is often used in |
| 4577 | * {@link #onPause} to determine whether the activity is simply pausing or |
| 4578 | * completely finishing. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4579 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4580 | * @return If the activity is finishing, returns true; else returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4581 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4582 | * @see #finish |
| 4583 | */ |
| 4584 | public boolean isFinishing() { |
| 4585 | return mFinished; |
| 4586 | } |
| 4587 | |
| 4588 | /** |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 4589 | * Returns true if the final {@link #onDestroy()} call has been made |
| 4590 | * on the Activity, so this instance is now dead. |
| 4591 | */ |
| 4592 | public boolean isDestroyed() { |
| 4593 | return mDestroyed; |
| 4594 | } |
| 4595 | |
| 4596 | /** |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 4597 | * Check to see whether this activity is in the process of being destroyed in order to be |
| 4598 | * recreated with a new configuration. This is often used in |
| 4599 | * {@link #onStop} to determine whether the state needs to be cleaned up or will be passed |
| 4600 | * on to the next instance of the activity via {@link #onRetainNonConfigurationInstance()}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4601 | * |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 4602 | * @return If the activity is being torn down in order to be recreated with a new configuration, |
| 4603 | * returns true; else returns false. |
| 4604 | */ |
| 4605 | public boolean isChangingConfigurations() { |
| 4606 | return mChangingConfigurations; |
| 4607 | } |
| 4608 | |
| 4609 | /** |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4610 | * Cause this Activity to be recreated with a new instance. This results |
| 4611 | * in essentially the same flow as when the Activity is created due to |
| 4612 | * a configuration change -- the current instance will go through its |
| 4613 | * lifecycle to {@link #onDestroy} and a new instance then created after it. |
| 4614 | */ |
| 4615 | public void recreate() { |
| 4616 | if (mParent != null) { |
| 4617 | throw new IllegalStateException("Can only be called on top-level activity"); |
| 4618 | } |
| 4619 | if (Looper.myLooper() != mMainThread.getLooper()) { |
| 4620 | throw new IllegalStateException("Must be called from main thread"); |
| 4621 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4622 | mMainThread.requestRelaunchActivity(mToken, null, null, 0, false, null, null, false); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4623 | } |
| 4624 | |
| 4625 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 4626 | * Finishes the current activity and specifies whether to remove the task associated with this |
| 4627 | * activity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4628 | */ |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 4629 | private void finish(boolean finishTask) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4630 | if (mParent == null) { |
| 4631 | int resultCode; |
| 4632 | Intent resultData; |
| 4633 | synchronized (this) { |
| 4634 | resultCode = mResultCode; |
| 4635 | resultData = mResultData; |
| 4636 | } |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 4637 | if (false) Log.v(TAG, "Finishing self: token=" + mToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4638 | try { |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 4639 | if (resultData != null) { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 4640 | resultData.prepareToLeaveProcess(); |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 4641 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4642 | if (ActivityManagerNative.getDefault() |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 4643 | .finishActivity(mToken, resultCode, resultData, finishTask)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4644 | mFinished = true; |
| 4645 | } |
| 4646 | } catch (RemoteException e) { |
| 4647 | // Empty |
| 4648 | } |
| 4649 | } else { |
| 4650 | mParent.finishFromChild(this); |
| 4651 | } |
| 4652 | } |
| 4653 | |
| 4654 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 4655 | * Call this when your activity is done and should be closed. The |
| 4656 | * ActivityResult is propagated back to whoever launched you via |
| 4657 | * onActivityResult(). |
| 4658 | */ |
| 4659 | public void finish() { |
| 4660 | finish(false); |
| 4661 | } |
| 4662 | |
| 4663 | /** |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 4664 | * Finish this activity as well as all activities immediately below it |
| 4665 | * in the current task that have the same affinity. This is typically |
| 4666 | * used when an application can be launched on to another task (such as |
| 4667 | * from an ACTION_VIEW of a content type it understands) and the user |
| 4668 | * has used the up navigation to switch out of the current task and in |
| 4669 | * to its own task. In this case, if the user has navigated down into |
| 4670 | * any other activities of the second application, all of those should |
| 4671 | * be removed from the original task as part of the task switch. |
| 4672 | * |
| 4673 | * <p>Note that this finish does <em>not</em> allow you to deliver results |
| 4674 | * to the previous activity, and an exception will be thrown if you are trying |
| 4675 | * to do so.</p> |
| 4676 | */ |
| 4677 | public void finishAffinity() { |
| 4678 | if (mParent != null) { |
| 4679 | throw new IllegalStateException("Can not be called from an embedded activity"); |
| 4680 | } |
| 4681 | if (mResultCode != RESULT_CANCELED || mResultData != null) { |
| 4682 | throw new IllegalStateException("Can not be called to deliver a result"); |
| 4683 | } |
| 4684 | try { |
| 4685 | if (ActivityManagerNative.getDefault().finishActivityAffinity(mToken)) { |
| 4686 | mFinished = true; |
| 4687 | } |
| 4688 | } catch (RemoteException e) { |
| 4689 | // Empty |
| 4690 | } |
| 4691 | } |
| 4692 | |
| 4693 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4694 | * 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] | 4695 | * {@link #finish} method. The default implementation simply calls |
| 4696 | * finish() on this activity (the parent), finishing the entire group. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4697 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4698 | * @param child The activity making the call. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4699 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4700 | * @see #finish |
| 4701 | */ |
| 4702 | public void finishFromChild(Activity child) { |
| 4703 | finish(); |
| 4704 | } |
| 4705 | |
| 4706 | /** |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 4707 | * Reverses the Activity Scene entry Transition and triggers the calling Activity |
| 4708 | * to reverse its exit Transition. When the exit Transition completes, |
| 4709 | * {@link #finish()} is called. If no entry Transition was used, finish() is called |
| 4710 | * immediately and the Activity exit Transition is run. |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 4711 | * @see android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, android.util.Pair[]) |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 4712 | */ |
Craig Mautner | 73f843d | 2014-05-19 09:42:28 -0700 | [diff] [blame] | 4713 | public void finishAfterTransition() { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 4714 | if (!mActivityTransitionState.startExitBackTransition(this)) { |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 4715 | finish(); |
| 4716 | } |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 4717 | } |
| 4718 | |
| 4719 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4720 | * Force finish another activity that you had previously started with |
| 4721 | * {@link #startActivityForResult}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4722 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4723 | * @param requestCode The request code of the activity that you had |
| 4724 | * given to startActivityForResult(). If there are multiple |
| 4725 | * activities started with this request code, they |
| 4726 | * will all be finished. |
| 4727 | */ |
| 4728 | public void finishActivity(int requestCode) { |
| 4729 | if (mParent == null) { |
| 4730 | try { |
| 4731 | ActivityManagerNative.getDefault() |
| 4732 | .finishSubActivity(mToken, mEmbeddedID, requestCode); |
| 4733 | } catch (RemoteException e) { |
| 4734 | // Empty |
| 4735 | } |
| 4736 | } else { |
| 4737 | mParent.finishActivityFromChild(this, requestCode); |
| 4738 | } |
| 4739 | } |
| 4740 | |
| 4741 | /** |
| 4742 | * This is called when a child activity of this one calls its |
| 4743 | * finishActivity(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4744 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4745 | * @param child The activity making the call. |
| 4746 | * @param requestCode Request code that had been used to start the |
| 4747 | * activity. |
| 4748 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4749 | public void finishActivityFromChild(@NonNull Activity child, int requestCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4750 | try { |
| 4751 | ActivityManagerNative.getDefault() |
| 4752 | .finishSubActivity(mToken, child.mEmbeddedID, requestCode); |
| 4753 | } catch (RemoteException e) { |
| 4754 | // Empty |
| 4755 | } |
| 4756 | } |
| 4757 | |
| 4758 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 4759 | * Call this when your activity is done and should be closed and the task should be completely |
| 4760 | * removed as a part of finishing the Activity. |
| 4761 | */ |
| 4762 | public void finishAndRemoveTask() { |
| 4763 | finish(true); |
| 4764 | } |
| 4765 | |
| 4766 | /** |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4767 | * Ask that the local app instance of this activity be released to free up its memory. |
| 4768 | * This is asking for the activity to be destroyed, but does <b>not</b> finish the activity -- |
| 4769 | * a new instance of the activity will later be re-created if needed due to the user |
| 4770 | * navigating back to it. |
| 4771 | * |
| 4772 | * @return Returns true if the activity was in a state that it has started the process |
| 4773 | * of destroying its current instance; returns false if for any reason this could not |
| 4774 | * be done: it is currently visible to the user, it is already being destroyed, it is |
| 4775 | * being finished, it hasn't yet saved its state, etc. |
| 4776 | */ |
| 4777 | public boolean releaseInstance() { |
| 4778 | try { |
| 4779 | return ActivityManagerNative.getDefault().releaseActivityInstance(mToken); |
| 4780 | } catch (RemoteException e) { |
| 4781 | // Empty |
| 4782 | } |
| 4783 | return false; |
| 4784 | } |
| 4785 | |
| 4786 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4787 | * Called when an activity you launched exits, giving you the requestCode |
| 4788 | * you started it with, the resultCode it returned, and any additional |
| 4789 | * data from it. The <var>resultCode</var> will be |
| 4790 | * {@link #RESULT_CANCELED} if the activity explicitly returned that, |
| 4791 | * didn't return any result, or crashed during its operation. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4792 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4793 | * <p>You will receive this call immediately before onResume() when your |
| 4794 | * activity is re-starting. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4795 | * |
Ricardo Cervera | 92f6a74 | 2014-04-04 11:17:06 -0700 | [diff] [blame] | 4796 | * <p>This method is never invoked if your activity sets |
| 4797 | * {@link android.R.styleable#AndroidManifestActivity_noHistory noHistory} to |
| 4798 | * <code>true</code>. |
Ricardo Cervera | 93f94c2 | 2015-01-16 09:54:30 -0800 | [diff] [blame] | 4799 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4800 | * @param requestCode The integer request code originally supplied to |
| 4801 | * startActivityForResult(), allowing you to identify who this |
| 4802 | * result came from. |
| 4803 | * @param resultCode The integer result code returned by the child activity |
| 4804 | * through its setResult(). |
| 4805 | * @param data An Intent, which can return result data to the caller |
| 4806 | * (various data can be attached to Intent "extras"). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4807 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4808 | * @see #startActivityForResult |
| 4809 | * @see #createPendingResult |
| 4810 | * @see #setResult(int) |
| 4811 | */ |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 4812 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4813 | } |
| 4814 | |
| 4815 | /** |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 4816 | * Called when an activity you launched with an activity transition exposes this |
| 4817 | * Activity through a returning activity transition, giving you the resultCode |
| 4818 | * and any additional data from it. This method will only be called if the activity |
| 4819 | * 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] | 4820 | * transitions with {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 4821 | * |
| 4822 | * <p>The purpose of this function is to let the called Activity send a hint about |
| 4823 | * its state so that this underlying Activity can prepare to be exposed. A call to |
| 4824 | * this method does not guarantee that the called Activity has or will be exiting soon. |
| 4825 | * It only indicates that it will expose this Activity's Window and it has |
| 4826 | * some data to pass to prepare it.</p> |
| 4827 | * |
| 4828 | * @param resultCode The integer result code returned by the child activity |
| 4829 | * through its setResult(). |
| 4830 | * @param data An Intent, which can return result data to the caller |
| 4831 | * (various data can be attached to Intent "extras"). |
| 4832 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 4833 | public void onActivityReenter(int resultCode, Intent data) { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4837 | * Create a new PendingIntent object which you can hand to others |
| 4838 | * for them to use to send result data back to your |
| 4839 | * {@link #onActivityResult} callback. The created object will be either |
| 4840 | * one-shot (becoming invalid after a result is sent back) or multiple |
| 4841 | * (allowing any number of results to be sent through it). |
| 4842 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4843 | * @param requestCode Private request code for the sender that will be |
| 4844 | * associated with the result data when it is returned. The sender can not |
| 4845 | * modify this value, allowing you to identify incoming results. |
| 4846 | * @param data Default data to supply in the result, which may be modified |
| 4847 | * by the sender. |
| 4848 | * @param flags May be {@link PendingIntent#FLAG_ONE_SHOT PendingIntent.FLAG_ONE_SHOT}, |
| 4849 | * {@link PendingIntent#FLAG_NO_CREATE PendingIntent.FLAG_NO_CREATE}, |
| 4850 | * {@link PendingIntent#FLAG_CANCEL_CURRENT PendingIntent.FLAG_CANCEL_CURRENT}, |
| 4851 | * {@link PendingIntent#FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT}, |
| 4852 | * or any of the flags as supported by |
| 4853 | * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts |
| 4854 | * of the intent that can be supplied when the actual send happens. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4855 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4856 | * @return Returns an existing or new PendingIntent matching the given |
| 4857 | * parameters. May return null only if |
| 4858 | * {@link PendingIntent#FLAG_NO_CREATE PendingIntent.FLAG_NO_CREATE} has been |
| 4859 | * supplied. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4860 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4861 | * @see PendingIntent |
| 4862 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4863 | public PendingIntent createPendingResult(int requestCode, @NonNull Intent data, |
| 4864 | @PendingIntent.Flags int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4865 | String packageName = getPackageName(); |
| 4866 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 4867 | data.prepareToLeaveProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4868 | IIntentSender target = |
| 4869 | ActivityManagerNative.getDefault().getIntentSender( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4870 | ActivityManager.INTENT_SENDER_ACTIVITY_RESULT, packageName, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4871 | mParent == null ? mToken : mParent.mToken, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 4872 | mEmbeddedID, requestCode, new Intent[] { data }, null, flags, null, |
| 4873 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4874 | return target != null ? new PendingIntent(target) : null; |
| 4875 | } catch (RemoteException e) { |
| 4876 | // Empty |
| 4877 | } |
| 4878 | return null; |
| 4879 | } |
| 4880 | |
| 4881 | /** |
| 4882 | * Change the desired orientation of this activity. If the activity |
| 4883 | * is currently in the foreground or otherwise impacting the screen |
| 4884 | * orientation, the screen will immediately be changed (possibly causing |
| 4885 | * the activity to be restarted). Otherwise, this will be used the next |
| 4886 | * time the activity is visible. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4887 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4888 | * @param requestedOrientation An orientation constant as used in |
| 4889 | * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}. |
| 4890 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4891 | public void setRequestedOrientation(@ActivityInfo.ScreenOrientation int requestedOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4892 | if (mParent == null) { |
| 4893 | try { |
| 4894 | ActivityManagerNative.getDefault().setRequestedOrientation( |
| 4895 | mToken, requestedOrientation); |
| 4896 | } catch (RemoteException e) { |
| 4897 | // Empty |
| 4898 | } |
| 4899 | } else { |
| 4900 | mParent.setRequestedOrientation(requestedOrientation); |
| 4901 | } |
| 4902 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4903 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4904 | /** |
| 4905 | * Return the current requested orientation of the activity. This will |
| 4906 | * either be the orientation requested in its component's manifest, or |
| 4907 | * the last requested orientation given to |
| 4908 | * {@link #setRequestedOrientation(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4909 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4910 | * @return Returns an orientation constant as used in |
| 4911 | * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}. |
| 4912 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4913 | @ActivityInfo.ScreenOrientation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4914 | public int getRequestedOrientation() { |
| 4915 | if (mParent == null) { |
| 4916 | try { |
| 4917 | return ActivityManagerNative.getDefault() |
| 4918 | .getRequestedOrientation(mToken); |
| 4919 | } catch (RemoteException e) { |
| 4920 | // Empty |
| 4921 | } |
| 4922 | } else { |
| 4923 | return mParent.getRequestedOrientation(); |
| 4924 | } |
| 4925 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 4926 | } |
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 | /** |
| 4929 | * Return the identifier of the task this activity is in. This identifier |
| 4930 | * will remain the same for the lifetime of the activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4931 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4932 | * @return Task identifier, an opaque integer. |
| 4933 | */ |
| 4934 | public int getTaskId() { |
| 4935 | try { |
| 4936 | return ActivityManagerNative.getDefault() |
| 4937 | .getTaskForActivity(mToken, false); |
| 4938 | } catch (RemoteException e) { |
| 4939 | return -1; |
| 4940 | } |
| 4941 | } |
| 4942 | |
| 4943 | /** |
| 4944 | * Return whether this activity is the root of a task. The root is the |
| 4945 | * first activity in a task. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4946 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4947 | * @return True if this is the root activity, else false. |
| 4948 | */ |
| 4949 | public boolean isTaskRoot() { |
| 4950 | try { |
| 4951 | return ActivityManagerNative.getDefault() |
| 4952 | .getTaskForActivity(mToken, true) >= 0; |
| 4953 | } catch (RemoteException e) { |
| 4954 | return false; |
| 4955 | } |
| 4956 | } |
| 4957 | |
| 4958 | /** |
| 4959 | * Move the task containing this activity to the back of the activity |
| 4960 | * stack. The activity's order within the task is unchanged. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4961 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4962 | * @param nonRoot If false then this only works if the activity is the root |
| 4963 | * of a task; if true it will work for any activity in |
| 4964 | * a task. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4965 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4966 | * @return If the task was moved (or it was already at the |
| 4967 | * back) true is returned, else false. |
| 4968 | */ |
| 4969 | public boolean moveTaskToBack(boolean nonRoot) { |
| 4970 | try { |
| 4971 | return ActivityManagerNative.getDefault().moveActivityTaskToBack( |
| 4972 | mToken, nonRoot); |
| 4973 | } catch (RemoteException e) { |
| 4974 | // Empty |
| 4975 | } |
| 4976 | return false; |
| 4977 | } |
| 4978 | |
| 4979 | /** |
| 4980 | * Returns class name for this activity with the package prefix removed. |
| 4981 | * This is the default name used to read and write settings. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4982 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4983 | * @return The local class name. |
| 4984 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4985 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4986 | public String getLocalClassName() { |
| 4987 | final String pkg = getPackageName(); |
| 4988 | final String cls = mComponent.getClassName(); |
| 4989 | int packageLen = pkg.length(); |
| 4990 | if (!cls.startsWith(pkg) || cls.length() <= packageLen |
| 4991 | || cls.charAt(packageLen) != '.') { |
| 4992 | return cls; |
| 4993 | } |
| 4994 | return cls.substring(packageLen+1); |
| 4995 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4997 | /** |
| 4998 | * Returns complete component name of this activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4999 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5000 | * @return Returns the complete component name for this activity |
| 5001 | */ |
| 5002 | public ComponentName getComponentName() |
| 5003 | { |
| 5004 | return mComponent; |
| 5005 | } |
| 5006 | |
| 5007 | /** |
| 5008 | * Retrieve a {@link SharedPreferences} object for accessing preferences |
| 5009 | * that are private to this activity. This simply calls the underlying |
| 5010 | * {@link #getSharedPreferences(String, int)} method by passing in this activity's |
| 5011 | * class name as the preferences name. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5012 | * |
| 5013 | * @param mode Operating mode. Use {@link #MODE_PRIVATE} for the default |
| 5014 | * operation, {@link #MODE_WORLD_READABLE} and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5015 | * {@link #MODE_WORLD_WRITEABLE} to control permissions. |
| 5016 | * |
| 5017 | * @return Returns the single SharedPreferences instance that can be used |
| 5018 | * to retrieve and modify the preference values. |
| 5019 | */ |
| 5020 | public SharedPreferences getPreferences(int mode) { |
| 5021 | return getSharedPreferences(getLocalClassName(), mode); |
| 5022 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5023 | |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 5024 | private void ensureSearchManager() { |
| 5025 | if (mSearchManager != null) { |
| 5026 | return; |
| 5027 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5028 | |
Amith Yamasani | e9ce3f0 | 2010-01-25 09:15:50 -0800 | [diff] [blame] | 5029 | mSearchManager = new SearchManager(this, null); |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 5030 | } |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5031 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5032 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5033 | public Object getSystemService(@ServiceName @NonNull String name) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5034 | if (getBaseContext() == null) { |
| 5035 | throw new IllegalStateException( |
| 5036 | "System services not available to Activities before onCreate()"); |
| 5037 | } |
| 5038 | |
| 5039 | if (WINDOW_SERVICE.equals(name)) { |
| 5040 | return mWindowManager; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 5041 | } else if (SEARCH_SERVICE.equals(name)) { |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 5042 | ensureSearchManager(); |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 5043 | return mSearchManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5044 | } |
| 5045 | return super.getSystemService(name); |
| 5046 | } |
| 5047 | |
| 5048 | /** |
| 5049 | * Change the title associated with this activity. If this is a |
| 5050 | * top-level activity, the title for its window will change. If it |
| 5051 | * is an embedded activity, the parent can do whatever it wants |
| 5052 | * with it. |
| 5053 | */ |
| 5054 | public void setTitle(CharSequence title) { |
| 5055 | mTitle = title; |
| 5056 | onTitleChanged(title, mTitleColor); |
| 5057 | |
| 5058 | if (mParent != null) { |
| 5059 | mParent.onChildTitleChanged(this, title); |
| 5060 | } |
| 5061 | } |
| 5062 | |
| 5063 | /** |
| 5064 | * Change the title associated with this activity. If this is a |
| 5065 | * top-level activity, the title for its window will change. If it |
| 5066 | * is an embedded activity, the parent can do whatever it wants |
| 5067 | * with it. |
| 5068 | */ |
| 5069 | public void setTitle(int titleId) { |
| 5070 | setTitle(getText(titleId)); |
| 5071 | } |
| 5072 | |
Alan Viverette | 2525d9c | 2013-11-15 14:42:19 -0800 | [diff] [blame] | 5073 | /** |
| 5074 | * Change the color of the title associated with this activity. |
| 5075 | * <p> |
| 5076 | * This method is deprecated starting in API Level 11 and replaced by action |
| 5077 | * bar styles. For information on styling the Action Bar, read the <a |
| 5078 | * href="{@docRoot} guide/topics/ui/actionbar.html">Action Bar</a> developer |
| 5079 | * guide. |
| 5080 | * |
| 5081 | * @deprecated Use action bar styles instead. |
| 5082 | */ |
| 5083 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5084 | public void setTitleColor(int textColor) { |
| 5085 | mTitleColor = textColor; |
| 5086 | onTitleChanged(mTitle, textColor); |
| 5087 | } |
| 5088 | |
| 5089 | public final CharSequence getTitle() { |
| 5090 | return mTitle; |
| 5091 | } |
| 5092 | |
| 5093 | public final int getTitleColor() { |
| 5094 | return mTitleColor; |
| 5095 | } |
| 5096 | |
| 5097 | protected void onTitleChanged(CharSequence title, int color) { |
| 5098 | if (mTitleReady) { |
| 5099 | final Window win = getWindow(); |
| 5100 | if (win != null) { |
| 5101 | win.setTitle(title); |
| 5102 | if (color != 0) { |
| 5103 | win.setTitleColor(color); |
| 5104 | } |
| 5105 | } |
Adam Powell | af2d859 | 2014-08-26 18:06:40 -0700 | [diff] [blame] | 5106 | if (mActionBar != null) { |
| 5107 | mActionBar.setWindowTitle(title); |
| 5108 | } |
Adam Powell | a557fdc | 2014-08-21 18:05:53 -0700 | [diff] [blame] | 5109 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5110 | } |
| 5111 | |
| 5112 | protected void onChildTitleChanged(Activity childActivity, CharSequence title) { |
| 5113 | } |
| 5114 | |
| 5115 | /** |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 5116 | * Sets information describing the task with this activity for presentation inside the Recents |
| 5117 | * System UI. When {@link ActivityManager#getRecentTasks} is called, the activities of each task |
| 5118 | * are traversed in order from the topmost activity to the bottommost. The traversal continues |
| 5119 | * for each property until a suitable value is found. For each task the taskDescription will be |
| 5120 | * returned in {@link android.app.ActivityManager.TaskDescription}. |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 5121 | * |
| 5122 | * @see ActivityManager#getRecentTasks |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 5123 | * @see android.app.ActivityManager.TaskDescription |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 5124 | * |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 5125 | * @param taskDescription The TaskDescription properties that describe the task with this activity |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 5126 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 5127 | public void setTaskDescription(ActivityManager.TaskDescription taskDescription) { |
| 5128 | ActivityManager.TaskDescription td; |
| 5129 | // Scale the icon down to something reasonable if it is provided |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 5130 | if (taskDescription.getIconFilename() == null && taskDescription.getIcon() != null) { |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 5131 | final int size = ActivityManager.getLauncherLargeIconSizeInner(this); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 5132 | final Bitmap icon = Bitmap.createScaledBitmap(taskDescription.getIcon(), size, size, true); |
| 5133 | td = new ActivityManager.TaskDescription(taskDescription.getLabel(), icon, |
| 5134 | taskDescription.getPrimaryColor()); |
| 5135 | } else { |
| 5136 | td = taskDescription; |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 5137 | } |
| 5138 | try { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 5139 | ActivityManagerNative.getDefault().setTaskDescription(mToken, td); |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 5140 | } catch (RemoteException e) { |
| 5141 | } |
| 5142 | } |
| 5143 | |
| 5144 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5145 | * Sets the visibility of the progress bar in the title. |
| 5146 | * <p> |
| 5147 | * In order for the progress bar to be shown, the feature must be requested |
| 5148 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5149 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5150 | * @param visible Whether to show the progress bars in the title. |
| 5151 | */ |
| 5152 | public final void setProgressBarVisibility(boolean visible) { |
| 5153 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, visible ? Window.PROGRESS_VISIBILITY_ON : |
| 5154 | Window.PROGRESS_VISIBILITY_OFF); |
| 5155 | } |
| 5156 | |
| 5157 | /** |
| 5158 | * Sets the visibility of the indeterminate progress bar in the title. |
| 5159 | * <p> |
| 5160 | * In order for the progress bar to be shown, the feature must be requested |
| 5161 | * via {@link #requestWindowFeature(int)}. |
| 5162 | * |
| 5163 | * @param visible Whether to show the progress bars in the title. |
| 5164 | */ |
| 5165 | public final void setProgressBarIndeterminateVisibility(boolean visible) { |
| 5166 | getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, |
| 5167 | visible ? Window.PROGRESS_VISIBILITY_ON : Window.PROGRESS_VISIBILITY_OFF); |
| 5168 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5170 | /** |
| 5171 | * Sets whether the horizontal progress bar in the title should be indeterminate (the circular |
| 5172 | * is always indeterminate). |
| 5173 | * <p> |
| 5174 | * In order for the progress bar to be shown, the feature must be requested |
| 5175 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5176 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5177 | * @param indeterminate Whether the horizontal progress bar should be indeterminate. |
| 5178 | */ |
| 5179 | public final void setProgressBarIndeterminate(boolean indeterminate) { |
| 5180 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 5181 | indeterminate ? Window.PROGRESS_INDETERMINATE_ON |
| 5182 | : Window.PROGRESS_INDETERMINATE_OFF); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5183 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5185 | /** |
| 5186 | * Sets the progress for the progress bars in the title. |
| 5187 | * <p> |
| 5188 | * In order for the progress bar to be shown, the feature must be requested |
| 5189 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5190 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5191 | * @param progress The progress for the progress bar. Valid ranges are from |
| 5192 | * 0 to 10000 (both inclusive). If 10000 is given, the progress |
| 5193 | * bar will be completely filled and will fade out. |
| 5194 | */ |
| 5195 | public final void setProgress(int progress) { |
| 5196 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, progress + Window.PROGRESS_START); |
| 5197 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5199 | /** |
| 5200 | * Sets the secondary progress for the progress bar in the title. This |
| 5201 | * progress is drawn between the primary progress (set via |
| 5202 | * {@link #setProgress(int)} and the background. It can be ideal for media |
| 5203 | * scenarios such as showing the buffering progress while the default |
| 5204 | * progress shows the play progress. |
| 5205 | * <p> |
| 5206 | * In order for the progress bar to be shown, the feature must be requested |
| 5207 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5208 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5209 | * @param secondaryProgress The secondary progress for the progress bar. Valid ranges are from |
| 5210 | * 0 to 10000 (both inclusive). |
| 5211 | */ |
| 5212 | public final void setSecondaryProgress(int secondaryProgress) { |
| 5213 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, |
| 5214 | secondaryProgress + Window.PROGRESS_SECONDARY_START); |
| 5215 | } |
| 5216 | |
| 5217 | /** |
| 5218 | * Suggests an audio stream whose volume should be changed by the hardware |
| 5219 | * volume controls. |
| 5220 | * <p> |
| 5221 | * The suggested audio stream will be tied to the window of this Activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5222 | * Volume requests which are received while the Activity is in the |
| 5223 | * foreground will affect this stream. |
| 5224 | * <p> |
| 5225 | * It is not guaranteed that the hardware volume controls will always change |
| 5226 | * this stream's volume (for example, if a call is in progress, its stream's |
| 5227 | * volume may be changed instead). To reset back to the default, use |
| 5228 | * {@link AudioManager#USE_DEFAULT_STREAM_TYPE}. |
| 5229 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5230 | * @param streamType The type of the audio stream whose volume should be |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5231 | * changed by the hardware volume controls. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5232 | */ |
| 5233 | public final void setVolumeControlStream(int streamType) { |
| 5234 | getWindow().setVolumeControlStream(streamType); |
| 5235 | } |
| 5236 | |
| 5237 | /** |
| 5238 | * Gets the suggested audio stream whose volume should be changed by the |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5239 | * hardware volume controls. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5240 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5241 | * @return The suggested audio stream type whose volume should be changed by |
| 5242 | * the hardware volume controls. |
| 5243 | * @see #setVolumeControlStream(int) |
| 5244 | */ |
| 5245 | public final int getVolumeControlStream() { |
| 5246 | return getWindow().getVolumeControlStream(); |
| 5247 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5248 | |
| 5249 | /** |
| 5250 | * Sets a {@link MediaController} to send media keys and volume changes to. |
| 5251 | * <p> |
| 5252 | * The controller will be tied to the window of this Activity. Media key and |
| 5253 | * volume events which are received while the Activity is in the foreground |
| 5254 | * will be forwarded to the controller and used to invoke transport controls |
| 5255 | * or adjust the volume. This may be used instead of or in addition to |
| 5256 | * {@link #setVolumeControlStream} to affect a specific session instead of a |
| 5257 | * specific stream. |
| 5258 | * <p> |
| 5259 | * It is not guaranteed that the hardware volume controls will always change |
| 5260 | * this session's volume (for example, if a call is in progress, its |
| 5261 | * stream's volume may be changed instead). To reset back to the default use |
| 5262 | * null as the controller. |
| 5263 | * |
| 5264 | * @param controller The controller for the session which should receive |
| 5265 | * media keys and volume changes. |
| 5266 | */ |
| 5267 | public final void setMediaController(MediaController controller) { |
| 5268 | getWindow().setMediaController(controller); |
| 5269 | } |
| 5270 | |
| 5271 | /** |
| 5272 | * Gets the controller which should be receiving media key and volume events |
| 5273 | * while this activity is in the foreground. |
| 5274 | * |
| 5275 | * @return The controller which should receive events. |
| 5276 | * @see #setMediaController(android.media.session.MediaController) |
| 5277 | */ |
| 5278 | public final MediaController getMediaController() { |
| 5279 | return getWindow().getMediaController(); |
| 5280 | } |
| 5281 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5282 | /** |
| 5283 | * Runs the specified action on the UI thread. If the current thread is the UI |
| 5284 | * thread, then the action is executed immediately. If the current thread is |
| 5285 | * not the UI thread, the action is posted to the event queue of the UI thread. |
| 5286 | * |
| 5287 | * @param action the action to run on the UI thread |
| 5288 | */ |
| 5289 | public final void runOnUiThread(Runnable action) { |
| 5290 | if (Thread.currentThread() != mUiThread) { |
| 5291 | mHandler.post(action); |
| 5292 | } else { |
| 5293 | action.run(); |
| 5294 | } |
| 5295 | } |
| 5296 | |
| 5297 | /** |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 5298 | * Standard implementation of |
| 5299 | * {@link android.view.LayoutInflater.Factory#onCreateView} used when |
| 5300 | * inflating with the LayoutInflater returned by {@link #getSystemService}. |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 5301 | * This implementation does nothing and is for |
| 5302 | * pre-{@link android.os.Build.VERSION_CODES#HONEYCOMB} apps. Newer apps |
| 5303 | * should use {@link #onCreateView(View, String, Context, AttributeSet)}. |
| 5304 | * |
| 5305 | * @see android.view.LayoutInflater#createView |
| 5306 | * @see android.view.Window#getLayoutInflater |
| 5307 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5308 | @Nullable |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 5309 | public View onCreateView(String name, Context context, AttributeSet attrs) { |
| 5310 | return null; |
| 5311 | } |
| 5312 | |
| 5313 | /** |
| 5314 | * Standard implementation of |
| 5315 | * {@link android.view.LayoutInflater.Factory2#onCreateView(View, String, Context, AttributeSet)} |
| 5316 | * used when inflating with the LayoutInflater returned by {@link #getSystemService}. |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 5317 | * This implementation handles <fragment> tags to embed fragments inside |
| 5318 | * of the activity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5319 | * |
| 5320 | * @see android.view.LayoutInflater#createView |
| 5321 | * @see android.view.Window#getLayoutInflater |
| 5322 | */ |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 5323 | public View onCreateView(View parent, String name, Context context, AttributeSet attrs) { |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 5324 | if (!"fragment".equals(name)) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 5325 | return onCreateView(name, context, attrs); |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 5326 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5327 | |
Adam Powell | 371a809 | 2014-06-20 12:51:12 -0700 | [diff] [blame] | 5328 | return mFragments.onCreateView(parent, name, context, attrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5329 | } |
| 5330 | |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 5331 | /** |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 5332 | * 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] | 5333 | * you run "adb shell dumpsys activity <activity_component_name>". |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 5334 | * |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 5335 | * @param prefix Desired prefix to prepend at each line of output. |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 5336 | * @param fd The raw file descriptor that the dump is being sent to. |
| 5337 | * @param writer The PrintWriter to which you should dump your state. This will be |
| 5338 | * closed for you after you return. |
| 5339 | * @param args additional arguments to the dump request. |
| 5340 | */ |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 5341 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 5342 | dumpInner(prefix, fd, writer, args); |
| 5343 | } |
| 5344 | |
| 5345 | void dumpInner(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 5346 | writer.print(prefix); writer.print("Local Activity "); |
| 5347 | writer.print(Integer.toHexString(System.identityHashCode(this))); |
| 5348 | writer.println(" State:"); |
| 5349 | String innerPrefix = prefix + " "; |
| 5350 | writer.print(innerPrefix); writer.print("mResumed="); |
| 5351 | writer.print(mResumed); writer.print(" mStopped="); |
| 5352 | writer.print(mStopped); writer.print(" mFinished="); |
| 5353 | writer.println(mFinished); |
| 5354 | writer.print(innerPrefix); writer.print("mLoadersStarted="); |
| 5355 | writer.println(mLoadersStarted); |
| 5356 | writer.print(innerPrefix); writer.print("mChangingConfigurations="); |
| 5357 | writer.println(mChangingConfigurations); |
| 5358 | writer.print(innerPrefix); writer.print("mCurrentConfig="); |
| 5359 | writer.println(mCurrentConfig); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5360 | |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 5361 | if (mLoaderManager != null) { |
| 5362 | writer.print(prefix); writer.print("Loader Manager "); |
| 5363 | writer.print(Integer.toHexString(System.identityHashCode(mLoaderManager))); |
| 5364 | writer.println(":"); |
| 5365 | mLoaderManager.dump(prefix + " ", fd, writer, args); |
| 5366 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5367 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5368 | mFragments.dump(prefix, fd, writer, args); |
| 5369 | |
Michael Wright | 5f48dc7 | 2013-11-01 12:42:49 -0700 | [diff] [blame] | 5370 | if (getWindow() != null && |
| 5371 | getWindow().peekDecorView() != null && |
| 5372 | getWindow().peekDecorView().getViewRootImpl() != null) { |
| 5373 | getWindow().peekDecorView().getViewRootImpl().dump(prefix, fd, writer, args); |
| 5374 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5375 | |
| 5376 | mHandler.getLooper().dump(new PrintWriterPrinter(writer), prefix); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 5377 | } |
| 5378 | |
| 5379 | /** |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 5380 | * Bit indicating that this activity is "immersive" and should not be |
| 5381 | * interrupted by notifications if possible. |
| 5382 | * |
| 5383 | * This value is initially set by the manifest property |
| 5384 | * <code>android:immersive</code> but may be changed at runtime by |
| 5385 | * {@link #setImmersive}. |
| 5386 | * |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 5387 | * @see #setImmersive(boolean) |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 5388 | * @see android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 5389 | */ |
| 5390 | public boolean isImmersive() { |
| 5391 | try { |
| 5392 | return ActivityManagerNative.getDefault().isImmersive(mToken); |
| 5393 | } catch (RemoteException e) { |
| 5394 | return false; |
| 5395 | } |
| 5396 | } |
| 5397 | |
| 5398 | /** |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 5399 | * Indication of whether this is the highest level activity in this task. Can be used to |
| 5400 | * determine whether an activity launched by this activity was placed in the same task or |
| 5401 | * another task. |
| 5402 | * |
| 5403 | * @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] | 5404 | */ |
George Mount | ff24328 | 2014-07-07 16:12:07 -0700 | [diff] [blame] | 5405 | private boolean isTopOfTask() { |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 5406 | try { |
| 5407 | return ActivityManagerNative.getDefault().isTopOfTask(mToken); |
| 5408 | } catch (RemoteException e) { |
| 5409 | return false; |
| 5410 | } |
| 5411 | } |
| 5412 | |
| 5413 | /** |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 5414 | * Convert a translucent themed Activity {@link android.R.attr#windowIsTranslucent} to a |
| 5415 | * fullscreen opaque Activity. |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5416 | * <p> |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 5417 | * 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] | 5418 | * Doing so will allow the {@link android.view.Surface} of the Activity behind to be released. |
| 5419 | * <p> |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 5420 | * This call has no effect on non-translucent activities or on activities with the |
| 5421 | * {@link android.R.attr#windowIsFloating} attribute. |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5422 | * |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5423 | * @see #convertToTranslucent(android.app.Activity.TranslucentConversionListener, |
| 5424 | * ActivityOptions) |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5425 | * @see TranslucentConversionListener |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 5426 | * |
| 5427 | * @hide |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 5428 | */ |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5429 | @SystemApi |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5430 | public void convertFromTranslucent() { |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 5431 | try { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5432 | mTranslucentCallback = null; |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 5433 | if (ActivityManagerNative.getDefault().convertFromTranslucent(mToken)) { |
| 5434 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, true); |
| 5435 | } |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 5436 | } catch (RemoteException e) { |
| 5437 | // pass |
| 5438 | } |
| 5439 | } |
| 5440 | |
| 5441 | /** |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5442 | * Convert a translucent themed Activity {@link android.R.attr#windowIsTranslucent} back from |
| 5443 | * opaque to translucent following a call to {@link #convertFromTranslucent()}. |
| 5444 | * <p> |
| 5445 | * Calling this allows the Activity behind this one to be seen again. Once all such Activities |
| 5446 | * have been redrawn {@link TranslucentConversionListener#onTranslucentConversionComplete} will |
| 5447 | * be called indicating that it is safe to make this activity translucent again. Until |
| 5448 | * {@link TranslucentConversionListener#onTranslucentConversionComplete} is called the image |
| 5449 | * behind the frontmost Activity will be indeterminate. |
| 5450 | * <p> |
| 5451 | * This call has no effect on non-translucent activities or on activities with the |
| 5452 | * {@link android.R.attr#windowIsFloating} attribute. |
| 5453 | * |
| 5454 | * @param callback the method to call when all visible Activities behind this one have been |
| 5455 | * drawn and it is safe to make this Activity translucent again. |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 5456 | * @param options activity options delivered to the activity below this one. The options |
| 5457 | * are retrieved using {@link #getActivityOptions}. |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 5458 | * @return <code>true</code> if Window was opaque and will become translucent or |
| 5459 | * <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] | 5460 | * |
| 5461 | * @see #convertFromTranslucent() |
| 5462 | * @see TranslucentConversionListener |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 5463 | * |
| 5464 | * @hide |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5465 | */ |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5466 | @SystemApi |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 5467 | public boolean convertToTranslucent(TranslucentConversionListener callback, |
Jose Lima | 5517ea7 | 2014-06-10 12:31:43 -0700 | [diff] [blame] | 5468 | ActivityOptions options) { |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 5469 | boolean drawComplete; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5470 | try { |
| 5471 | mTranslucentCallback = callback; |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 5472 | mChangeCanvasToTranslucent = |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 5473 | ActivityManagerNative.getDefault().convertToTranslucent(mToken, options); |
George Mount | 9e18397 | 2014-09-03 12:35:09 -0700 | [diff] [blame] | 5474 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, false); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 5475 | drawComplete = true; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5476 | } catch (RemoteException e) { |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 5477 | // Make callback return as though it timed out. |
| 5478 | mChangeCanvasToTranslucent = false; |
| 5479 | drawComplete = false; |
| 5480 | } |
| 5481 | if (!mChangeCanvasToTranslucent && mTranslucentCallback != null) { |
| 5482 | // Window is already translucent. |
| 5483 | mTranslucentCallback.onTranslucentConversionComplete(drawComplete); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5484 | } |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 5485 | return mChangeCanvasToTranslucent; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5486 | } |
| 5487 | |
| 5488 | /** @hide */ |
| 5489 | void onTranslucentConversionComplete(boolean drawComplete) { |
| 5490 | if (mTranslucentCallback != null) { |
| 5491 | mTranslucentCallback.onTranslucentConversionComplete(drawComplete); |
| 5492 | mTranslucentCallback = null; |
| 5493 | } |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 5494 | if (mChangeCanvasToTranslucent) { |
| 5495 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, false); |
| 5496 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5497 | } |
| 5498 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 5499 | /** @hide */ |
| 5500 | public void onNewActivityOptions(ActivityOptions options) { |
| 5501 | mActivityTransitionState.setEnterActivityOptions(this, options); |
| 5502 | if (!mStopped) { |
| 5503 | mActivityTransitionState.enterReady(this); |
| 5504 | } |
| 5505 | } |
| 5506 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5507 | /** |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 5508 | * Retrieve the ActivityOptions passed in from the launching activity or passed back |
| 5509 | * from an activity launched by this activity in its call to {@link |
| 5510 | * #convertToTranslucent(TranslucentConversionListener, ActivityOptions)} |
| 5511 | * |
| 5512 | * @return The ActivityOptions passed to {@link #convertToTranslucent}. |
| 5513 | * @hide |
| 5514 | */ |
| 5515 | ActivityOptions getActivityOptions() { |
| 5516 | try { |
| 5517 | return ActivityManagerNative.getDefault().getActivityOptions(mToken); |
| 5518 | } catch (RemoteException e) { |
| 5519 | } |
| 5520 | return null; |
| 5521 | } |
| 5522 | |
| 5523 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5524 | * 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] | 5525 | * this method anytime between the start of {@link #onResume()} and the return from |
| 5526 | * {@link #onPause()}. If this call is successful then the activity will remain visible after |
| 5527 | * {@link #onPause()} is called, and is allowed to continue playing media in the background. |
| 5528 | * |
| 5529 | * <p>The actions of this call are reset each time that this activity is brought to the |
| 5530 | * front. That is, every time {@link #onResume()} is called the activity will be assumed |
| 5531 | * to not have requested visible behind. Therefore, if you want this activity to continue to |
| 5532 | * be visible in the background you must call this method again. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5533 | * |
| 5534 | * <p>Only fullscreen opaque activities may make this call. I.e. this call is a nop |
| 5535 | * for dialog and translucent activities. |
| 5536 | * |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 5537 | * <p>Under all circumstances, the activity must stop playing and release resources prior to or |
| 5538 | * within a call to {@link #onVisibleBehindCanceled()} or if this call returns false. |
| 5539 | * |
| 5540 | * <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] | 5541 | * the next call to onResume. |
| 5542 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5543 | * @param visible true to notify the system that the activity wishes to be visible behind other |
| 5544 | * translucent activities, false to indicate otherwise. Resources must be |
| 5545 | * released when passing false to this method. |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 5546 | * @return the resulting visibiity state. If true the activity will remain visible beyond |
| 5547 | * {@link #onPause()} if the next activity is translucent or not fullscreen. If false |
| 5548 | * then the activity may not count on being visible behind other translucent activities, |
| 5549 | * and must stop any media playback and release resources. |
| 5550 | * Returning false may occur in lieu of a call to {@link #onVisibleBehindCanceled()} so |
| 5551 | * the return value must be checked. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5552 | * |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 5553 | * @see #onVisibleBehindCanceled() |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5554 | * @see #onBackgroundVisibleBehindChanged(boolean) |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5555 | */ |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5556 | public boolean requestVisibleBehind(boolean visible) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5557 | if (!mResumed) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5558 | // Do not permit paused or stopped activities to do this. |
| 5559 | visible = false; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5560 | } |
| 5561 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5562 | mVisibleBehind = ActivityManagerNative.getDefault() |
| 5563 | .requestVisibleBehind(mToken, visible) && visible; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5564 | } catch (RemoteException e) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5565 | mVisibleBehind = false; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5566 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5567 | return mVisibleBehind; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5571 | * Called when a translucent activity over this activity is becoming opaque or another |
| 5572 | * activity is being launched. Activities that override this method must call |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 5573 | * <code>super.onVisibleBehindCanceled()</code> or a SuperNotCalledException will be thrown. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5574 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5575 | * <p>When this method is called the activity has 500 msec to release any resources it may be |
| 5576 | * using while visible in the background. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5577 | * 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] | 5578 | * 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] | 5579 | * process. Otherwise {@link #onStop()} will be called following return. |
| 5580 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5581 | * @see #requestVisibleBehind(boolean) |
| 5582 | * @see #onBackgroundVisibleBehindChanged(boolean) |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5583 | */ |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 5584 | public void onVisibleBehindCanceled() { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5585 | mCalled = true; |
| 5586 | } |
| 5587 | |
| 5588 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5589 | * Translucent activities may call this to determine if there is an activity below them that |
| 5590 | * is currently set to be visible in the background. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5591 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5592 | * @return true if an activity below is set to visible according to the most recent call to |
| 5593 | * {@link #requestVisibleBehind(boolean)}, false otherwise. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5594 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5595 | * @see #requestVisibleBehind(boolean) |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 5596 | * @see #onVisibleBehindCanceled() |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5597 | * @see #onBackgroundVisibleBehindChanged(boolean) |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5598 | * @hide |
| 5599 | */ |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5600 | @SystemApi |
| 5601 | public boolean isBackgroundVisibleBehind() { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5602 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5603 | return ActivityManagerNative.getDefault().isBackgroundVisibleBehind(mToken); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5604 | } catch (RemoteException e) { |
| 5605 | } |
| 5606 | return false; |
| 5607 | } |
| 5608 | |
| 5609 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5610 | * The topmost foreground activity will receive this call when the background visibility state |
| 5611 | * of the activity below it changes. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5612 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5613 | * 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] | 5614 | * due to a background activity finishing itself. |
| 5615 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5616 | * @param visible true if a background activity is visible, false otherwise. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5617 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5618 | * @see #requestVisibleBehind(boolean) |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 5619 | * @see #onVisibleBehindCanceled() |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5620 | * @hide |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5621 | */ |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5622 | @SystemApi |
| 5623 | public void onBackgroundVisibleBehindChanged(boolean visible) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5624 | } |
| 5625 | |
| 5626 | /** |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 5627 | * Activities cannot draw during the period that their windows are animating in. In order |
| 5628 | * to know when it is safe to begin drawing they can override this method which will be |
| 5629 | * called when the entering animation has completed. |
| 5630 | */ |
| 5631 | public void onEnterAnimationComplete() { |
| 5632 | } |
| 5633 | |
| 5634 | /** |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 5635 | * @hide |
| 5636 | */ |
| 5637 | public void dispatchEnterAnimationComplete() { |
| 5638 | onEnterAnimationComplete(); |
| 5639 | if (getWindow() != null && getWindow().getDecorView() != null) { |
| 5640 | getWindow().getDecorView().getViewTreeObserver().dispatchOnEnterAnimationComplete(); |
| 5641 | } |
| 5642 | } |
| 5643 | |
| 5644 | /** |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 5645 | * Adjust the current immersive mode setting. |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 5646 | * |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 5647 | * Note that changing this value will have no effect on the activity's |
| 5648 | * {@link android.content.pm.ActivityInfo} structure; that is, if |
| 5649 | * <code>android:immersive</code> is set to <code>true</code> |
| 5650 | * in the application's manifest entry for this activity, the {@link |
| 5651 | * android.content.pm.ActivityInfo#flags ActivityInfo.flags} member will |
| 5652 | * always have its {@link android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 5653 | * FLAG_IMMERSIVE} bit set. |
| 5654 | * |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 5655 | * @see #isImmersive() |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 5656 | * @see android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 5657 | */ |
| 5658 | public void setImmersive(boolean i) { |
| 5659 | try { |
| 5660 | ActivityManagerNative.getDefault().setImmersive(mToken, i); |
| 5661 | } catch (RemoteException e) { |
| 5662 | // pass |
| 5663 | } |
| 5664 | } |
| 5665 | |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 5666 | /** |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 5667 | * Start an action mode. |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 5668 | * |
| 5669 | * @param callback Callback that will manage lifecycle events for this context mode |
| 5670 | * @return The ContextMode that was started, or null if it was canceled |
| 5671 | * |
| 5672 | * @see ActionMode |
| 5673 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5674 | @Nullable |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 5675 | public ActionMode startActionMode(ActionMode.Callback callback) { |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 5676 | return mWindow.getDecorView().startActionMode(callback); |
| 5677 | } |
| 5678 | |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 5679 | /** |
| 5680 | * Give the Activity a chance to control the UI for an action mode requested |
| 5681 | * by the system. |
| 5682 | * |
| 5683 | * <p>Note: If you are looking for a notification callback that an action mode |
| 5684 | * has been started for this activity, see {@link #onActionModeStarted(ActionMode)}.</p> |
| 5685 | * |
| 5686 | * @param callback The callback that should control the new action mode |
| 5687 | * @return The new action mode, or <code>null</code> if the activity does not want to |
| 5688 | * provide special handling for this action mode. (It will be handled by the system.) |
| 5689 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5690 | @Nullable |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5691 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 5692 | public ActionMode onWindowStartingActionMode(ActionMode.Callback callback) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 5693 | initWindowDecorActionBar(); |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 5694 | if (mActionBar != null) { |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 5695 | return mActionBar.startActionMode(callback); |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 5696 | } |
| 5697 | return null; |
| 5698 | } |
| 5699 | |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 5700 | /** |
| 5701 | * Notifies the Activity that an action mode has been started. |
| 5702 | * Activity subclasses overriding this method should call the superclass implementation. |
| 5703 | * |
| 5704 | * @param mode The new action mode. |
| 5705 | */ |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5706 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 5707 | public void onActionModeStarted(ActionMode mode) { |
| 5708 | } |
| 5709 | |
| 5710 | /** |
| 5711 | * Notifies the activity that an action mode has finished. |
| 5712 | * Activity subclasses overriding this method should call the superclass implementation. |
| 5713 | * |
| 5714 | * @param mode The action mode that just finished. |
| 5715 | */ |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 5716 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 5717 | public void onActionModeFinished(ActionMode mode) { |
| 5718 | } |
| 5719 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 5720 | /** |
| 5721 | * Returns true if the app should recreate the task when navigating 'up' from this activity |
| 5722 | * by using targetIntent. |
| 5723 | * |
| 5724 | * <p>If this method returns false the app can trivially call |
| 5725 | * {@link #navigateUpTo(Intent)} using the same parameters to correctly perform |
| 5726 | * up navigation. If this method returns false, the app should synthesize a new task stack |
| 5727 | * by using {@link TaskStackBuilder} or another similar mechanism to perform up navigation.</p> |
| 5728 | * |
| 5729 | * @param targetIntent An intent representing the target destination for up navigation |
| 5730 | * @return true if navigating up should recreate a new task stack, false if the same task |
| 5731 | * should be used for the destination |
| 5732 | */ |
| 5733 | public boolean shouldUpRecreateTask(Intent targetIntent) { |
| 5734 | try { |
| 5735 | PackageManager pm = getPackageManager(); |
| 5736 | ComponentName cn = targetIntent.getComponent(); |
| 5737 | if (cn == null) { |
| 5738 | cn = targetIntent.resolveActivity(pm); |
| 5739 | } |
| 5740 | ActivityInfo info = pm.getActivityInfo(cn, 0); |
| 5741 | if (info.taskAffinity == null) { |
| 5742 | return false; |
| 5743 | } |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 5744 | return ActivityManagerNative.getDefault() |
| 5745 | .shouldUpRecreateTask(mToken, info.taskAffinity); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 5746 | } catch (RemoteException e) { |
| 5747 | return false; |
| 5748 | } catch (NameNotFoundException e) { |
| 5749 | return false; |
| 5750 | } |
| 5751 | } |
| 5752 | |
| 5753 | /** |
| 5754 | * Navigate from this activity to the activity specified by upIntent, finishing this activity |
| 5755 | * in the process. If the activity indicated by upIntent already exists in the task's history, |
| 5756 | * 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] | 5757 | * finished. |
| 5758 | * |
| 5759 | * <p>If the indicated activity does not appear in the history stack, this will finish |
| 5760 | * each activity in this task until the root activity of the task is reached, resulting in |
| 5761 | * an "in-app home" behavior. This can be useful in apps with a complex navigation hierarchy |
| 5762 | * when an activity may be reached by a path not passing through a canonical parent |
| 5763 | * activity.</p> |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 5764 | * |
| 5765 | * <p>This method should be used when performing up navigation from within the same task |
| 5766 | * as the destination. If up navigation should cross tasks in some cases, see |
| 5767 | * {@link #shouldUpRecreateTask(Intent)}.</p> |
| 5768 | * |
| 5769 | * @param upIntent An intent representing the target destination for up navigation |
| 5770 | * |
| 5771 | * @return true if up navigation successfully reached the activity indicated by upIntent and |
| 5772 | * upIntent was delivered to it. false if an instance of the indicated activity could |
| 5773 | * not be found and this activity was simply finished normally. |
| 5774 | */ |
| 5775 | public boolean navigateUpTo(Intent upIntent) { |
| 5776 | if (mParent == null) { |
| 5777 | ComponentName destInfo = upIntent.getComponent(); |
| 5778 | if (destInfo == null) { |
| 5779 | destInfo = upIntent.resolveActivity(getPackageManager()); |
| 5780 | if (destInfo == null) { |
| 5781 | return false; |
| 5782 | } |
| 5783 | upIntent = new Intent(upIntent); |
| 5784 | upIntent.setComponent(destInfo); |
| 5785 | } |
| 5786 | int resultCode; |
| 5787 | Intent resultData; |
| 5788 | synchronized (this) { |
| 5789 | resultCode = mResultCode; |
| 5790 | resultData = mResultData; |
| 5791 | } |
| 5792 | if (resultData != null) { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 5793 | resultData.prepareToLeaveProcess(); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 5794 | } |
| 5795 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 5796 | upIntent.prepareToLeaveProcess(); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 5797 | return ActivityManagerNative.getDefault().navigateUpTo(mToken, upIntent, |
| 5798 | resultCode, resultData); |
| 5799 | } catch (RemoteException e) { |
| 5800 | return false; |
| 5801 | } |
| 5802 | } else { |
| 5803 | return mParent.navigateUpToFromChild(this, upIntent); |
| 5804 | } |
| 5805 | } |
| 5806 | |
| 5807 | /** |
| 5808 | * This is called when a child activity of this one calls its |
| 5809 | * {@link #navigateUpTo} method. The default implementation simply calls |
| 5810 | * navigateUpTo(upIntent) on this activity (the parent). |
| 5811 | * |
| 5812 | * @param child The activity making the call. |
| 5813 | * @param upIntent An intent representing the target destination for up navigation |
| 5814 | * |
| 5815 | * @return true if up navigation successfully reached the activity indicated by upIntent and |
| 5816 | * upIntent was delivered to it. false if an instance of the indicated activity could |
| 5817 | * not be found and this activity was simply finished normally. |
| 5818 | */ |
| 5819 | public boolean navigateUpToFromChild(Activity child, Intent upIntent) { |
| 5820 | return navigateUpTo(upIntent); |
| 5821 | } |
| 5822 | |
| 5823 | /** |
| 5824 | * Obtain an {@link Intent} that will launch an explicit target activity specified by |
| 5825 | * this activity's logical parent. The logical parent is named in the application's manifest |
| 5826 | * by the {@link android.R.attr#parentActivityName parentActivityName} attribute. |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 5827 | * Activity subclasses may override this method to modify the Intent returned by |
| 5828 | * super.getParentActivityIntent() or to implement a different mechanism of retrieving |
| 5829 | * the parent intent entirely. |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 5830 | * |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 5831 | * @return a new Intent targeting the defined parent of this activity or null if |
| 5832 | * there is no valid parent. |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 5833 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5834 | @Nullable |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 5835 | public Intent getParentActivityIntent() { |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 5836 | final String parentName = mActivityInfo.parentActivityName; |
| 5837 | if (TextUtils.isEmpty(parentName)) { |
| 5838 | return null; |
| 5839 | } |
Adam Powell | 5a4010c | 2012-09-16 15:14:05 -0700 | [diff] [blame] | 5840 | |
| 5841 | // If the parent itself has no parent, generate a main activity intent. |
| 5842 | final ComponentName target = new ComponentName(this, parentName); |
| 5843 | try { |
| 5844 | final ActivityInfo parentInfo = getPackageManager().getActivityInfo(target, 0); |
| 5845 | final String parentActivity = parentInfo.parentActivityName; |
| 5846 | final Intent parentIntent = parentActivity == null |
| 5847 | ? Intent.makeMainActivity(target) |
| 5848 | : new Intent().setComponent(target); |
| 5849 | return parentIntent; |
| 5850 | } catch (NameNotFoundException e) { |
| 5851 | Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName + |
| 5852 | "' in manifest"); |
| 5853 | return null; |
| 5854 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 5855 | } |
| 5856 | |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 5857 | /** |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5858 | * When {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 5859 | * 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] | 5860 | * 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] | 5861 | * {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 5862 | * |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 5863 | * @param callback Used to manipulate shared element transitions on the launched Activity. |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 5864 | */ |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 5865 | public void setEnterSharedElementCallback(SharedElementCallback callback) { |
| 5866 | if (callback == null) { |
| 5867 | callback = SharedElementCallback.NULL_CALLBACK; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 5868 | } |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 5869 | mEnterTransitionListener = callback; |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 5870 | } |
| 5871 | |
| 5872 | /** |
| 5873 | * When {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 5874 | * 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] | 5875 | * will be called to handle shared elements on the <i>launching</i> Activity. Most |
| 5876 | * calls will only come when returning from the started Activity. |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 5877 | * This requires {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 5878 | * |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 5879 | * @param callback Used to manipulate shared element transitions on the launching Activity. |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 5880 | */ |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 5881 | public void setExitSharedElementCallback(SharedElementCallback callback) { |
| 5882 | if (callback == null) { |
| 5883 | callback = SharedElementCallback.NULL_CALLBACK; |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 5884 | } |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 5885 | mExitTransitionListener = callback; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 5886 | } |
| 5887 | |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 5888 | /** |
| 5889 | * Postpone the entering activity transition when Activity was started with |
| 5890 | * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
| 5891 | * android.util.Pair[])}. |
| 5892 | * <p>This method gives the Activity the ability to delay starting the entering and |
| 5893 | * shared element transitions until all data is loaded. Until then, the Activity won't |
| 5894 | * draw into its window, leaving the window transparent. This may also cause the |
| 5895 | * returning animation to be delayed until data is ready. This method should be |
| 5896 | * called in {@link #onCreate(android.os.Bundle)} or in |
| 5897 | * {@link #onActivityReenter(int, android.content.Intent)}. |
| 5898 | * {@link #startPostponedEnterTransition()} must be called to allow the Activity to |
| 5899 | * start the transitions. If the Activity did not use |
| 5900 | * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
| 5901 | * android.util.Pair[])}, then this method does nothing.</p> |
| 5902 | */ |
| 5903 | public void postponeEnterTransition() { |
| 5904 | mActivityTransitionState.postponeEnterTransition(); |
| 5905 | } |
| 5906 | |
| 5907 | /** |
| 5908 | * Begin postponed transitions after {@link #postponeEnterTransition()} was called. |
| 5909 | * If postponeEnterTransition() was called, you must call startPostponedEnterTransition() |
| 5910 | * to have your Activity start drawing. |
| 5911 | */ |
| 5912 | public void startPostponedEnterTransition() { |
| 5913 | mActivityTransitionState.startPostponedEnterTransition(); |
| 5914 | } |
| 5915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5916 | // ------------------ Internal API ------------------ |
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 | final void setParent(Activity parent) { |
| 5919 | mParent = parent; |
| 5920 | } |
| 5921 | |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 5922 | final void attach(Context context, ActivityThread aThread, |
| 5923 | Instrumentation instr, IBinder token, int ident, |
| 5924 | Application application, Intent intent, ActivityInfo info, |
| 5925 | CharSequence title, Activity parent, String id, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 5926 | NonConfigurationInstances lastNonConfigurationInstances, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 5927 | Configuration config, String referrer, IVoiceInteractor voiceInteractor) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5928 | attachBaseContext(context); |
| 5929 | |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 5930 | mFragments.attachActivity(this, mContainer, null); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5931 | |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame^] | 5932 | mWindow = new PhoneWindow(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5933 | mWindow.setCallback(this); |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 5934 | mWindow.setOnWindowDismissedCallback(this); |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 5935 | mWindow.getLayoutInflater().setPrivateFactory(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5936 | if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) { |
| 5937 | mWindow.setSoftInputMode(info.softInputMode); |
| 5938 | } |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 5939 | if (info.uiOptions != 0) { |
| 5940 | mWindow.setUiOptions(info.uiOptions); |
| 5941 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5942 | mUiThread = Thread.currentThread(); |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 5943 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5944 | mMainThread = aThread; |
| 5945 | mInstrumentation = instr; |
| 5946 | mToken = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 5947 | mIdent = ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5948 | mApplication = application; |
| 5949 | mIntent = intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 5950 | mReferrer = referrer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5951 | mComponent = intent.getComponent(); |
| 5952 | mActivityInfo = info; |
| 5953 | mTitle = title; |
| 5954 | mParent = parent; |
| 5955 | mEmbeddedID = id; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 5956 | mLastNonConfigurationInstances = lastNonConfigurationInstances; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 5957 | if (voiceInteractor != null) { |
| 5958 | if (lastNonConfigurationInstances != null) { |
| 5959 | mVoiceInteractor = lastNonConfigurationInstances.voiceInteractor; |
| 5960 | } else { |
| 5961 | mVoiceInteractor = new VoiceInteractor(voiceInteractor, this, this, |
| 5962 | Looper.myLooper()); |
| 5963 | } |
| 5964 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5965 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5966 | mWindow.setWindowManager( |
| 5967 | (WindowManager)context.getSystemService(Context.WINDOW_SERVICE), |
| 5968 | mToken, mComponent.flattenToString(), |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 5969 | (info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5970 | if (mParent != null) { |
| 5971 | mWindow.setContainer(mParent.getWindow()); |
| 5972 | } |
| 5973 | mWindowManager = mWindow.getWindowManager(); |
| 5974 | mCurrentConfig = config; |
| 5975 | } |
| 5976 | |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 5977 | /** @hide */ |
| 5978 | public final IBinder getActivityToken() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5979 | return mParent != null ? mParent.getActivityToken() : mToken; |
| 5980 | } |
| 5981 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5982 | final void performCreateCommon() { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5983 | mVisibleFromClient = !mWindow.getWindowStyle().getBoolean( |
| 5984 | com.android.internal.R.styleable.Window_windowNoDisplay, false); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 5985 | mFragments.dispatchActivityCreated(); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5986 | mActivityTransitionState.setEnterActivityOptions(this, getActivityOptions()); |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 5987 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 5988 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5989 | final void performCreate(Bundle icicle) { |
| 5990 | onCreate(icicle); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5991 | mActivityTransitionState.readState(icicle); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5992 | performCreateCommon(); |
| 5993 | } |
| 5994 | |
| 5995 | final void performCreate(Bundle icicle, PersistableBundle persistentState) { |
| 5996 | onCreate(icicle, persistentState); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5997 | mActivityTransitionState.readState(icicle); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5998 | performCreateCommon(); |
| 5999 | } |
| 6000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6001 | final void performStart() { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6002 | mActivityTransitionState.setEnterActivityOptions(this, getActivityOptions()); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 6003 | mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6004 | mCalled = false; |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 6005 | mFragments.execPendingActions(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6006 | mInstrumentation.callActivityOnStart(this); |
| 6007 | if (!mCalled) { |
| 6008 | throw new SuperNotCalledException( |
| 6009 | "Activity " + mComponent.toShortString() + |
| 6010 | " did not call through to super.onStart()"); |
| 6011 | } |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 6012 | mFragments.dispatchStart(); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 6013 | if (mAllLoaderManagers != null) { |
Dianne Hackborn | 3e82ba1 | 2013-07-16 13:23:55 -0700 | [diff] [blame] | 6014 | final int N = mAllLoaderManagers.size(); |
| 6015 | LoaderManagerImpl loaders[] = new LoaderManagerImpl[N]; |
| 6016 | for (int i=N-1; i>=0; i--) { |
| 6017 | loaders[i] = mAllLoaderManagers.valueAt(i); |
| 6018 | } |
| 6019 | for (int i=0; i<N; i++) { |
| 6020 | LoaderManagerImpl lm = loaders[i]; |
| 6021 | lm.finishRetain(); |
| 6022 | lm.doReportStart(); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 6023 | } |
| 6024 | } |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6025 | mActivityTransitionState.enterReady(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6026 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6027 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6028 | final void performRestart() { |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 6029 | mFragments.noteStateNotSaved(); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 6030 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6031 | if (mStopped) { |
| 6032 | mStopped = false; |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 6033 | if (mToken != null && mParent == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6034 | WindowManagerGlobal.getInstance().setStoppedState(mToken, false); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 6035 | } |
Dianne Hackborn | 185e3e2 | 2011-06-03 15:26:01 -0700 | [diff] [blame] | 6036 | |
| 6037 | synchronized (mManagedCursors) { |
| 6038 | final int N = mManagedCursors.size(); |
| 6039 | for (int i=0; i<N; i++) { |
| 6040 | ManagedCursor mc = mManagedCursors.get(i); |
| 6041 | if (mc.mReleased || mc.mUpdated) { |
| 6042 | if (!mc.mCursor.requery()) { |
Dianne Hackborn | a5445d3 | 2011-09-01 14:38:24 -0700 | [diff] [blame] | 6043 | if (getApplicationInfo().targetSdkVersion |
| 6044 | >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
| 6045 | throw new IllegalStateException( |
| 6046 | "trying to requery an already closed cursor " |
| 6047 | + mc.mCursor); |
| 6048 | } |
Dianne Hackborn | 185e3e2 | 2011-06-03 15:26:01 -0700 | [diff] [blame] | 6049 | } |
| 6050 | mc.mReleased = false; |
| 6051 | mc.mUpdated = false; |
| 6052 | } |
| 6053 | } |
| 6054 | } |
| 6055 | |
| 6056 | mCalled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6057 | mInstrumentation.callActivityOnRestart(this); |
| 6058 | if (!mCalled) { |
| 6059 | throw new SuperNotCalledException( |
| 6060 | "Activity " + mComponent.toShortString() + |
| 6061 | " did not call through to super.onRestart()"); |
| 6062 | } |
| 6063 | performStart(); |
| 6064 | } |
| 6065 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6066 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6067 | final void performResume() { |
| 6068 | performRestart(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6069 | |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 6070 | mFragments.execPendingActions(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6071 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 6072 | mLastNonConfigurationInstances = null; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6073 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6074 | mCalled = false; |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 6075 | // mResumed is set by the instrumentation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6076 | mInstrumentation.callActivityOnResume(this); |
| 6077 | if (!mCalled) { |
| 6078 | throw new SuperNotCalledException( |
| 6079 | "Activity " + mComponent.toShortString() + |
| 6080 | " did not call through to super.onResume()"); |
| 6081 | } |
| 6082 | |
Todd Kennedy | ee8c9c6 | 2014-12-10 14:22:59 -0800 | [diff] [blame] | 6083 | // invisible activities must be finished before onResume() completes |
| 6084 | if (!mVisibleFromClient && !mFinished) { |
| 6085 | Log.w(TAG, "An activity without a UI must call finish() before onResume() completes"); |
| 6086 | if (getApplicationInfo().targetSdkVersion |
| 6087 | > android.os.Build.VERSION_CODES.LOLLIPOP_MR1) { |
| 6088 | throw new IllegalStateException( |
| 6089 | "Activity " + mComponent.toShortString() + |
| 6090 | " did not call finish() prior to onResume() completing"); |
| 6091 | } |
| 6092 | } |
| 6093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6094 | // 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] | 6095 | mCalled = false; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6096 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 6097 | mFragments.dispatchResume(); |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 6098 | mFragments.execPendingActions(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6099 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6100 | onPostResume(); |
| 6101 | if (!mCalled) { |
| 6102 | throw new SuperNotCalledException( |
| 6103 | "Activity " + mComponent.toShortString() + |
| 6104 | " did not call through to super.onPostResume()"); |
| 6105 | } |
| 6106 | } |
| 6107 | |
| 6108 | final void performPause() { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 6109 | mDoReportFullyDrawn = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 6110 | mFragments.dispatchPause(); |
Dianne Hackborn | e794e9f | 2010-08-24 12:32:10 -0700 | [diff] [blame] | 6111 | mCalled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6112 | onPause(); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 6113 | mResumed = false; |
Dianne Hackborn | e794e9f | 2010-08-24 12:32:10 -0700 | [diff] [blame] | 6114 | if (!mCalled && getApplicationInfo().targetSdkVersion |
| 6115 | >= android.os.Build.VERSION_CODES.GINGERBREAD) { |
| 6116 | throw new SuperNotCalledException( |
| 6117 | "Activity " + mComponent.toShortString() + |
| 6118 | " did not call through to super.onPause()"); |
| 6119 | } |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 6120 | mResumed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6121 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6122 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6123 | final void performUserLeaving() { |
| 6124 | onUserInteraction(); |
| 6125 | onUserLeaveHint(); |
| 6126 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6128 | final void performStop() { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 6129 | mDoReportFullyDrawn = false; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 6130 | if (mLoadersStarted) { |
| 6131 | mLoadersStarted = false; |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 6132 | if (mLoaderManager != null) { |
| 6133 | if (!mChangingConfigurations) { |
| 6134 | mLoaderManager.doStop(); |
| 6135 | } else { |
| 6136 | mLoaderManager.doRetain(); |
| 6137 | } |
| 6138 | } |
| 6139 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6141 | if (!mStopped) { |
| 6142 | if (mWindow != null) { |
| 6143 | mWindow.closeAllPanels(); |
| 6144 | } |
| 6145 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 6146 | if (mToken != null && mParent == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6147 | WindowManagerGlobal.getInstance().setStoppedState(mToken, true); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 6148 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6149 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 6150 | mFragments.dispatchStop(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6152 | mCalled = false; |
| 6153 | mInstrumentation.callActivityOnStop(this); |
| 6154 | if (!mCalled) { |
| 6155 | throw new SuperNotCalledException( |
| 6156 | "Activity " + mComponent.toShortString() + |
| 6157 | " did not call through to super.onStop()"); |
| 6158 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6159 | |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 6160 | synchronized (mManagedCursors) { |
| 6161 | final int N = mManagedCursors.size(); |
| 6162 | for (int i=0; i<N; i++) { |
| 6163 | ManagedCursor mc = mManagedCursors.get(i); |
| 6164 | if (!mc.mReleased) { |
| 6165 | mc.mCursor.deactivate(); |
| 6166 | mc.mReleased = true; |
| 6167 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6168 | } |
| 6169 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 6170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6171 | mStopped = true; |
| 6172 | } |
| 6173 | mResumed = false; |
| 6174 | } |
| 6175 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 6176 | final void performDestroy() { |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 6177 | mDestroyed = true; |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 6178 | mWindow.destroy(); |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 6179 | mFragments.dispatchDestroy(); |
| 6180 | onDestroy(); |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 6181 | if (mLoaderManager != null) { |
| 6182 | mLoaderManager.doDestroy(); |
| 6183 | } |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 6184 | if (mVoiceInteractor != null) { |
| 6185 | mVoiceInteractor.detachActivity(); |
| 6186 | } |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 6187 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 6188 | |
| 6189 | /** |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 6190 | * @hide |
| 6191 | */ |
| 6192 | public final boolean isResumed() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6193 | return mResumed; |
| 6194 | } |
| 6195 | |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 6196 | void dispatchActivityResult(String who, int requestCode, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6197 | int resultCode, Intent data) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 6198 | if (false) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6199 | TAG, "Dispatching result: who=" + who + ", reqCode=" + requestCode |
| 6200 | + ", resCode=" + resultCode + ", data=" + data); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 6201 | mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6202 | if (who == null) { |
| 6203 | onActivityResult(requestCode, resultCode, data); |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 6204 | } else { |
| 6205 | Fragment frag = mFragments.findFragmentByWho(who); |
| 6206 | if (frag != null) { |
| 6207 | frag.onActivityResult(requestCode, resultCode, data); |
| 6208 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6209 | } |
| 6210 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6211 | |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 6212 | /** |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 6213 | * Request to put this Activity in a mode where the user is locked to the |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 6214 | * current task. |
| 6215 | * |
| 6216 | * This will prevent the user from launching other apps, going to settings, |
| 6217 | * or reaching the home screen. |
| 6218 | * |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 6219 | * If {@link DevicePolicyManager#isLockTaskPermitted(String)} returns true |
| 6220 | * for this component then the app will go directly into Lock Task mode. The user |
| 6221 | * will not be able to exit this mode until {@link Activity#stopLockTask()} is called. |
| 6222 | * |
| 6223 | * If {@link DevicePolicyManager#isLockTaskPermitted(String)} returns false |
| 6224 | * then the system will prompt the user with a dialog requesting permission to enter |
Jason Monk | 8863b57 | 2014-07-29 13:49:32 -0400 | [diff] [blame] | 6225 | * this mode. When entered through this method the user can exit at any time through |
| 6226 | * an action described by the request dialog. Calling stopLockTask will also exit the |
| 6227 | * mode. |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 6228 | */ |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 6229 | public void startLockTask() { |
| 6230 | try { |
| 6231 | ActivityManagerNative.getDefault().startLockTaskMode(mToken); |
| 6232 | } catch (RemoteException e) { |
| 6233 | } |
| 6234 | } |
| 6235 | |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 6236 | /** |
| 6237 | * Allow the user to switch away from the current task. |
| 6238 | * |
| 6239 | * Called to end the mode started by {@link Activity#startLockTask}. This |
| 6240 | * can only be called by activities that have successfully called |
| 6241 | * startLockTask previously. |
| 6242 | * |
| 6243 | * This will allow the user to exit this app and move onto other activities. |
| 6244 | */ |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 6245 | public void stopLockTask() { |
| 6246 | try { |
| 6247 | ActivityManagerNative.getDefault().stopLockTaskMode(); |
| 6248 | } catch (RemoteException e) { |
| 6249 | } |
| 6250 | } |
| 6251 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6252 | /** |
| 6253 | * Interface for informing a translucent {@link Activity} once all visible activities below it |
| 6254 | * have completed drawing. This is necessary only after an {@link Activity} has been made |
| 6255 | * opaque using {@link Activity#convertFromTranslucent()} and before it has been drawn |
| 6256 | * translucent again following a call to {@link |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 6257 | * Activity#convertToTranslucent(android.app.Activity.TranslucentConversionListener, |
| 6258 | * ActivityOptions)} |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 6259 | * |
| 6260 | * @hide |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6261 | */ |
Jose Lima | 1491485 | 2014-08-14 09:14:12 -0700 | [diff] [blame] | 6262 | @SystemApi |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6263 | public interface TranslucentConversionListener { |
| 6264 | /** |
| 6265 | * Callback made following {@link Activity#convertToTranslucent} once all visible Activities |
| 6266 | * below the top one have been redrawn. Following this callback it is safe to make the top |
| 6267 | * Activity translucent because the underlying Activity has been drawn. |
| 6268 | * |
| 6269 | * @param drawComplete True if the background Activity has drawn itself. False if a timeout |
| 6270 | * occurred waiting for the Activity to complete drawing. |
| 6271 | * |
| 6272 | * @see Activity#convertFromTranslucent() |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6273 | * @see Activity#convertToTranslucent(TranslucentConversionListener, ActivityOptions) |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6274 | */ |
| 6275 | public void onTranslucentConversionComplete(boolean drawComplete); |
| 6276 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6277 | } |