0
在acquire()
的權利失敗。 Eclipse沒有說錯誤是什麼。它只是停止執行我的模擬器,並給我那個「類文件編輯器」「源找不到」顯示。Android的WakeLocks無法正常工作
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
}
}
}
日誌說什麼? – mach
哪個日誌?我爲我的應用程序過濾的「LogCat」沒有說什麼。我在發生故障之前清除它,然後導致故障,並且LogCat爲空。 –
什麼是「類文件編輯器」「源未找到」?屏幕? 'allocStructs()'叫什麼名字?發佈更多的代碼。編輯:添加@user如果你想_user_被通知你的評論 –