Created
January 14, 2016 13:40
-
-
Save joinAero/72d5d7a2d42762261065 to your computer and use it in GitHub Desktop.
Android - Activity for providing resume under the window has been attached.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cc.cubone.turbo.core.app; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
public class TokenActivity extends AppCompatActivity { | |
private boolean mAttached; | |
/*public boolean isAttached() { | |
return mAttached; | |
}*/ | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
tryResumeUnderAttached(); | |
} | |
/** | |
* To avoid {@link android.view.WindowManager.BadTokenException}, should show | |
* {@link android.widget.PopupWindow}, {@link android.app.Dialog} in this method. | |
* Must not show them in {@link #onCreate(Bundle)}, {@link #onResume()} directly. | |
* | |
* <p>It is also recommended that register the {@link android.content.BroadcastReceiver} | |
* in this method and unregister it in {@link #onDetachedFromWindow()}. | |
*/ | |
@Override | |
public void onAttachedToWindow() { | |
super.onAttachedToWindow(); | |
mAttached = true; | |
tryResumeUnderAttached(); | |
} | |
@Override | |
public void onDetachedFromWindow() { | |
super.onDetachedFromWindow(); | |
mAttached = false; | |
} | |
private void tryResumeUnderAttached() { | |
if (mAttached) { | |
onResumeUnderAttached(); | |
} | |
} | |
/** | |
* Ensure {@link #onResume()} under the window has been attached. | |
*/ | |
protected void onResumeUnderAttached() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment