简体   繁体   English

使用自己的插件后,Cordova后退按钮会破坏CordovaActivity

[英]Cordova backbutton destroy the CordovaActivity after use own plugin

I develop a cordova plugin that can create a file container for pdf. 我开发了一个cordova插件,可以为pdf创建文件容器。 My Plugin have the functions enterFullscreen() and exitFUllscreen() . 我的插件具有功能enterFullscreen()exitFUllscreen() If i switch to Fullscreen and want back to defaut file container i want use the backbutton for this, but if i press the backbutton the app close. 如果我切换到“全屏”并想返回到默认文件容器,则需要使用后退按钮,但是如果我按下后退按钮,则应用程序关闭。 In my logcat i get this message: 在我的logcat中,我收到以下消息:

在此处输入图片说明

Here is my plugin code: java 这是我的插件代码:java

/**
 * Enters the fullscreen mode of a Container.
 *
 * @param {Container} _container The Container which should enter the fullscreen mode.
 * @param {boolean} _enableFullscreen True for enabling fullscreen mode, false for disabling.
 */
private void setContainerFullscreen(final Container _container,final boolean _enableFullscreen)
{
    Log.d(LOGTAG,"FileViewer -> enterFullscreen of container with id: " + _container.id());

    this.cordova.getActivity().runOnUiThread(new Runnable()
    {
        @Override
        public void run()
        {
            _container.enableFullscreen(_enableFullscreen);

            FrameLayout containerLayout = _container.containerFrameLayout();

            /* first we must call removeView() then addView(), because the updateView() function don't work with fullscreen mode.
            //todo I must check this later.
            call a exception.*/
            mainLayout.removeView(containerLayout);
            mainLayout.addView(containerLayout,containerLayout.getLayoutParams());
        }
    });
}

here the container class 这里是容器类

/**
 * Enables fullscreen mode for this Container.
 *
 * @param {boolean} _enable True for enabling fullscreen mode, false for disabling.
 */
public void enableFullscreen(boolean _enable)
{
    this.isFullscreen = _enable;

    if (this.isFullscreen && this.isVisible)
    {   // Sets the size of the parentlayout to fullscreen.
        this.containerFrameLayout.setLayoutParams(mainLayout.getLayoutParams());
        this.enableToolbar(true);
    }
    else if (!this.isFullscreen && this.isVisible)
    {   // Sets the size back to the values before it went into fullscreen mode.
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(this.containerRect.right-this.containerRect.left,this.containerRect.bottom-this.containerRect.top);
        layoutParams.leftMargin = this.containerRect.left;
        layoutParams.topMargin = this.containerRect.top;
        layoutParams.gravity = 0;

        this.containerFrameLayout.setLayoutParams(layoutParams);
        this.enableToolbar(false);
    }
}

Here is the javascript code: 这是JavaScript代码:

// backbutton support for android in fullscreen mode
document.addEventListener("backbutton", Ext.bind(function(_event){
    if (this.fullScreen)
    {
        //console.log("We are in fullscreen!");
        this.fileViewerPlugin.exitFullscreen();
        this.fullScreen=false;
        _event.preventDefault();
    }
    else
    {
        navigator.app.exitApp();
    }
},this), false);

What you see is the original behaviour of back-button . 您看到的是back-button的原始行为。 You should override this behaviour using for example this guide . 您应该使用本指南override此行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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