Updated on 2026-08-14
This commit is contained in:
parent
2a85a3ce32
commit
9478a17d36
3 changed files with 28 additions and 12 deletions
|
|
@ -4,30 +4,38 @@ import android.app.Activity
|
|||
import android.app.Application.ActivityLifecycleCallbacks
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import java.util.WeakHashMap
|
||||
import timber.log.Timber
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class ForegroundActivityObserver {
|
||||
object ForegroundActivityObserver {
|
||||
|
||||
private val activities = WeakHashMap<KClass<out Activity>, AppCompatActivity>()
|
||||
private val activities = HashMap<KClass<out Activity>, AppCompatActivity>()
|
||||
|
||||
val foregroundActivity: AppCompatActivity?
|
||||
get() = activities.entries
|
||||
.firstOrNull { it.value?.isDestroyed == false }
|
||||
.firstOrNull {
|
||||
Timber.i("foregroundActivity: ${it.key} | ${it.value.isDestroyed}")
|
||||
it.value.isDestroyed == false
|
||||
}
|
||||
?.value
|
||||
|
||||
internal val callbacks: ActivityLifecycleCallbacks
|
||||
get() = Callbacks()
|
||||
|
||||
internal inner class Callbacks : ActivityLifecycleCallbacks {
|
||||
internal class Callbacks : ActivityLifecycleCallbacks {
|
||||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
||||
}
|
||||
|
||||
override fun onActivityResumed(activity: Activity) {
|
||||
activities[activity::class] = activity as? AppCompatActivity
|
||||
Timber.i("onActivityResumed ${activity::class}")
|
||||
(activity as? AppCompatActivity)?.let {
|
||||
Timber.i("onActivityResumed store activity")
|
||||
activities[activity::class] = it
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityDestroyed(activity: Activity) {
|
||||
Timber.i("onActivityDestroyed")
|
||||
activities.remove(activity::class)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -191,6 +191,7 @@ class MainActivity : AppCompatActivity(), ActivityResultCallbackHolder {
|
|||
private val onActivityResultCallbacks = mutableListOf<OnActivityResultCallback>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
Timber.i("onCreate")
|
||||
// We need to call it before onCreate to prevent unnecessary activity recreation
|
||||
installAppTheme()
|
||||
|
||||
|
|
@ -328,15 +329,18 @@ class MainActivity : AppCompatActivity(), ActivityResultCallbackHolder {
|
|||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
Timber.i("onStart")
|
||||
dialogManager.onStart(this)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
dialogManager.onStop()
|
||||
super.onStop()
|
||||
Timber.i("onStop")
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
Timber.i("onDestroy")
|
||||
// workaround: kill process when activity destroy to avoid state when lock() wallets
|
||||
// and navigation to unlock screen was skipped because system kills activity but not process
|
||||
if (BuildConfig.BUILD_TYPE != MOCKED_BUILD_TYPE) {
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ import timber.log.Timber
|
|||
|
||||
lateinit var store: Store<AppState>
|
||||
|
||||
lateinit var foregroundActivityObserver: ForegroundActivityObserver
|
||||
val foregroundActivityObserver = ForegroundActivityObserver
|
||||
internal lateinit var derivationsFinder: DerivationsFinder
|
||||
|
||||
abstract class TangemApplication : Application(), ImageLoaderFactory, Configuration.Provider {
|
||||
|
|
@ -246,6 +246,7 @@ abstract class TangemApplication : Application(), ImageLoaderFactory, Configurat
|
|||
|
||||
override fun onCreate() {
|
||||
enableStrictModeInDebug()
|
||||
preInit()
|
||||
super.onCreate()
|
||||
init()
|
||||
}
|
||||
|
|
@ -286,22 +287,25 @@ abstract class TangemApplication : Application(), ImageLoaderFactory, Configurat
|
|||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize components that need to be initialized before [super.onCreate] is called
|
||||
*/
|
||||
private fun preInit() {
|
||||
tangemAppLoggerInitializer.initialize()
|
||||
registerActivityLifecycleCallbacks(foregroundActivityObserver.callbacks)
|
||||
}
|
||||
|
||||
fun init() {
|
||||
apiConfigsManager.initialize()
|
||||
|
||||
store = createReduxStore()
|
||||
|
||||
tangemAppLoggerInitializer.initialize()
|
||||
|
||||
Timber.i("APP STARTED")
|
||||
if (BuildConfig.TESTER_MENU_ENABLED) {
|
||||
Timber.i(featureTogglesManager.toString())
|
||||
Timber.i(excludedBlockchainsManager.toString())
|
||||
}
|
||||
|
||||
foregroundActivityObserver = ForegroundActivityObserver()
|
||||
registerActivityLifecycleCallbacks(foregroundActivityObserver.callbacks)
|
||||
|
||||
runBlocking {
|
||||
initWithConfigDependency(environmentConfig = environmentConfigStorage.initialize())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue