Skip to content

Commit

Permalink
Sync clipboard in 'onWindowFocusChanged()' instead of 'onResume()'
Browse files Browse the repository at this point in the history
Since Android 10, multiple activities can simultaneously be in resumed state.
Specifically in multi-window mode, onPause()/onResume() are not called when
window focus changes, because activity is never paused.
So now we use onWindowFocusChanged() as a signal to sync clipboard.

Ref: https://source.android.com/docs/core/display/multi_display/multi-resume
GitHub issue: #62 & #120
  • Loading branch information
gujjwal00 committed Jan 15, 2023
1 parent b66e76c commit 71f84b5
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions app/src/main/java/com/gaurav/avnc/ui/vnc/VncActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ class VncActivity : AppCompatActivity() {
viewModel.state.observe(this) { onClientStateChanged(it) }
}

override fun onResume() {
super.onResume()
viewModel.sendClipboardText()
}

override fun onStart() {
super.onStart()
binding.frameView.onResume()
Expand Down Expand Up @@ -414,7 +409,10 @@ class VncActivity : AppCompatActivity() {

override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) updateSystemUiVisibility()
if (hasFocus) {
updateSystemUiVisibility()
viewModel.sendClipboardText()
}
}


Expand Down

0 comments on commit 71f84b5

Please sign in to comment.