views:

109

answers:

2

Hi there

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

A: 

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

benvd
+1  A: 

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) { ... }
Konstantin Burov
Hi I forgot to add one of the classes already passes an Extra bundle which I was going to retrieve at the other end if a certain activity passed the intent. If I pass an extra from the other class then it overrides the current bundle.
Greenhouse Gases
Not true, you can pass as many extras as you wish. Also in case only one of them passes bundle, why not to make bundle existence to be the defining condition.
Konstantin Burov
One of the classes passes a bundle with the game parameters to the activity in order to rebuild the game from a certain level, the other class needs to pass an integer value to determine the game mode to the activity. Though when I do this it seems the bundle contents are overwritten by the class that last called the intent to start the activity.Perhaps I could pass the name of the calling class as a string in the bundle and use that as a condition actually?!
Greenhouse Gases
You may do so. Also nothing stops you from passing any other identifier within the bundle.
Konstantin Burov