tags:

views:

20

answers:

1

I create an Intent in one class then it's returned to another class. I need to check the type of intent it is. I need to ensure it's not a specific class of intent.

How to do this?

if( newIntent == ActivityName.class )

Edit: So I would need to know if the new intent would equal an intent of a certain type:

newIntent = new Intent(context, ActivityName.class);
return newIntent;

In another class:

if( newIntent == ActivityName.class ) // do something

Hope this clarifies a bit.

A: 

If you're just trying to check what type the intent is (or any java object for that matter) use

if (newIntent instanceof ActivityName){
  //do stuff
}

However, I suspect this isn't what you're actually looking to do. Regardless of what activity you create an Intent in, it is always an instance of the Intent class. That is, of course, unless you have explicitly created a subclass of the Intent class. Can you tell us a little more about what you're trying to do?

Chris Thompson
After the intent is created, it's returned. I need to identify the class of the intent. E.g., newIntent = new Intent(context, ActivityName.class); I need to check for the specific ActivityName.
just_another_coder
@just_another_coder, Check out the `getComponent()` method as described here: http://developer.android.com/guide/topics/intents/intents-filters.html
Chris Thompson
getComponent().getClassName() or getShortclassName() works but the string that is returned needs to be compared with either the fully qualified name or the class itself with a leading dot. Thank Chris
just_another_coder