Getting intent extra and the onCreate method?

user1876202 picture user1876202 · Mar 10, 2013 · Viewed 13.1k times · Source

I have classes A, B and C. Class A sends intent to B, B runs C, C returns to B.....but then inside of the onCreate of the B class it wants the intent of Class A. But because its come from class C it does not get it but I still need the intent of class A

Any idea on how to get around this? I guess one solution might be to store the extra.getString in a database or similar?

Bundle extras = getIntent().getExtras();
 newString = extras.getString("ID"); 

Answer

Hoan Nguyen picture Hoan Nguyen · Mar 10, 2013

Since I do not know exactly your Activities flow, this is a solution but may not be the appropriate one.

When you start new activity, put an extra

intent.putExtra("ID_FROM_A", value); // except for ActivityA value = mIdFromA
startActivity(intent);

On the receiving activity

onCreate()
{
    mIdFromA = getIntent().getStringExtra("ID_FROM_A");
}