Problem implementing OnActivityResultHandler

Trying to deploy the sample code in post http://forums.coronalabs.com/topic/37282-how-can-one-capture-cameragallery-return-result-in-android-native-code/

Gives the error.

unregisterActivityResultHandler(com.mycompany.simpleluaextension.CallLuaFunction)

    [javac] location: class com.ansca.corona.CoronaActivity

    [javac]             activity.unregisterActivityResultHandler(this);

    [javac]                     ^

    [javac] /Users/xxxxx/xxxxx/xxxx/xxxx/xxxx/android/src/com/mycompany/simpleluaextension/CallLuaFunction.java:112: method does not override or implement a method from a supertype

    [javac]         @Override

    [javac]         ^

    [javac] 4 errors

¿Not implementing the interface CoronaActivity.OnActivityResultHandler?

¿Why?

You likely haven’t imported the CoronaActivity class in your code.  You can solve it by doing one of the following:

  1. Add “import com.ansca.corona.CoronaActivity;” to the top of your Java file.

  2. Instead of importing, you can type out the fully qualified class name in your code by replacing “CoronaActivity” with “com.ansca.corona.CoronaActivity”.

Also, make sure that you are at least using the last release version of Corona Enterprise.

Thanks Joshua,

The example works fine.

Another question6,

How I can return the value from Android to LUA?

I retrieve the value in 

public void onHandleActivityResult(
CoronaActivity activity, int requestCode, int resultCode, android.content.Intent data)
{
// Unregister this handler.
activity.unregisterActivityResultHandler(this);

// Handle the result…
}

Have a look at the “AsyncCallLuaFunction.java” file under the following directory in Corona Enterprise…

   ./CoronaEnterprise/Samples/SimpleLuaExtensions/android/src/…

That Java file shows you how to get back to the Lua thread from the main UI thread and then call a Lua function, which is what you need to do.  Remember that Lua on Android does not run on the main UI thread.  So, you must never access the LuaState object from another thread or else random crashes will occur.  That sample code shows you how to get back to the Lua thread safely using our CoronaRuntimeTaskDispatcher class in Java.

   http://docs.coronalabs.com/daily/native/android/html/com/ansca/corona/CoronaRuntimeTaskDispatcher.html

Also, that same sample project has many other Java files that shows you how to read Lua values from Java and how to push Java values into Lua.  That sample project effectively teaches you the fundamentals on how to use the LuaState in Java and should contain all of the answers that you need.  It’s very well commented.  We also have the LuaState Java class documented here…

   http://docs.coronalabs.com/daily/native/android/html/com/naef/jnlua/LuaState.html

I hope this helps!

You likely haven’t imported the CoronaActivity class in your code.  You can solve it by doing one of the following:

  1. Add “import com.ansca.corona.CoronaActivity;” to the top of your Java file.

  2. Instead of importing, you can type out the fully qualified class name in your code by replacing “CoronaActivity” with “com.ansca.corona.CoronaActivity”.

Also, make sure that you are at least using the last release version of Corona Enterprise.

Thanks Joshua,

The example works fine.

Another question6,

How I can return the value from Android to LUA?

I retrieve the value in 

public void onHandleActivityResult(
CoronaActivity activity, int requestCode, int resultCode, android.content.Intent data)
{
// Unregister this handler.
activity.unregisterActivityResultHandler(this);

// Handle the result…
}

Have a look at the “AsyncCallLuaFunction.java” file under the following directory in Corona Enterprise…

   ./CoronaEnterprise/Samples/SimpleLuaExtensions/android/src/…

That Java file shows you how to get back to the Lua thread from the main UI thread and then call a Lua function, which is what you need to do.  Remember that Lua on Android does not run on the main UI thread.  So, you must never access the LuaState object from another thread or else random crashes will occur.  That sample code shows you how to get back to the Lua thread safely using our CoronaRuntimeTaskDispatcher class in Java.

   http://docs.coronalabs.com/daily/native/android/html/com/ansca/corona/CoronaRuntimeTaskDispatcher.html

Also, that same sample project has many other Java files that shows you how to read Lua values from Java and how to push Java values into Lua.  That sample project effectively teaches you the fundamentals on how to use the LuaState in Java and should contain all of the answers that you need.  It’s very well commented.  We also have the LuaState Java class documented here…

   http://docs.coronalabs.com/daily/native/android/html/com/naef/jnlua/LuaState.html

I hope this helps!