Created
March 24, 2016 07:52
-
-
Save dmitrikudrenko/5085b343d4a838b5fd69 to your computer and use it in GitHub Desktop.
Detect opening application from history stack
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
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.support.v7.app.AppCompatActivity; | |
public abstract class SecurityActivity extends AppCompatActivity { | |
protected boolean launchedFromHistory; | |
@Override | |
protected void onStart() { | |
super.onStart(); | |
if (launchedFromHistory) { | |
launchedFromHistory = false; | |
dispatchLaunchingFromHistory(); | |
} else launchedFromHistory = true; | |
} | |
@Override | |
public void startActivityForResult(Intent intent, int requestCode) { | |
super.startActivityForResult(intent, requestCode); | |
launchedFromHistory = false; | |
} | |
@Override | |
public void startActivity(Intent intent) { | |
super.startActivity(intent); | |
launchedFromHistory = false; | |
} | |
@Override | |
public void startActivity(Intent intent, Bundle options) { | |
super.startActivity(intent, options); | |
launchedFromHistory = false; | |
} | |
@Override | |
public void startActivityForResult(Intent intent, int requestCode, Bundle options) { | |
super.startActivityForResult(intent, requestCode, options); | |
launchedFromHistory = false; | |
} | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
this.launchedFromHistory = savedInstanceState != null; | |
} | |
protected abstract void dispatchLaunchingFromHistory(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment