我从来没有做过很多Java编程,大部分都是PHP / RUBY / Javascript,所以我不确定如何从wLock.release()访问onDestroy

public class SlammedNavigatorActivity extends DroidGap {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.loadUrl("file:///android_asset/www/index.html");

        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock wLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "SN Wake Lock");
        wLock.acquire();
    }

    public void onDestroy() {
        wLock.release();
    }
}

最佳答案

您应该将局部变量wLock转换为私有字段:

public class SlammedNavigatorActivity extends DroidGap {
  private PowerManager.WakeLock wLock;


  public void onCreate(Bundle savedInstanceState) {
    // ...
    wLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "SN Wake Lock");
    // ...
  }
}

10-08 13:37