2
votes

Does wlcommoninit get called when the app is reloaded using WL.Client.reloadApp??

I have a user logout function in a hybrid app. After logout, there is a call to reloadApp() method for WL.Client. It seems after reloading the wlcommoninit is not being called. It does get called if I kill the app and re-start it.

The MobileFirst version we're working with is 7.1. Added: There is a Cordova.js error in the logs which may be preventing the wlCommonInit() from being called after logout + reloadApp:

12-28 16:52:18.354: I/chromium(9539): [INFO:CONSOLE(309)] "Error in Success callbackId: App414539960 : Error: Unknown event action undefined", source: file:///android_asset/www/default/worklight/cordova.js (309)

12-28 16:52:18.354: I/chromium(9539): [INFO:CONSOLE(1576)] "Uncaught (in promise) Error: Unknown event action undefined", source: file:///android_asset/www/default/worklight/cordova.js (1576)

2

2 Answers

0
votes

You don't mention what version of MobileFirst Platform Foundation (or Worklight) you are using, but I'm not sure it actually matters in this case.

I just tested on 7.1, and confirmed that wlCommonInit() is in fact called when you reload the app with WL.Client.reloadApp().

I did this by taking the sample "Hello MobileFirst" app (the template that is automatically created when you create a new MobileFirst Platform hybrid app), adding this to the index.html file:

<a onClick="WL.Client.reloadApp();">Click Me</a>

and then adding this inside wlCommonInit():

alert("init");

The alert is displayed when the app first initializes, and is also displayed when you click the "Click Me" link in the app, confirming that wlCommonInit() is being called in that case.

I didn't try this on any actual devices, but I tried it in preview for Common Resources and Android environment, and also tried it in Desktop Browser environment, and got the same result in all three places.

