简体   繁体   中英

If I setcontentview in Cordova Plugin, how do I set content view back to cordova?

I am creating a Cordova Android plugin to perform authentication (with Oracle Mobile and Social SDK). When I kick off the authentication method I need to setContentView a view provided by Oracle. Here is how the code looks like:

            View myview = mss.authenticate();
            cordova.getActivity().setContentView(myview);

This is working fine. The Oracle's authentication screen comes up and I can enter my credentials. But when I am done I don't know how to switch back to the Cordova view (back to my index.html). I am able to set callback context status correctly and able to send back message to JavaScript which can throw an alert. However the screen is stuck at the authentication screen. I would like to go back to the index.html page.

Any guidance on this is greatly appreciated.

Thanks!

You can copy a function from the cordova-plugin-splashscreen repo at https://github.com/apache/cordova-plugin-splashscreen/blob/master/src/android/SplashScreen.java

private View getView() {
    try {
        return (View)webView.getClass().getMethod("getView").invoke(webView);
    } catch (Exception e) {
        return (View)webView;
    }
}

To go back to the Cordova web view you can then do:

cordova.getActivity().setContentView(getView());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM