Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Internal sructure. Where is MainActivity Class in Corona Native template?
Started by ysharoiko Feb 03 2019 12:19 AM

2 replies to this topic
main thread mainactivity
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ysharoiko

[GLOBAL: userInfoPane.html]
ysharoiko
  • Observer

  • 18 posts
  • Corona SDK

Hello, please help me find out where is  MainActivity Class in Corona Native template.

I wanted to enable speechrecognition, but it gives me an erorr

 

No pending exception expected: java.lang.RuntimeException: SpeechRecognizer should be used only from the application's main thread'

 

I thought it would be okey to run it in onLoaded method, just before main.lua starts but they say

it is not called on the main thread.

I tried to find any method that 

is called on the main thread

and failed to find any. 

Please, help me to move on.

 

 

 

 

private class CoronaRuntimeEventHandler implements com.ansca.corona.CoronaRuntimeListener {
/**
* Called after the Corona runtime has been created and just before executing the "main.lua" file.
* This is the application's opportunity to register custom APIs into Lua.
* <p>
* Warning! This method is not called on the main thread.
* @param runtime Reference to the CoronaRuntime object that has just been loaded/initialized.
*                Provides a LuaState object that allows the application to extend the Lua API.
*/
@Override
public void onLoaded(com.ansca.corona.CoronaRuntime runtime) {
...SPEECH DOES NOT WORK HERE
}


[TOPIC: post.html]
#2

ysharoiko

[GLOBAL: userInfoPane.html]
ysharoiko
  • Observer

  • 18 posts
  • Corona SDK

Not a trivial case for me.

 

So far found 2 ways here

https://forums.coronalabs.com/topic/69480-sample-code-that-says-warning-this-method-is-not-called-on-the-main-ui-thread/

 

1) 

activity.runOnUiThread(new Runnable() {

    @Override
    public void run() {
.........
    }
});

 

 

But i cannot get not null activity in onLoaded method

 

when i do here 

Activity activity = getActivity();

it is null

 

Maybe i will check other methods, but onLoaded seems to be the most right way

 

 

2) 

import com.ansca.corona.CoronaRuntime

 

CoronaEnvironment.getCoronaActivity().getRuntimeTaskDispatcher().send( new com.ansca.corona.CoronaRuntime() {
@Override
public void executeUsing(com.ansca.corona.CoronaRuntime runtime) {
// // This task's execute() method will be called on the Corona runtime thread, just before rendering a frame.

 

Activity activity = getActivity();

if(activity == null)
{
Log.w("HTTPD", "!!! ZEO TIME NO ACTIVITY FOUND. GOT NULL");
return;
}
android.content.Context mcontext = getApplicationContext(); // for NATIVE APPLICATION
Speech.init(mcontext, getPackageName());
}
} );

 

 

But here i got a tough answer

error: constructor CoronaRuntime in class CoronaRuntime cannot be applied to given types;
required: Context,boolean
found: no arguments
reason: actual and formal argument lists differ in length
 
 
Running it like this
CoronaEnvironment.getCoronaActivity().getRuntimeTaskDispatcher().send( new com.ansca.corona.CoronaRuntime(mcontext) {
 
does not change anything


[TOPIC: post.html]
#3

ysharoiko

[GLOBAL: userInfoPane.html]
ysharoiko
  • Observer

  • 18 posts
  • Corona SDK

Finally got it working!!! 1st way

 

Got not null activity in onStarted and onLoaded method using

 

Activity activity = CoronaEnvironment.getCoronaActivity();

 

activity.runOnUiThread(new Runnable() {
@Override
public void run() {

 

... //MAIN THREAD HERE

}
});

 

 

But unfortunatly has no results on recognition yet :((( 




[topic_controls]
[/topic_controls]