-2

Hi I am creating a MobileFirst Hybrid application and need to launch/call Activity class onCreate() method on index.html page load.

Samra
  • 1,815
  • 4
  • 35
  • 71

3 Answers3

0

Use the SendAction API: https://www.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.dev.doc/devref/t_sending_actions_js_to_native.html

You can call right in wlCommonInit which is called once the MobileFirst SDK has been fully initialized.

Idan Adar
  • 44,156
  • 13
  • 50
  • 89
0
Use this API

main.js


var param = {
              name: "hello"   //parameter pass to activity
            };
WL.NativePage.show("com.xyz.TestActivity", function(data){
        alert("data from activity "+data);
    }, param);

Make TestActivity in pkg com.xyz

TestActivity.java

package com.xyz;
import android.util.Log;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;

public class TestActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);

    String l_name = getIntent().getStringExtra("name");  // way to take   param from js file

    Intent in = new Intent();
    in.putExtra("test", "hello success");  // return data to js from activity
    setResult(RESULT_OK, in);
    finish();
}

}

  AndroidManifest.xml

 <activity android:name=".TestActivity"></activity> 
Praj
  • 117
  • 1
  • 2
  • Thanks! was great help, :).. now i need to call my html page from the native activity, guess WL client is used but not sure how? – Samra Jul 04 '16 at 03:53
  • May be I can explain some more, I have implemented OnActionReceived function in my JS and called it on a listitem click from my native code.WL.getInstance().sendActionToJS("LoadPageReceiver"); Here, WL.getinstance gives java.state.illegalstateexception – Samra Jul 04 '16 at 05:08
  • http://stackoverflow.com/questions/31331579/android-mobilefirst-sending-data-from-native-to-cross-page follow the link (please mark as answered :)) – Praj Jul 05 '16 at 12:48
  • implement "WLActionReceiver" in your activity and it will work. – Praj Jul 05 '16 at 12:51
0

So here is what I did,

Inherited CordovaActivity class instead of Activity class and implemented WLInitWebFrameworkListener. In onInitWebFrameworkComplete event added:

super.loadUrl(WL.getInstance().getMainHtmlFilePath());

Under Oncreate() method added

WL.createInstance(this);
WL.getInstance().initializeWebFramework(getApplicationContext(), this);

and now my SendActionAPI works

Samra
  • 1,815
  • 4
  • 35
  • 71