-4

My activity receives two intent from two different activity.

One intent contains int value with extras and another contains String. I want to distinguish both intent in receiver activity.

Is there any way to check if the received intent has int value in extras or String?

Please don't suggest to use startActivityForResult() to receive multiple intents in same activity.

Yash Sampat
  • 30,051
  • 12
  • 94
  • 120
Apurva
  • 7,871
  • 7
  • 40
  • 59
  • Why down vote? Any explanation could be better. – Apurva Mar 16 '15 at 09:49
  • are you still facing a problem with my answer ? By the way it wasn't me who downvoted you :) – Yash Sampat Mar 16 '15 at 10:23
  • @ZygoteInit I know it's not you down voted, you suggested the use of `hasExtra()` was really nice, but it doesn't solve my issue. I couldn't differentiate between received intents using `hasExtra()` that's why I had to unaccept. Btw I used `startActivityForResult()` to get it done. – Apurva Mar 16 '15 at 10:34
  • I see ... no problem, good for you ... best :) – Yash Sampat Mar 16 '15 at 10:35
  • Have you ever faced [this problem](http://stackoverflow.com/q/30473371/3287204) ? – Yash Sampat May 27 '15 at 09:27
  • @Y.S. yes, once I had same problem, but with linux terminal; searching over the internet I came to know that terminal or any other command line doesn't accept `%20` on behalf of a single space. Simply remove %20 or put `-` *(yes linux terminal accepts `-` for space)* to get rid of that error. – Apurva May 27 '15 at 13:46
  • that's right :) I found that out today the hard way after wasting a lot of time ... got the answer, thanks anyway. – Yash Sampat May 27 '15 at 13:49

1 Answers1

3

I don't think there is a way to differentiate between the datatype of the extras in an Intent. All you have is the hasExtra() method, and with it you can try differentiating between the datatype if you know the name of the extra:

if(intent.hasExtra("number")){
    // int
}else if(intent.hasExtra("name"))
    // string
}
Yash Sampat
  • 30,051
  • 12
  • 94
  • 120