parth.hirpara
parth.hirpara

Reputation: 542

Javascript to Android call in worklight

In worklight, I am using WL.NativePage.show for android native call. As I am doing so much process in activity(native), It throws me error "The application may be doing too much work on its main thread".

As resolution I used threading for calculation(so much process) and It is working OK. But In this case, Native page showed up.

But I just want some calculation on input (From JS) in native and output(At JS) without rendering activity.

 ...

    public class EmbeddedCalculator extends Activity {

        public static Boolean isSuccessful = false;
        private Calculation calculation = new Calculation();
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    //  .. calculation - Higher process ..
                }
            };
            Thread t= new Thread(runnable);
            t.start();
        }
    }

Upvotes: 1

Views: 129

Answers (1)

Idan Adar
Idan Adar

Reputation: 44516

Then why use WL.NativePage at all?

Since you did not mention the actual version of Worklight that you are using, I will just list possible alternatives:

  1. Create a Cordova plug-in that will invoke native code and return the result: https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/adding-native-functionality/ - tutorials and samples are available
  2. Use the SendAction APIs to invoke native code (MobileFirst Platform Foundatin 6.3 and above): http://www-01.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.dev.doc/devref/c_action_sender.html

Upvotes: 1

Related Questions