Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve the activity requested by an Intent

Say I have an Intent like this:

 Intent intent = new Intent(context, MyActivity.class);

I then want a method that will return true for the following:

 boolean found = intent.getSomeMethodToRetrieveActivity() instanceof MyActivity;

Basically is there any way to find out what Activity the intent resolves to?

any ideas?

EDIT

Perusing the src I can see I can get the class name like this:

 intent.getComponent().getClassName()

which will return "com.my.package.MyActivity" which is close but I'd like to use instanceof

like image 364
Blundell Avatar asked Feb 01 '12 10:02

Blundell


People also ask

How do I get activity intent?

To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo.

How do I get data from startActivityForResult?

First you use startActivityForResult() with parameters in the first Activity and if you want to send data from the second Activity to first Activity then pass the value using Intent with the setResult() method and get that data inside the onActivityResult() method in the first Activity .


1 Answers

I just ended up using equals() like in my question with:

 intent.getComponent().getClassName()
like image 57
Blundell Avatar answered Sep 18 '22 18:09

Blundell