任何人都可以帮忙
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class FlashLightActivity extends Activity {
Button main;
//flag to detect flash is on or off
private boolean isLighOn = false;
private Camera camera;
private Button button;
@Override
protected void onStop() {
super.onStop();
if (camera != null) {
camera.release();
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
这里的问题
main=(Button)this.findViewById(R.id.main);
main.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(FlashLightActivity.this, "main",Toast.LENGTH_LONG).show();
Intent myinIntent=new Intent(v.getContext(),MainMenu.class);
startActivity(myinIntent);
//this.finish();
}
});
This Work will
button = (Button) findViewById(R.id.buttonFlashlight);
Context context = this;
PackageManager pm = context.getPackageManager();
// if device support camera?
if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Log.e("err", "Device has no camera!");
return;
}
camera = Camera.open();
final Parameters p = camera.getParameters();
button.setOnClickListener(new OnClickListener() {
flash work here
@Override
public void onClick(View arg0) {
if (isLighOn) {
Log.i("info", "torch is turn off!");
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
camera.stopPreview();
isLighOn = false;
} else {
Log.i("info", "torch is turn on!");
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
camera.startPreview();
isLighOn = true;
}
}
});
}
}
不是所有的活动都有在按下BACK键时被销毁的行为。当用户开始在音乐应用程序中播放音乐,然后按后退键,应用程序覆盖正常的后退行为,防止播放器活动被破坏,并继续播放音乐,即使它的活动不再可见
尝试替换:-
Intent myinIntent=new Intent(v.getContext(),MainMenu.class);
Intent myinIntent=new Intent(this,MainMenu.class);