android运行时错误振动

时间:2013-03-08 11:38:56

标签: android runtime-error android-4.0-ice-cream-sandwich

enter image description here 在我的应用中只有2个振动调用

1. Vibration Call 

listView.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, final View view,
                        int position, long id) {
...
    vibrator.vibrate(200);
...}
}

2. Vibration Call    

public void onSensorChanged(SensorEvent event) {
            if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
    }
    ....
//z axes accelerator changes
    long[] pattern = { 0, 200, 200 };
                    vibrator.vibrate(pattern, 3);
    }}

我认为第一个是考虑错误。

我真的没有看到任何错误。

这是我第一次编程振动。

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

目前最好的解决方案是

Handler handler = new Handler();
handler.post(new Runnable() {
        public void run() {
vibrator.vibrate(200);
        }

});
}

应用程序不会崩溃,但振动有时会失败

答案 1 :(得分:-1)

我认为这会起作用

long[] pattern = new long[]{ 0, 200, 200 };
                    vibrator.vibrate(pattern, 3);