1
0
mirror of https://github.com/tuskyapp/Tusky synced 2025-01-03 12:29:30 +01:00

fix MainActivity behavior (#4818)

This fixes two issues, but I tested them together to make sure this time
everything works as expected.

1) The fix in #4813 went into the right direction, but the condition was
a bit too broad. When sharing something to Tusky so that Tusky switches
accounts, sometimes nothing would happen.

2) fixes #4766. There are two possibilities here (I think it depends
mostly on API level):
2a) Sharing starts a new task. `android:maxRecents="1"` makes sure old
tasks disappear and are not left in the weird in-between state.
3a) Sharing starts a new `MainActivity` in an existing task.
`Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK` makes
sure old `MainActivity` instances are removed. On newer Android versions
this has the sideeffect of changing the switch animation, but whatever.

Basically this gives us the behavior I wanted to achieve with the
`android:launchMode="singleTask"` without the unintended side effects.
This commit is contained in:
Konrad Pozniak 2024-12-21 20:34:54 +01:00 committed by GitHub
parent 55467affc8
commit dee1767ec1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -42,6 +42,7 @@
android:name=".MainActivity"
android:exported="true"
android:alwaysRetainTaskState="true"
android:maxRecents="1"
android:theme="@style/SplashTheme">
<intent-filter>

View File

@ -212,7 +212,10 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
super.onCreate(savedInstanceState)
// make sure MainActivity doesn't hide other activities when launcher icon is clicked again
if ((intent.flags and Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
if (!isTaskRoot &&
intent.hasCategory(Intent.CATEGORY_LAUNCHER) &&
intent.action == Intent.ACTION_MAIN
) {
finish()
return
}
@ -582,7 +585,6 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
}
}
startActivity(composeIntent)
finish()
}
private fun setupDrawer(
@ -1006,6 +1008,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
intent.action = forward.action
intent.putExtras(forward)
}
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
finish()
startActivity(intent)
}