Reputation: 39
I have an activity that receives .getExtras() from two different activities. The only problem is that it crashes because of the two different .getExtras() being set on that activity. How can I overcome this issue. Like could I make an activity pass some sort of unique ID to the other Activity.
Thanks
Upvotes: 1
Views: 83
Reputation: 508
check if the extra of key is found then do your code like the following
if(getIntent().hasExtra("Name"))
{
//Write your code here
}
Upvotes: 1
Reputation: 1601
Pass a boolean extra from both activity and make that value true for one activity and false for other activity and when you getextra in receiving activity first get that boolean value and than get all other data base on that Key
Intent actA=new Intent(CurrentAct.this, ActivityA.class); //Activity A code
actA.putExtra("Key",true);
startActivity(actA);
Intent actB=new Intent(CurrentAct.this, ActivityB.class); //Activity B code
actB.putExtra("Key",true);
startActivity(actB);
Bundle extras = getIntent().getExtras(); //Receiving Activity Code
boolean mKey=extras.getBoolean("Key");
if(mKey){
//Activity A calling
}else{
//Activity B calling
}
Upvotes: 0