标签:create null sum onpause oncreate screen ide onresume view
Android保持屏幕常亮,PowerManager.WakeLock的使用
package com.hebaijun.wakelock; import android.app.Activity; import android.os.Bundle; import android.os.PowerManager; public class WakeLockActivity extends Activity { PowerManager.WakeLock wakeLock; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); wakeLock = ((PowerManager)getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "WakeLockActivity"); } @Override protected void onPause() { super.onPause(); if (wakeLock != null) { wakeLock.release(); } } @Override protected void onResume() { super.onResume(); wakeLock.acquire(); } }
需要在AndroidManifest.xml中添加权限<uses-permission android:name="android.permission.WAKE_LOCK"/>
标签:create null sum onpause oncreate screen ide onresume view
原文地址:http://www.cnblogs.com/ganchuanpu/p/6720217.html