Android活动并未完全关闭

时间:2016-11-28 18:53:56

标签: java android crosswalk-runtime

我有一个我在人行横道上使用的javascript界面​​,它有一个closeActivity方法。界面如下所示:

public class JavaScriptInterface {

    private Activity activity;

    public JavaScriptInterface(Activity activity) {
        this.activity = activity;
    }

    /**
     * Starts a new activity
     * @param page
     * @return
     */
    @JavascriptInterface
    public boolean openActivity(String page){
        if(isConnected()) {
            Intent intent = new Intent(activity, GenericActivity.class);
            intent.putExtra("page", page);
            activity.startActivity(intent);
            return true;
        }
        return false;
    }

    /**
     * Closes the current activity
     */
    @JavascriptInterface
    public void closeActivity(){
        activity.finish();
    }
}

以下是推出的活动:

public class GenericActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_generic);

        Intent intent = getIntent();
        String page = intent.getStringExtra("page");

        XWalkView xWalkWebView = (XWalkView)findViewById(R.id.xwalkWebView);

        // Turn on debugging if we are in DEBUG mode
        if (BuildConfig.DEBUG) {
            XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
            xWalkWebView.clearCache(true);
        }

        // Add the connector to talk to/from javascript
        JavaScriptInterface i = new JavaScriptInterface(this);
        xWalkWebView.addJavascriptInterface(i, "jsConnector");

        // Load the base file
        xWalkWebView.loadAppFromManifest("file:///android_asset/manifest.json", null);
        xWalkWebView.loadUrl("file:///android_asset/" + page + ".html", null);
    }
}

当我致电closeActivity时,视觉活动会消失,但在Chrome检查员(chrome://inspect)中,我仍然可以看到人行横道webview。为什么它仍然存在,如何关闭它?

1 个答案:

答案 0 :(得分:0)

哇!这是一个非常简单的解决方案。

在活动中,我只需要像这样添加view.onDestroy()

@Override
public void onDestroy(){
    XWalkView view = (XWalkView)findViewById(R.id.xwalkWebView);
    view.onDestroy();
    super.onDestroy();
    finish();
}