alibaba / alibaba/flutter_boost
[Bug]:
- Dominant language
- Dart
- Stars
- 7.2k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
### 请描述遇到的问题,以及您所期望的正确的结果
在 4层 Fragment 嵌套(Activity → HomeFragment → TypeFragment → CategoryFragment)时跳转 Flutter 页面然后返回 页面消失了4到8秒收才调用 onDestroy方法(华为mate20pro)貌似是低端机型
/**
* 针对有些特殊问题的处理 比如onUpdateSystemUiOverlays
*/
class PuFlutterBoostFragment : FlutterBoostFragment() {
companion object {
private const val TAG = "PuFlutterBoostFragmentTAG"
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
PuLog.d(TAG, "onViewCreated: ${getUrl()}")
}
override fun onDestroyView() {
PuLog.d(TAG, "onDestroyView: ${getUrl()}")
super.onDestroyView()
}
override fun onDestroy() {
PuLog.d(TAG, "onDestroy: ${getUrl()}")
super.onDestroy()
}
},而 3层嵌套正常(略微延时)。class PuFlutterBoostActivity : FlutterFragmentActivity() {
private var pageUrl: String? = null
private var pageParams: Map? = null
private var uniqueId: String? = null
companion object{
private const val TAG = "PuFlutterBoostActivity"
}
override fun onCreate(savedInstanceState: Bundle?) {
setupStatusBar()
// 先获取参数
pageUrl = intent.getStringExtra("url")
pageParams = intent.getSerializableExtra("params") as? Map
uniqueId = intent.getStringExtra("uniqueId")
PuLog.d(TAG, "生成新的uniqueId: $uniqueId")
// 再调用父类的onCreate
super.onCreate(savedInstanceState)
}
/**
* 设置状态栏样式
*/
private fun setupStatusBar() {
window.decorView.post {
// 根据是否透明设置状态栏
PuStatusBar.setStatusBar(this, true, getColor(R.color.ai_bg_surface), translucent = false)
}
}
override fun createFlutterFragment(): FlutterFragment {
// 直接创建并返回新的Fragment实例
return FlutterBoostFragment.CachedEngineFragmentBuilder(PuFlutterBoostFragment::class.java)
.url(pageUrl ?: "default_route")
.urlParams(pageParams ?: emptyMap())
.uniqueId(uniqueId ?: "${System.currentTimeMillis()}_${pageUrl}")
.build()
}
override fun onBackPressed() {
// 从FragmentManager中获取当前的Fragment
val fragment = supportFragmentManager.findFragmentById(android.R.id.content) as? FlutterBoostFragment
if (fragment != null) {
fragment.onBackPressed()这种实现方式
### 请说明如何操作会遇到上述问题
_No response_
### 在下面填入关键复现代码
```
```
### 复现的平台
Both
### Flutter SDK版本
3.16.9
### FlutterBoost版本
5.0.0
### 是否延迟初始化FlutterBoost
No
### 解决方案
在 4层 Fragment 嵌套(Activity → HomeFragment → TypeFragment → CategoryFragment)时跳转 Flutter 页面然后返回 页面消失了4到8秒收才调用 onDestroy方法(华为mate20pro)貌似是低端机型
/**
* 针对有些特殊问题的处理 比如onUpdateSystemUiOverlays
*/
class PuFlutterBoostFragment : FlutterBoostFragment() {
companion object {
private const val TAG = "PuFlutterBoostFragmentTAG"
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
PuLog.d(TAG, "onViewCreated: ${getUrl()}")
}
override fun onDestroyView() {
PuLog.d(TAG, "onDestroyView: ${getUrl()}")
super.onDestroyView()
}
override fun onDestroy() {
PuLog.d(TAG, "onDestroy: ${getUrl()}")
super.onDestroy()
}
},而 3层嵌套正常(略微延时)。class PuFlutterBoostActivity : FlutterFragmentActivity() {
private var pageUrl: String? = null
private var pageParams: Map? = null
private var uniqueId: String? = null
companion object{
private const val TAG = "PuFlutterBoostActivity"
}
override fun onCreate(savedInstanceState: Bundle?) {
setupStatusBar()
// 先获取参数
pageUrl = intent.getStringExtra("url")
pageParams = intent.getSerializableExtra("params") as? Map
uniqueId = intent.getStringExtra("uniqueId")
PuLog.d(TAG, "生成新的uniqueId: $uniqueId")
// 再调用父类的onCreate
super.onCreate(savedInstanceState)
}
/**
* 设置状态栏样式
*/
private fun setupStatusBar() {
window.decorView.post {
// 根据是否透明设置状态栏
PuStatusBar.setStatusBar(this, true, getColor(R.color.ai_bg_surface), translucent = false)
}
}
override fun createFlutterFragment(): FlutterFragment {
// 直接创建并返回新的Fragment实例
return FlutterBoostFragment.CachedEngineFragmentBuilder(PuFlutterBoostFragment::class.java)
.url(pageUrl ?: "default_route")
.urlParams(pageParams ?: emptyMap())
.uniqueId(uniqueId ?: "${System.currentTimeMillis()}_${pageUrl}")
.build()
}
override fun onBackPressed() {
// 从FragmentManager中获取当前的Fragment
val fragment = supportFragmentManager.findFragmentById(android.R.id.content) as? FlutterBoostFragment
if (fragment != null) {
fragment.onBackPressed()这种实现方式
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the four-level Activity → HomeFragment → TypeFragment → CategoryFragment navigation on the reported Huawei Mate 20 Pro configuration, using Flutter SDK 3.16.9 and FlutterBoost 5.0.0. Read the lifecycle logging in PuFlutterBoostFragment and the creation and back-navigation paths in PuFlutterBoostActivity; done means identifying why destruction is delayed and confirming the delay is removed or explained without breaking the three-level case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, dart, kotlin
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100