My work flow is as follows:
LoginActivity -> ActivityB -> ActivityC -> ActivityD
I’d like to pass data from LoginActivity to ActivityD, but not go directly to ActivityD. ie, I’d like to pass data from LoginActivity to ActivityD, but go to ActivityB and ActivityC before I get to ActivityD and get the data there.
Is this possible?
I know to pass data from one activity to another the code is as follows:
Intent i = new Intent(getApplicationContext(), AnotherActivity.class);
i.putExtra("key", (int)1);
i.putExtra("something", something);
startActivity(i);
And in AnotherActivity you do the following to get the data:
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
String var = extras.getString("something");
}
But this does not work if I want to delay going straight to the activity. So if I take out startActivity(i); and go to another activity. The program crashes when tyring get the data in the final activity. The good old NullPointerExeption pops up.
Does anyone know a way of doing what I’ve described? Get the data from one activity to another, but not go (or start) that activity right away?
If you want to pass the data like this, it is preferable to use shared preferences.
It is simple to use and you can use the data any where in your program.
at the time of receiving: