Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final Intent activityIntent = new Intent(context, MainActivity.class);
- activityIntent.putExtra("smsChallenge", smsText);
- activityIntent.putExtra("smsSenderNumber", senderMobilNumber);
- activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- context.startActivity(activityIntent);
- Bundle extras = getIntent().getExtras();
- if (extras != null) {
- smsChallenge = extras.getString("smsChallenge");
- extras.remove("smsChallenge");
- }
- getIntent().removeExtra("smsChallenge");
- public YourActivity extends Activity {
- private boolean extrasClearedOut;
- private SharedPreferences mPrefs;
- private static String EXTRA_CLEAR_OUT = "extras_cleared_out";
- public void onCreate(Bundle savedInstanceState) {
- mPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
- extrasClearedOut = mPrefs.getBoolean(EXTRA_CLEAR_OUT, false);
- if (savedInstanceState != null && savedInstanceState.getBoolean(EXTRA_CLEAR_OUT, false)) {
- extrasClearedOut = true;
- }
- Intent intent = getIntent();
- if (extrasClearedOut) {
- // ignore the extras in the intent.
- }
- else {
- // Read and use the extras in the intent.
- }
- }
- protected void onNewIntent (Intent intent) {
- super.onNewIntent(intent);
- setIntent(intent);
- if (extrasClearedOut) {
- // ignore the extras in the intent.
- }
- else {
- // Read and use the extras in the intent.
- }
- }
- public void someMethod(...) {
- extrasClearedOut = true;
- }
- protected void onSaveInstanceState (Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putBoolean(EXTRA_CLEAR_OUT, extrasClearedOut);
- }
- public void onDestroy()
- {
- final Editor edit = mPrefs.edit();
- edit.putBoolean(EXTRA_CLEAR_OUT, extrasClearedOut);
- edit.commit();
- }
- }
- private void removeExtraFromBundle(String key){
- Bundle bundle = getArguments();
- if(bundle != null){
- String value = null;
- value = bundle.getString(key);
- if(value != null){
- bundle.remove(key);
- }
- }
- }
- final Intent activityIntent = new Intent(context, MainActivity.class);
- activityIntent.putExtra("smsChallenge", smsText);
- activityIntent.putExtra("smsSenderNumber", senderMobilNumber);
- activityIntent.putExtra("nonce", UUID.randomUUID().toString);
- activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- context.startActivity(activityIntent);
- public void onCreate(final Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Intent = getIntent();
- smsChallenge = intent.getStringExtra("smsChallenge", null);
- String nonce = intent.getStringExtra("nonce", null);
- if (nonce == null) {
- // should not happen, but do something sane here
- }
- SharedPreferences sp = PreferenceManager.getDefaultPreferences(this);
- if (nonce.equals(sp.getString("nonce", null)) {
- // app was restarted
- } else {
- // app was started from a shiny fresh intent
- sp.edit().putString("nonce", nonce).commit();
- }
- }
- final Intent activityIntent = new Intent(context, MainActivity.class);
- final Intent activityIntent = new Intent(context.getApplicationContext(), MainActivity.class);
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // The Intent provided by getIntent() (and its extras) will persist through a restore
- // via savedInstance. Because of this, restoring this activity from a
- // an instance that was originally started with extras (deep-link or
- // pre-defined destination) may cause un-desired behavior
- // (ie...infinite loop of sending the user directly to somewhere else because of a
- // pre-defined alternate destination in the Intent's extras).
- //
- // To get around this, if restoring from savedInstanceState, we explicitly
- // set a new Intent *** to override the original Intent that started the activity.***
- // Note...it is still possible to re-use the original Intent values...simply
- // set them in the savedInstanceState Bundle in onSavedInstanceState.
- if (savedInstanceState != null) {
- // Place savedInstanceState Bundle as the Intent "extras"
- setIntent(new Intent().putExtras(savedInstanceState));
- }
- processIntent(getIntent())
- }
- private void processIntent(Intent intent) {
- if (getIntent().getExtras() == null) {
- // Protection condition
- return;
- }
- doSomething(intent.getExtras.getString("SOMETHING_I_REALLY_NEED_TO_PERSIST"));
- final String somethingIDontWantToPersist =
- intent.getExtras.getString("SOMETHING_I_DONT_WANT_TO_PERSIST");
- if(somethingIDontWantToPersist != null) {
- doSomething(somethingIDontWantToPersist);
- }
- }
- @Override
- public void onSaveInstanceState(Bundle savedInstanceState) {
- // Save selective extras from original Intent...
- savedInstanceState.putString("SOMETHING_I_REALLY_NEED_TO_PERSIST", "persistedValued");
- super.onSaveInstanceState(savedInstanceState);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement