Exemple #1
0
		/// <summary>Core implementation of stopping an activity.</summary>
		/// <remarks>
		/// Core implementation of stopping an activity.  Note this is a little
		/// tricky because the server's meaning of stop is slightly different
		/// than our client -- for the server, stop means to save state and give
		/// it the result when it is done, but the window may still be visible.
		/// For the client, we want to call onStop()/onStart() to indicate when
		/// the activity's UI visibillity changes.
		/// </remarks>
		private void performStopActivityInner(android.app.ActivityThread.ActivityClientRecord
			 r, android.app.ActivityThread.StopInfo info, bool keepShown, bool saveState)
		{
			android.os.Bundle state = null;
			if (r != null)
			{
				if (!keepShown && r.stopped)
				{
					if (r.activity.mFinished)
					{
						// If we are finishing, we won't call onResume() in certain
						// cases.  So here we likewise don't want to call onStop()
						// if the activity isn't resumed.
						return;
					}
					java.lang.RuntimeException e = new java.lang.RuntimeException("Performing stop of activity that is not resumed: "
						 + r.intent.getComponent().toShortString());
					android.util.Slog.e(TAG, e.Message, e);
				}
				if (info != null)
				{
					try
					{
						// First create a thumbnail for the activity...
						info.thumbnail = createThumbnailBitmap(r);
						info.description = r.activity.onCreateDescription();
					}
					catch (System.Exception e)
					{
						if (!mInstrumentation.onException(r.activity, e))
						{
							throw new java.lang.RuntimeException("Unable to save state of activity " + r.intent
								.getComponent().toShortString() + ": " + e.ToString(), e);
						}
					}
				}
				// Next have the activity save its current state and managed dialogs...
				if (!r.activity.mFinished && saveState)
				{
					if (r.state == null)
					{
						state = new android.os.Bundle();
						state.setAllowFds(false);
						mInstrumentation.callActivityOnSaveInstanceState(r.activity, state);
						r.state = state;
					}
					else
					{
						state = r.state;
					}
				}
				if (!keepShown)
				{
					try
					{
						// Now we are idle.
						r.activity.performStop();
					}
					catch (System.Exception e)
					{
						if (!mInstrumentation.onException(r.activity, e))
						{
							throw new java.lang.RuntimeException("Unable to stop activity " + r.intent.getComponent
								().toShortString() + ": " + e.ToString(), e);
						}
					}
					r.stopped = true;
				}
				r.paused = true;
			}
		}
Exemple #2
0
		internal android.os.Bundle performPauseActivity(android.app.ActivityThread.ActivityClientRecord
			 r, bool finished, bool saveState)
		{
			if (r.paused)
			{
				if (r.activity.mFinished)
				{
					// If we are finishing, we won't call onResume() in certain cases.
					// So here we likewise don't want to call onPause() if the activity
					// isn't resumed.
					return null;
				}
				java.lang.RuntimeException e = new java.lang.RuntimeException("Performing pause of activity that is not resumed: "
					 + r.intent.getComponent().toShortString());
				android.util.Slog.e(TAG, e.Message, e);
			}
			android.os.Bundle state = null;
			if (finished)
			{
				r.activity.mFinished = true;
			}
			try
			{
				// Next have the activity save its current state and managed dialogs...
				if (!r.activity.mFinished && saveState)
				{
					state = new android.os.Bundle();
					state.setAllowFds(false);
					mInstrumentation.callActivityOnSaveInstanceState(r.activity, state);
					r.state = state;
				}
				// Now we are idle.
				r.activity.mCalled = false;
				mInstrumentation.callActivityOnPause(r.activity);
				android.util.EventLog.writeEvent(LOG_ON_PAUSE_CALLED, r.activity.getComponentName
					().getClassName());
				if (!r.activity.mCalled)
				{
					throw new android.app.SuperNotCalledException("Activity " + r.intent.getComponent
						().toShortString() + " did not call through to super.onPause()");
				}
			}
			catch (android.app.SuperNotCalledException e)
			{
				throw;
			}
			catch (System.Exception e)
			{
				if (!mInstrumentation.onException(r.activity, e))
				{
					throw new java.lang.RuntimeException("Unable to pause activity " + r.intent.getComponent
						().toShortString() + ": " + e.ToString(), e);
				}
			}
			r.paused = true;
			// Notify any outstanding on paused listeners
			java.util.ArrayList<android.app.OnActivityPausedListener> listeners;
			lock (mOnPauseListeners)
			{
				listeners = mOnPauseListeners.remove(r.activity);
			}
			int size = (listeners != null ? listeners.size() : 0);
			{
				for (int i = 0; i < size; i++)
				{
					listeners.get(i).onPaused(r.activity);
				}
			}
			return state;
		}