Android Will the value of isFinishing () remain true after the action has been destroyed?

I apologize if this question sounds incredibly thorough. I have an Activity that has an asynchronous callback on the network. A callback may be executed after the user leaves the Activity.

As a check, I would like to use isFinishing() (I cannot use isDestroyed() since my minimum API level is 16, not 17, for which isDestroyed() is required).

Can I use isFinishing() in a callback to make sure my logic only executes when activity is not destroyed?

More specifically, isFinishing() returns true for an Activity that is destroyed by calling finish() even after calling onDestroy() ?

I also looked at the source code. Here isFinishing() :

  public boolean isFinishing() { return mFinished; } 

And here is finish (), where the variable is true:

  /** * Finishes the current activity and specifies whether to remove the task associated with this * activity. */ private void finish(boolean finishTask) { if (mParent == null) { int resultCode; Intent resultData; synchronized (this) { resultCode = mResultCode; resultData = mResultData; } if (false) Log.v(TAG, "Finishing self: token=" + mToken); try { if (resultData != null) { resultData.prepareToLeaveProcess(); } if (ActivityManagerNative.getDefault() .finishActivity(mToken, resultCode, resultData, finishTask)) { mFinished = true; } } catch (RemoteException e) { // Empty } } else { mParent.finishFromChild(this); } } /** * Call this when your activity is done and should be closed. The * ActivityResult is propagated back to whoever launched you via * onActivityResult(). */ public void finish() { finish(false); } 

I also looked at Understanding isFinishing () but I cannot find the answer to this specific question.

+6
source share

All Articles