Created
September 25, 2020 13:18
-
-
Save AshuTyagi16/92fd584a992ac7aabec7acbc52afd664 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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