So I have an app and I want it to run immediately whenever device got rebooted. To achieve this I added home and default category to MainActivity.
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
However after doing this since default home screen is not launched it needs to click home button twice to go back to the home screen. I know that I could handle this by monitor home button click action like follow.
override fun onAttachedToWindow() {
super.onAttachedToWindow()
this.window.setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
}
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
if (keyCode == KeyEvent.KEYCODE_HOME) {
//open defualt home screen intent
}
return super.onKeyDown(keyCode, event)
}
However, if user goes to somewhere else (let's say open setting from status bar) then click home button. This issue will happen again.
Therefore is there a way to avoid this? Maybe consider run default home screen at background when device get reboot but I honestly don't know the solution.