If you can edit your question to provide more information (such as, maybe, a link to your actual MFP project, and/or what you have observed that leads you to believe that wlCommonInit() isn't being called), a more useful answer could be provided. But, as far as the specific question you've asked - yes, wlCommonInit() is definitely called when you invoke WL.Client.reloadApp().

0
votes

I had the same issue on my side, but I think this was my fault. My android/res/xml/config.xml file had been migrated successfully by the migration script to include the latest required MobileFirst plugins, but I had it excluded from my source repository so I hadn't checked in the latest version and was still using the old version in my app. Once I manually copied a correctly migrated config.xml everything worked correctly.

Can you verify that your config.xml contains all of the required MobileFirst plugins for Android. Here's my example config.xml that works for me.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
--><widget xmlns="http://www.w3.org/ns/widgets" id="PluginDevelopment" version="1.0.0.0">
    <name>PluginDevelopment</name>

    <description>
        PluginDevelopment
    </description>

    <author email="application author's e-mail" href="http://mycompany.com">
        application's author
    </author>

    <access origin="*"/>
    <preference name="loglevel" value="DEBUG"/>
    <!--
      <preference name="splashscreen" value="resourceName" />
      <preference name="backgroundColor" value="0xFFF" />
      <preference name="loadUrlTimeoutValue" value="20000" />
      <preference name="InAppBrowserStorageEnabled" value="true" />
      <preference name="disallowOverscroll" value="true" />
    -->
    <!-- This is required for native Android hooks -->
    <feature name="App">
        <param name="android-package" value="org.apache.cordova.App"/>
    </feature>
    <feature name="Device">
        <param name="android-package" value="org.apache.cordova.device.Device"/>
    </feature>
    <feature name="Accelerometer">
        <param name="android-package" value="org.apache.cordova.devicemotion.AccelListener"/>
    </feature>
    <feature name="Compass">
        <param name="android-package" value="org.apache.cordova.deviceorientation.CompassListener"/>
    </feature>
    <feature name="Media">
        <param name="android-package" value="org.apache.cordova.media.AudioHandler"/>
    </feature>         
    <feature name="Camera">
        <param name="android-package" value="org.apache.cordova.camera.CameraLauncher"/>
    </feature>
    <feature name="Contacts">
        <param name="android-package" value="org.apache.cordova.contacts.ContactManager"/>
    </feature>
    <feature name="File">
        <param name="android-package" value="org.apache.cordova.file.FileUtils"/>
    </feature>
    <feature name="Notification">
        <param name="android-package" value="org.apache.cordova.dialogs.Notification"/>
    </feature>    
    <feature name="FileTransfer">
        <param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer"/>
    </feature>
    <feature name="Capture">
        <param name="android-package" value="org.apache.cordova.mediacapture.Capture"/>
    </feature>
    <feature name="Battery">
        <param name="android-package" value="org.apache.cordova.batterystatus.BatteryListener"/>
    </feature>
    <feature name="SplashScreen">
        <param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen"/>
    </feature> 
    <feature name="Globalization">
        <param name="android-package" value="org.apache.cordova.globalization.Globalization"/>
    </feature>
    <feature name="InAppBrowser">
        <param name="android-package" value="org.apache.cordova.inappbrowser.InAppBrowser"/>
    </feature>    
    <feature name="Vibration">
        <param name="android-package" value="org.apache.cordova.vibration.Vibration"/>
    </feature>

<feature name="WLInitializationPlugin">
        <param name="android-package" value="com.worklight.androidgap.plugin.WLInitializationPlugin"/>
        <param name="onload" value="true"/>
    </feature>
    <feature name="UserAuth">
        <param name="android-package" value="com.worklight.androidgap.plugin.UserAuthPlugin"/>
        <param name="onload" value="false"/>
    </feature>
    <feature name="LoggerPlugin">
        <param name="android-package" value="com.worklight.androidgap.plugin.LoggerPlugin"/>
    </feature>
    <feature name="WLApp">
        <param name="android-package" value="com.worklight.androidgap.plugin.WLApp"/>
    </feature>
    <feature name="NativePage">
        <param name="android-package" value="com.worklight.androidgap.plugin.NativePage"/>
    </feature>
    <feature name="NativeBusyIndicator">
        <param name="android-package" value="com.worklight.androidgap.plugin.BusyIndicator"/>
    </feature>
    <feature name="SecurityPlugin">
        <param name="android-package" value="com.worklight.androidgap.plugin.SecurityPlugin"/>
    </feature>
    <feature name="StoragePlugin">
        <param name="android-package" value="com.worklight.androidgap.plugin.StoragePlugin"/>
    </feature>
    <feature name="Push">
        <param name="android-package" value="com.worklight.androidgap.plugin.Push"/>
    </feature>
    <feature name="WebResourcesDownloader">
        <param name="android-package" value="com.worklight.androidgap.plugin.WebResourcesDownloaderPlugin"/>
    </feature>
    <feature name="WLDirectUpdatePlugin">
        <param name="android-package" value="com.worklight.androidgap.plugin.WLDirectUpdatePlugin"/>
    </feature>
    <feature name="NetworkDetector">
        <param name="android-package" value="com.worklight.androidgap.plugin.NetworkDetector"/>
    </feature>
    <feature name="DeviceAuth">
        <param name="android-package" value="com.worklight.androidgap.plugin.DeviceAuthPlugin"/>
    </feature>
    <feature name="WifiPlugin">
        <param name="android-package" value="com.worklight.androidgap.plugin.WifiPlugin"/>
    </feature>
    <feature name="WLGeolocationPlugin">
        <param name="android-package" value="com.worklight.androidgap.plugin.WLGeolocationPlugin"/>
    </feature>
    <feature name="ForegroundBinderPlugin">
        <param name="android-package" value="com.worklight.androidgap.plugin.ForegroundBinderPlugin"/>
    </feature>
    <feature name="FIPSHttpPlugin">
        <param name="android-package" value="com.worklight.androidgap.plugin.FIPSHttpPlugin"/>
    </feature>
    <feature name="WLCustomDialog">
        <param name="android-package" value="com.worklight.androidgap.plugin.WLCustomDialog"/>
    </feature>
    <feature name="NetworkStatus">
        <param name="android-package" value="com.worklight.androidgap.plugin.WLNetworkManager"/>
    </feature>
    <feature name="WLSplashScreen">
        <param name="android-package" value="com.worklight.androidgap.plugin.WLSplashScreenPlugin"/>
    </feature>
    <feature name="WLNativeXHRPlugin">
        <param name="android-package" value="com.worklight.androidgap.plugin.WLNativeXHRPlugin"/>
    </feature>
    <feature name="WLActionSenderPlugin">
        <param name="android-package" value="com.worklight.androidgap.plugin.WLActionSenderPlugin"/>
    </feature>
    <feature name="StatusBar">
        <param name="android-package" value="org.apache.cordova.statusbar.StatusBar"/>
    </feature>
    <feature name="WLAuthorizationManagerPlugin">
        <param name="android-package" value="com.worklight.androidgap.plugin.WLAuthorizationManagerPlugin"/>
    </feature>
    <feature name="WLCertificatePinningPlugin">
        <param name="android-package" value="com.worklight.androidgap.plugin.WLCertificatePinningPlugin"/>
    </feature
</widget>