Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewTreeObserver
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
import androidx.activity.viewModels
Expand Down Expand Up @@ -126,22 +127,33 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
postponeEnterTransition()
checkUser()
initViews()
updateAppTitle()
notificationManager = NotificationUtils.getInstance(this)
if (handleGuestAccess()) return
setupNavigation()
handleInitialFragment()
setupToolbarActions()
hideWifi()
setupRealmListeners()
setupSystemNotificationReceiver()
checkIfShouldShowNotifications()
addBackPressCallback()
handleNotificationIntent(intent)
}

override fun onStart() {
super.onStart()
lifecycleScope.launch(Dispatchers.IO) {
setupHeavyTasks()
}
}

private fun setupHeavyTasks() {
setupNavigation()
setupRealmListeners()
challengeHelper = ChallengeHelper(this, mRealm, user, settings, editor, dashboardViewModel)
challengeHelper.evaluateChallengeDialog()
Comment on lines +145 to 156

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Badge Avoid running Realm/UI setup on Dispatchers.IO

The new onStart coroutine uses Dispatchers.IO to invoke setupHeavyTasks(), but that method still calls setupRealmListeners() and creates ChallengeHelper. Both rely on the activity’s mRealm (instantiated on the main thread in SyncActivity.onCreate) and immediately interact with fragments when evaluateChallengeDialog() shows dialogs. Realm objects are thread-confined and fragment operations must run on the main thread, so executing them on the IO dispatcher will crash with IllegalStateException or CalledFromWrongThreadException as soon as the activity starts. These calls need to stay on the main thread or use a background Realm instance and post UI work back to the main dispatcher.

Useful? React with 👍 / 👎.

handleNotificationIntent(intent)
}

private fun initViews() {
Expand All @@ -160,6 +172,15 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
service = Service(this)
tl = findViewById(R.id.tab_layout)
binding.root.viewTreeObserver.addOnGlobalLayoutListener { topBarVisible() }
binding.root.viewTreeObserver.addOnPreDrawListener(
object : ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean {
binding.root.viewTreeObserver.removeOnPreDrawListener(this)
startPostponedEnterTransition()
reportFullyDrawn()
return true
}
})
binding.appBarBell.ivSetting.setOnClickListener {
startActivity(Intent(this, SettingActivity::class.java))
}
Expand Down