Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling onActivityResult from outside the Activity

I'm trying to make a helper class to start an Activity and get the return result (startActivityForResult) to avoid developers writing their own onActivityResult code and encapsulate the complex internal details.

ie: the caller's code:

MyIntent i = new MyIntent();
i.getMyData(new OnData() { public void onData(Bundle data) {....} );

I tried creating a "dummy" Activity inside MyIntent just to be able to override onActivityResult, but the activity needs to be declared in the manifest, which is what the helper class tries to avoid. There is no "setOnActivityResult" which would be a good alternative.

So, how to create an Activity programmatically and "attach" it so it has valid state?

After creating new Activity() I'd like to call the Activity "attach" which is internal.

like image 905
David Berneda Avatar asked Feb 15 '11 09:02

David Berneda


1 Answers

So, how to create an Activity programmatically and "attach" it so it has valid state?

That is not possible, sorry.

I'm trying to make a helper class to start an Activity and get the return result (startActivityForResult) to avoid developers writing their own onActivityResult code and encapsulate the complex internal details.

That is not possible, sorry. The closest you can get is how the Barcode Scanner integration JAR works -- you delegate onActivityResult() to them to decode the result obtained from the scanner activity.

like image 167
CommonsWare Avatar answered Oct 19 '22 05:10

CommonsWare