Skip to main content
Vrvy
Participant
March 10, 2014
Question

[Android] Getting onActivityResult and onStart/onPause/.... events from AIR activity [solution]

  • March 10, 2014
  • 6 replies
  • 7256 views

Hi,

I struggled for a while with this issue and finally found a solution. I haven't seen it posted anywhere so I thought I would share it here.

  • In ANE extension's native java project, we include runtimeClasses.jar from AIR's lib folder (AIR\lib\android\lib), along with FlashRuntimeExtension.jar. This gives us access to AIR's AndroidActivityWrapper class.
  • Since some interfaces in runtimeClasses are defined as protected, we need to make them accessible to our extension. So we create two interfaces in com.adobe.air package namespace:

ActivityResultCallback.java


package com.adobe.air;

import com.adobe.air.AndroidActivityWrapper;

public abstract interface ActivityResultCallback extends AndroidActivityWrapper.ActivityResultCallback

{

}

StateChangeCallback.java

package com.adobe.air;

import com.adobe.air.AndroidActivityWrapper;

public abstract interface StateChangeCallback extends AndroidActivityWrapper.StateChangeCallback

{

}

  • We can now register some callbacks in our extension:

ExtensionContext.java

package com.company.extension;

import java.util.HashMap;

import java.util.Map;

import android.content.Intent;

import android.content.res.Configuration;

import com.adobe.air.ActivityResultCallback;

import com.adobe.air.AndroidActivityWrapper;

import com.adobe.air.AndroidActivityWrapper.ActivityState;

import com.adobe.air.StateChangeCallback;

import com.adobe.fre.FREContext;

import com.adobe.fre.FREFunction;

public class ExtensionContext extends FREContext implements ActivityResultCallback, StateChangeCallback

{

    private AndroidActivityWrapper aaw;

    public ExtensionContext() {

        aaw = AndroidActivityWrapper.GetAndroidActivityWrapper();

        aaw.addActivityResultListener( this );

        aaw.addActivityStateChangeListner( this );

    }

   

    @Override

    public void onActivityResult(int requestCode, int resultCode, Intent intent ) {

    }

    @Override

    public void onActivityStateChanged( ActivityState state ) {

        switch ( state ) {

            case STARTED:

            case RESTARTED:

            case RESUMED:

            case PAUSED:

            case STOPPED:

            case DESTROYED:

        }

    }

    @Override

    public void onConfigurationChanged(Configuration paramConfiguration) {

    }

    @Override

    public Map<String, FREFunction> getFunctions() {

        Map<String, FREFunction> functionMap = new HashMap<String, FREFunction>();

        return functionMap;

    }

    @Override

    public void dispose() {

        if (aaw!=null) {

            aaw.removeActivityResultListener( this );

            aaw.removeActivityStateChangeListner( this );

            aaw = null;

        }

    }

}

  • I hope this helps anyone.
This topic has been closed for replies.

6 replies

Participant
June 12, 2016

How can I override "onKeyDown" method?

lagoon_bbo
Known Participant
February 13, 2015

Can you provide the ANE ?

fransJeff
Participant
February 13, 2015

can you provide a sample working project

Participant
July 5, 2014

Thanks,

This path was looking promising

But for me, the Application crash

Do i need to add this Jar manually?

Inspiring
May 7, 2014

Finally I had to remove onActivityOnResult implementation because in FB 4.7 the ANE worked fine on debug but I was not able to get in run on release version . I tried even adding the runtimeClasses.jar manually to the ANE package but it simply did not work. See below error from adb logcat

I/NativeAlert(14030): initialize

I/dalvikvm(14030): Failed resolving Lcom/adobe/air/ActivityResultCallback; interface 76 'Lcom/adobe/air/AndroidActivityWrapper$ActivityResultCallback;'

W/dalvikvm(14030): Link of class 'Lcom/adobe/air/ActivityResultCallback;' failed

I/dalvikvm(14030): Failed resolving Lcom/delcasda/contactsANEext/selectContacts; interface 75 'Lcom/adobe/air/ActivityResultCallback;'

W/dalvikvm(14030): Link of class 'Lcom/delcasda/contactsANEext/selectContacts;' failed

E/dalvikvm(14030): Could not find class 'com.delcasda.contactsANEext.selectContacts', referenced from method com.delcasda.contactsANEext.ContactANEContext.getFunctions

W/dalvikvm(14030): VFY: unable to resolve new-instance 128 (Lcom/delcasda/contactsANEext/selectContacts;) in Lcom/delcasda/contactsANEext/ContactANEContext;

D/dalvikvm(14030): VFY: replacing opcode 0x22 at 0x004d

I/dalvikvm(14030): Failed resolving Lcom/adobe/air/ActivityResultCallback; interface 76 'Lcom/adobe/air/AndroidActivityWrapper$ActivityResultCallback;'

W/dalvikvm(14030): Link of class 'Lcom/adobe/air/ActivityResultCallback;' failed

I/dalvikvm(14030): Failed resolving Lcom/delcasda/contactsANEext/selectContacts; interface 75 'Lcom/adobe/air/ActivityResultCallback;'

W/dalvikvm(14030): Link of class 'Lcom/delcasda/contactsANEext/selectContacts;' failed

D/dalvikvm(14030): DexOpt: unable to opt direct call 0x01c1 at 0x4f in Lcom/delcasda/contactsANEext/ContactANEContext;.getFunctions

W/System.err(14030): java.lang.NoClassDefFoundError: com.delcasda.contactsANEext.selectContacts

W/System.err(14030):    at com.delcasda.contactsANEext.ContactANEContext.getFunctions(ContactANEContext.java:41)

W/System.err(14030):    at com.adobe.fre.FREContext.VisitFunctions(FREContext.java:134)

W/System.err(14030):    at com.adobe.air.customHandler.callTimeoutFunction(Native Method)

W/System.err(14030):    at com.adobe.air.customHandler.callTimeoutFunction(Native Method)

W/System.err(14030):    at com.adobe.air.customHandler.callTimeoutFunction(Native Method)

W/System.err(14030):    at com.adobe.air.customHandler.handleMessage(customHandler.java:22)

W/System.err(14030):    at android.os.Handler.dispatchMessage(Handler.java:99)

W/System.err(14030):    at android.os.Looper.loop(Looper.java:137)

W/System.err(14030):    at android.app.ActivityThread.main(ActivityThread.java:5455)

W/System.err(14030):    at java.lang.reflect.Method.invokeNative(Native Method)

W/System.err(14030):    at java.lang.reflect.Method.invoke(Method.java:525)

W/System.err(14030):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)

W/System.err(14030):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

W/System.err(14030):    at dalvik.system.NativeStart.main(Native Method)

Participant
April 8, 2014

Thanks !

Looks very useful

Though im having difficulty creating an ANE build which doesnt crash.

Any advice on what kind of options you used to build the ANE ?

Inspiring
April 25, 2014

I just implemented this on a FREObject call to get result from an activity and works like charm. Thanks for the good stuff