==================== Problem Description ====================
Here is the code that I shook to implement
Public class yao extends activity implements sensoreventlistener{ edittext tv = (EditText) Findviewbyid (R.ID.EDITTEXT1); button button = (Button) Findviewbyid ( R.id.button1); sensormanager sensormanager = null; vibrator vibrator = null; @Overrideprotected void oncreate (bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main);if ( ANDROID.OS.BUILD.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder (). Permitall (). Build (); strictmode.setthreadpolicy (Policy); } Button.setonclicklistener (New onclicklistener () {@Overridepublic void oNclick (VIEW V) {// todo auto-generated method stubtv.settext ("initial text");} });sensormanager = (Sensormanager) getsystemservice (SENSOR_SERVICE); vibrator = (Vibrator) getsystemservice (Service.vibrator_service);} @Override protected void onpause () { super.onpause (); Sensormanager.unregisterlistener (This); } @Override protected void onresume () { super.onresume (); sensormanager.registerlistener (this, Sensormanager.getdefaultsensor (Sensor.type_accelerometer), sensormanager.sensor_delay_normal); } @Override public void onaccuracychanged (sensor sensor, int Accuracy) { //when the sensor accuracy is changed,do nothing. } @Override public Void onsensorchanged (sensorevent event) { int sensortypE = event.sensor.gettype (); //values[0]:x axis, values[1]:y axis, values[2]:z axis float[] values = event.values; if (Sensortype == sensor.type_accelerometer) { if (Math.Abs (values[0]) > 17 | | math.abs (values[1]) > 17 | | math .abs (values[2]) > 17) {//   LOG.D ("sensor x ", "============ values[0] = " + values[0] );//    LOG.D ("sensor y ", "============ values[1] = " + values[1]);//    LOG.D ("sensor z ", "============ values[2] = " + values[2"); tv.settext ("Shake!!! Successfully"); //shake mobile phone, and then accompanied by vibration hint ~~ vibrator.vibrate ($); } }&nBSP;}}
Why does the program run with a hint that the program is unresponsive and then quits? I read the code on the Internet is so written, where does the problem arise? High distribution, please help the master
==================== Solution 1====================
Control initialization cannot be placed at the top of the
EditText TV = (EditText) Findviewbyid (R.ID.EDITTEXT1); Button button = (button) Findviewbyid (R.id.button1);
This needs to be
Setcontentview (R.layout.activity_main);
Called after
==================== Solution 2====================
It seems that LZ is a novice ah, later to study hard
Reference 1 Floor guoyoulei520 's reply:
control initialization cannot be placed at the top of the
EditText TV = (EditText) Findviewbyid (R.ID.EDITTEXT1); Button button = (button) Findviewbyid (R.id.button1);
This needs to be
Setcontentview (R.layout.activity_main);
Called after
==================== Solution 3====================
Do a lot of computational work in the UI thread.
Android Development shake-shake function