multiprocess - Android Execute code once per cold boot of android app - Stack Overflow

I have an Android application with a multi-process architecture where certain activities are launched i

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 in Process A.
  • When a user clicks on items listed in Activity A, a new Activity B is spawned in a different Process 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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744650422a4585866.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信