我有这个问题,我想在单击按钮时启动一个活动。我已经完成了,但是当我开始新的活动时,我也想同时停止振动器,这样当旧的活动继续时,我希望振动器停止。我有的代码:
package com.edae;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Btcom extends Activity implements OnClickListener {
private Button bokay;
Vibrator vibe;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_btcom);
bokay = (Button) this.findViewById(R.id.okay);
bokay.setOnClickListener(this);
final Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
int dot = 2000;
long patten[] = {0, dot };
vibe.vibrate(patten, -1);
}
@Override
public void onClick(View v){
Intent openBoot = new Intent(this, Boot.class);
startActivity(openBoot);
super.onPause();
}
}