admin管理员组文章数量:1389768
I have an Android application with a multi-process architecture where certain activities are launched in different processes. Here is the scenario:
- Main Activity (
Activity A
) runs inProcess A
. - When a user clicks on items listed in
Activity A
, a newActivity B
is spawned in a differentProcess B
, and the user is redirected there.
Edit: There can be independent App invocations of Activity B
other than getting launched from Activity A
.
I need to show a specific dialog once per cold boot/session, regardless of the number of processes the app spawns. The dialog should be shown when certain conditions are met, but the process/activity where the user is present when these conditions are met cannot be predicted.
I can use Shared Preferences
for this to save a setting (e.g., DIALOG_SHOWN
) to indicate that the dialog has been shown and should not be shown again in the same session. This preference needs to be reset to false during every app boot to ensure the dialog is shown once per cold boot.
In a single-process app, I could reset the preference in Application::onCreate
or another callback guaranteed to execute once per cold boot. However, in a multi-process architecture, each process creates its own instance of the Application object. Therefore, if I put the reset logic in Application::onCreate
, the preference would be wrongly reset to false when a new process (e.g., Process B
) is spawned, causing the dialog to be shown again.
I tried using static variables, but they are created afresh for every process.
Are there any other ways in Android to execute something "only" once per cold boot of the app (not the device), irrespective of the number of processes it ends up spawning?
本文标签: multiprocessAndroid Execute code once per cold boot of android appStack Overflow
版权声明:本文标题:multiprocess - Android Execute code once per cold boot of android app - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744650421a2617650.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论