就在acquire()
它失败了。Eclipse 没有说明错误是什么。它只是停止在我的模拟器上执行,并显示“类文件编辑器”“找不到源”。
public class MyAppActivity extends Activity {
private PowerManager pManager;
private PowerManager.WakeLock wakeLock;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.main);
allocStructs();
}
private void allocStructs() {
// I've tried this with "getBaseContext()" and with "this"
// same results. I get a pManager and a wakeLock
// Then it crashes when I attempt to acquire
pManager = (PowerManager)getBaseContext().getSystemService(
Context.POWER_SERVICE);
wakeLock = pManager.newWakeLock(
PowerManager.FULL_WAKE_LOCK, "full");
}
public void onWakeLockButtonClicked(View view) {
boolean checked = ((RadioButton) view).isChecked();
if (!checked) {
return;
}
if (!wakeLock.isHeld()) {
wakeLock.acquire(); // fails here
}
}
}