0

WL.App.close is deprecated. I know that this is not supported for iOS. But why is it deprecated for Android as well? At the moment, it is still functioning fine, even on 6.2, but since it is deprecated, what is the alternative/substitute for this?

psyntium
  • 147
  • 12

2 Answers2

1

In Android as well, this is not the recommended approach. You should let the user quit the app, and this is done by manually bringing up the "applications view" and swiping the app in order to quit it.

Can be corroborated by these answers by Googlers:
http://android.nextapp.com/site/fx/doc/exit

Additionally, there are these approaches:

You could write a Cordova plug-in that will force-quit the app and trigger it by overriding whatever you'd like (like the Back button), or create a dedicated Quit button, etc.

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • what about minimizing the app? something like the default behavior of the back button. Natively, I think it should be moveTaskToBack(true). Is this the only way at the moment? – psyntium Jul 17 '14 at 04:50
  • 1
    There is never a Worklight API for this; whatever Google provides, that's what you can use. – Idan Adar Jul 17 '14 at 04:51
  • @IdanAdar I try it and it works fine in MFP 7.0 indeed – Sam Su Sep 02 '15 at 07:05
1

In MobileFirst 7.0, this method seems to be deprecated in both iOS and Android, but when I call this "deprecated" method in Android, it really works.

I think overriding Android's back button might be a best practice in Android webapp as back button may cause strange page navigating issues (if you use UI frameworks like JQM). This is what I done in WL's main.js.

WL.App.overrideBackButton(backFunc);
function backFunc(){
    WL.SimpleDialog.show(
        "Alert", 
        "Sure to quit the app ?", 
        [ {text : 'Cancel', handler: function() {
        }},
        {text : 'Yes', handler: function() {
            if(WL.Client.getEnvironment() == WL.Environment.ANDROID) {
                WL.App.close();
            }
        }}]
    );
}
Sam Su
  • 6,532
  • 8
  • 39
  • 80