Darius
Darius

Reputation: 5259

Using the IF statement to see what intent started the activity - ANDROID

Hopefully this is very simple.

I have a central activity that can be launched from two separate classes. I was hoping that in this central activity I could have an IF statement like

if(this.getIntent() == MainMenu.class)
{ 
 // Do something here
}

But obviously that isn't legal so how could I structure an expression to check from what class an intent was started.

Many thanks

Upvotes: 2

Views: 2101

Answers (2)

Konstantin Burov
Konstantin Burov

Reputation: 69228

I think you may put a parameter into intent and then just compare against that (following is pseudocode):

intent.putExtra("starter", 1)

and then just compare in your central activity:

if (intent.getIntExtra("starter") == 1) { ... }

Upvotes: 2

benvd
benvd

Reputation: 5784

Why don't you pass something along as an extra using Intent#putExtra and then retrieve it in the central activity using Intent#getExtra?

Upvotes: 0

Related Questions