debug javascript in android emulator with phonegap

前端 未结 16 1959
抹茶落季
抹茶落季 2021-01-30 02:45

I am new to phonegap and android development. May I know how can I debug javascript error on the emulator? I have heard about ADB may I know how can I use and install it on wind

16条回答
  •  萌比男神i
    2021-01-30 03:33

    In Eclipse you can add an hook to the android emulator back button and inspect a value on the fly. Add the onBackPressed event manager and call the javascript console from there. From the eclipse debug perspective you will change the value of a String variable to what you want to inspect, and pass it to your app by calling super.loadUrl.

    See the code below. Do not forget to enable the debugging of your application from DDMS view

    public class MyActivity extends DroidGap {
        private String js = "";
        @Override
        public void onBackPressed() {  
            //add a breakpoint to the follow line 
            //and change the value for "js" variable before continuing execution
            super.loadUrl("javascript:console.log(" + js + ")");
            return;
        }
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            super.setBooleanProperty("keepRunning", false);
            super.setIntegerProperty("splashscreen", R.drawable.splash);
            super.loadUrl("file:///android_asset/www/index.html", 20000);
        }
    }
    

提交回复
热议问题