Skip to content

Instantly share code, notes, and snippets.

@AshuTyagi16
Created September 25, 2020 13:18
Show Gist options
  • Save AshuTyagi16/92fd584a992ac7aabec7acbc52afd664 to your computer and use it in GitHub Desktop.
Save AshuTyagi16/92fd584a992ac7aabec7acbc52afd664 to your computer and use it in GitHub Desktop.
import android.content.Context
import android.os.Bundle
import android.os.PowerManager
import androidx.appcompat.app.AppCompatActivity
class ExampleActivity : AppCompatActivity() {
private lateinit var wakeLock: PowerManager.WakeLock
companion object {
private const val TIMEOUT_DURATION = 6000L
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyApp::MyWakelockTag")
wakeLock.acquire(TIMEOUT_DURATION)
}
override fun onDestroy() {
super.onDestroy()
wakeLock.release()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment