Reputation: 4335
My use-case is as follows:
In activity A I call:
startActivity(B);
finish();
Now in onCreate of Activity B I need to know the activity that started B, so I wonder if in onCreate(...) of Activity B I call:
getIntent();
Would I even be able to get the Intent that started Activity B or would getIntent() at that point already return null because I finished Activity A immediately after calling startActivity(B) ?
Upvotes: 0
Views: 1950
Reputation: 34765
In first activity use below code to start new activity and restart method() to finish the activity::
Intent intent = new Intent(ThisActivity.this, NextActivity.class);
intent.putExtra("Key", "Value");
startActivity(intent);
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
finish();
}
In Second activity::
String started = getIntent().getStringExtras("Key");
Upvotes: 1
Reputation: 8852
here
Intent intent = new Intent(A.this, B.class);
intent.putExtra("activityStarted", "A");
and in Activity B
String started = getIntent().getExtras().getString("activityStarted");
Upvotes: 5