Activity Starter AFTER ACTIVITY

45 views
Skip to first unread message

Steve Marcus

unread,
Jul 17, 2013, 12:27:23 PM7/17/13
to alternate-java-bridg...@googlegroups.com
Hi there,

I want to do something after the activity starter returns a result. 

Is there something like Events.AFTER_ACTIVITY I can register? I want to mimic the App Inventor block ActivityStarter.AfterActivity. 

Thanks,

S

Imp Inc

unread,
Jul 17, 2013, 1:35:24 PM7/17/13
to alternate-java-bridg...@googlegroups.com
You can just use "AfterActivity" for now. It's not in the Events class at the moment, but will be there in the next update, which I hope to get out soon.

Ryan

Steve Marcus

unread,
Jul 18, 2013, 8:34:18 AM7/18/13
to alternate-java-bridg...@googlegroups.com
Thanks. Ah yes I found AfterActivity, but I'm not sure how to implement it. Anyone care to post a quick rough example code?

Brian Cohen

unread,
Jul 18, 2013, 8:37:47 AM7/18/13
to alternate-java-bridg...@googlegroups.com
I'm actually curious myself.  I am trying to picture how this would work and it doesn't seem to make much sense to me.  Curious to see how others are using it.

Imp Inc

unread,
Jul 18, 2013, 10:19:03 AM7/18/13
to alternate-java-bridg...@googlegroups.com
Just like any other event. Instead of using something like Events.CLICK, you'd use "AfterActivity".

if (component.equals(actStarter) && eventName.equals("AfterActivity") {
  dostuff();
}

What is it you are trying to do?

Ryan


On Thursday, July 18, 2013 8:34:18 AM UTC-4, Steve Marcus wrote:

Brian Cohen

unread,
Jul 18, 2013, 10:55:05 AM7/18/13
to alternate-java-bridg...@googlegroups.com
Well I can't speak for Steve.  But personally, I was curious as to exactly WHEN that event gets triggered.

For example, if the activity starter is launching another activity, does the event get triggered right after that activity launches?  if so, how does that work, because wouldn't the focus be on the new activity, so how can it still run code from the old activity?  

Steve Marcus

unread,
Jul 18, 2013, 11:45:36 AM7/18/13
to alternate-java-bridg...@googlegroups.com
Hooray I got it to work. I wanted it to open another app and return a String as a result. For the result I put args[0].toString() as the result object and it worked.

ActivityStarter as;
as = new ActivityStarter(this);

 EventDispatcher.registerEventForDelegation(this, "AfterActivity", "AfterActivity");

if (component.equals(as) && eventName.equals("AfterActivity")) {
    doAfterActivity(args[0].toString());
    return true;
    }


Then

 private void doAfterActivity(String result) {
notifier1.ShowAlert(result);
}

Displays a notification with the String returned from the other app! Thanks for the help.

Brian, it seems it is triggered after the activity starter has returned the result to the starting activity.

Imp Inc

unread,
Jul 18, 2013, 12:22:43 PM7/18/13
to alternate-java-bridg...@googlegroups.com
Brian,

 The activity starter is just using intents. The After Activity event is thrown inside the onActivityResult method. If you don't use Activity Starter, you can use the FORM_RESULT event to capture the return in onActivityResult method. Note that any component that registers for the onActivityResult method will handle the event on it's own, so, FORM_RESULT will NOT be thrown if one is using ActivityStarter to get results from other activities. However, if you just use intents (by using the startActivityForResult() method), you will need to capture the FORM_RESULT event for the return. (Or you can override the onActivityResult method).

I hope that made some sense, heh.

- Ryan
Reply all
Reply to author
Forward
0 new messages