While the application is running, it sometimes happens that other applications open, thereby taking away the focus from my application.
Question: how in such situations to restart the application in the services, where to dig?
While the application is running, it sometimes happens that other applications open, thereby taking away the focus from my application.
Question: how in such situations to restart the application in the services, where to dig?
You need to implement a Service in which to start some kind of timer that will check the ActivityManager and see which is currently in the topActivity stack. And if it's not yours, then start the right one.
UPD.
void check() { // получение Activity из верхнего таска ComponentName componentName = (mActivityManager.getRunningTasks(1).get(0)).topActivity; String s = componentName.getPackageName(); // сравнение текущего названия package с тем, который запущен if (!getPackageName().equals(s)) { // запуск своего приложения } } Source: https://ru.stackoverflow.com/questions/634620/
All Articles
onStop(), becauseonPause()will work for the activit when, for example, it is blocked byDialog- tim_taller