Android后退按钮关闭应用程序

时间:2016-04-19 03:07:01

标签: gluon gluon-mobile

我在WebView中显示本地html文件,该文件是Glisten View的中心节点。当我按下Android后退按钮时,应用程序将关闭,而不是返回上一个视图。当我使用appBar按钮切换到上一个视图时,它工作正常。 我试图将事件过滤器附加到webView和场景,但它没有被触发。

javafxports版本:8.60.6

更新

只有在关注webview时才会出现此问题。

public class ImportHelpPresenter extends BasePresenter {

    @FXML
    private WebView web;

    @Override
    protected void initialize() {
        super.initialize();
        web.setContextMenuEnabled(false);
        loadHelpPage();
    }

    private void loadHelpPage() {
        String htmlContent = null;
        try {
            htmlContent = readContent("importhelp.html");
        } catch (IOException e) {
            e.printStackTrace();
        }

        web.getEngine().loadContent(htmlContent);
    }

    String readContent(String fileName) throws IOException {
        InputStream is = getClass().getResourceAsStream(fileName);

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                line = br.readLine();
            }
            return sb.toString();
        } finally {
            br.close();
        }
    }

    EventHandler<? super KeyEvent> backButtonFilter = evt -> {
        System.out.println(evt);
        if (KeyCode.ESCAPE.equals(evt.getCode())) {
            evt.consume();
            showPreviousView();
        }
    };

    @Override
    protected void onShown() {
        super.onShown();
        web.getScene().addEventFilter(KeyEvent.ANY, backButtonFilter);
        web.addEventFilter(KeyEvent.ANY, backButtonFilter);
    }

    @Override
    protected void onHidden() {
        web.getScene().removeEventFilter(KeyEvent.ANY, backButtonFilter);
        web.removeEventFilter(KeyEvent.ANY, backButtonFilter);
    }
}

logcat的:

04-19 04:49:54.760: V/InternalWebView(11536): WebView added to ViewGroup [x: 0, y: 84 , w: 480 h: 678]
04-19 04:49:54.760: V/InternalWebView(11536): Loading content: <html>
//content omitted
04-19 04:49:54.930: D/webcoreglue(11536): netstack: Memory Cache feature is ON
04-19 04:49:55.070: V/chromium(11536): external/chromium/net/host_resolver_helper/host_resolver_helper.cc:66: [0419/044955:INFO:host_resolver_helper.cc(66)] DNSPreResolver::Init got hostprovider:0x51d36010
04-19 04:49:55.070: V/chromium(11536): external/chromium/net/base/host_resolver_impl.cc:1510: [0419/044955:INFO:host_resolver_impl.cc(1510)] HostResolverImpl::SetPreresolver preresolver:0x51d25d10
04-19 04:49:55.070: D/HostStatisticManager(11536): netstack: DNS Host Prioritization is: ON, Version: 5.0.1
04-19 04:49:55.080: D/(11536): external/chromium/net/socket/tcp_fin_aggregation_factory.cc: libtcpfinaggr.so successfully loaded
04-19 04:49:55.080: D/(11536): external/chromium/net/socket/tcp_fin_aggregation_factory.cc,: TCP Fin Aggregation initializing method was found in libtcpfinaggr.so
04-19 04:49:55.080: D/TCPFinAggregation(11536): netstack: TCPFinAggregation is 1, Version 5.0.1
04-19 04:49:55.080: D/TCPFinAggregation(11536): system property net.tcp.fin.aggregation.wait was set, value: 20
04-19 04:49:55.080: D/TCPFinAggregation(11536): system property net.tcp.fin.aggregation.close was set, value: 300
04-19 04:49:55.080: D/TCPFinAggregation(11536): netstack: CloseUnusedSockets is ON, (TCPFinAggregation), Version 5.0.1
04-19 04:49:55.080: D/TCPFinAggregation(11536): Failed to get network status! received ret: -2
04-19 04:49:55.080: D/Socket_Pool(11536): netstack: CloseUnusedSockets is ON
04-19 04:49:55.080: D/Socket_Pool(11536): netstack: system net.statistics value: 0
04-19 04:49:55.080: D/Socket_Pool(11536): netstack: CloseUnusedSockets is ON
04-19 04:49:55.080: D/Socket_Pool(11536): netstack: system net.statistics value: 0
04-19 04:49:55.090: D/(11536): external/chromium/net/http/http_getzip_factory.cc: libgetzip.so successfully loaded
04-19 04:49:55.090: D/(11536): external/chromium/net/http/http_getzip_factory.cc,: GETzip initializing method was found in libgetzip.so
04-19 04:49:55.090: D/netstack(11536): netstack: Request Priority is ON
04-19 04:49:55.090: D/(11536): netstack: Getzip is: ON, Version: 5.0.1
04-19 04:49:55.180: D/WebKit(11536): ERROR: 
04-19 04:49:55.180: D/WebKit(11536): alias gb18030 maps to GB18030 already, but someone is trying to make it map to GBK
04-19 04:49:55.180: D/WebKit(11536): external/webkit/Source/WebCore/platform/text/TextEncodingRegistry.cpp(152) : void WebCore::checkExistingName(char const*, char const*)
04-19 04:50:00.120: E/dalvikvm(11536): GC_CONCURRENT freed 1207K, 24% free 17251K/22599K, paused 5ms+7ms, total 350ms
04-19 04:50:02.810: D/AudioManager(11536): currentDeviceType = 1
04-19 04:50:02.870: V/FXActivity(11536): onPause
04-19 04:50:03.690: W/IInputConnectionWrapper(11536): showStatusIcon on inactive InputConnection
04-19 04:50:03.770: V/FXEntity(11536): Called Surface destroyed
04-19 04:50:03.780: V/FXActivity native(11536): [JVDBG] SURFACE created native android window at 0x0, surface = 0x0
04-19 04:50:03.790: I/GLASS(11536): Native code is notified that surface has changed (repaintall)!
04-19 04:50:04.210: W/ManagedEGLContext(11536): doTerminate failed: EGL count is 2 but managed count is 1
04-19 04:50:04.210: V/FXActivity(11536): onStop
04-19 04:50:04.210: V/FXActivity(11536): onDestroy

0 个答案:

没有答案