在Android中使用JavaScript更改活动(页面)

5
我有一个应用程序,当JavaScript被触发时应该调用一个活动,
这是我的JavaScript代码,它可以正常工作。
JavaScript接口
private class JsInterface{
    //function that will be called from assets/test.js
     
    public void log(String msg){
        Log.d("MSG FROM JAVASCRIPT", msg);
                
    }

这是我通过点击按钮调用活动的方式:
 Button next = (Button) findViewById(R.id.button1);
    next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), VideoVC.class);
            startActivityForResult(myIntent, 0);
        }
    });

由于我对Android开发还很菜,无法弄清楚如何在我的JsInterface上更改活动

我已经尝试在我的JS接口中:

 Intent myIntent2 = new Intent(JsExampleMain.this, VideoVC.class);
startActivity(myIntent2);

但不喜欢"startActivity(myIntent2);"

如何完成这个简单的任务?

1个回答

3

好的,我已经搞清楚了!哈哈,这让我有点疯狂!

所以我只需要将Intent代码放在我的日志方法中就可以了!

  //javascript interface
     private class JsInterface{
   //function that will be called from assets/test.js
    public void log(String msg){
        Log.d("MSG FROM JAVASCRIPT", msg);
        Log.d("kukusha", "mensaje");
        Intent i = new Intent(JsExampleMain.this,VideoVC.class);    
        startActivity(i); 
    }
 }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接