自定义view界面提示The application may be doing too much work on its main thread.

本文解决了Android应用中因自定义View导致的主线程过度工作问题。通过调整Typeface的初始化位置,避免了在draw()方法中加载字体,从而防止了界面刷新时出现的异常重启现象。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



界面在activity显示完:提示The application may be doing too much work on its main thread.

且刷新界面也会提示:The application may be doing too much work on its main thread.刷新个20遍,界面就会重启。


代码注释,发现是自己自定义view在

invalidate()

时候会出现上诉问题。切入自定义view的draw(),发现是



Typeface custom_font = Typeface.createFromAsset(mContext.getAssets(),"fonts/advent_regular.ttf")

;这句初始化字体的

的问题。把初始化字体这句放在

public 自定义View_name(Context context, AttributeSet attrs) {

 custom_font = Typeface.createFromAsset(mContext.getAssets(),"fonts/advent_regular.ttf")

}不放在draw就可以。

问题解决。









                
Flutter 项目中升级 google_mlkit_text_recognition 从0.11.0到 0.15.0,原来页面正常输入信息的输入框,现在只能删除,不能输入,可以调出输入法,就是无法输入信息,也没有任何错误日志出现,可能的原因是什么PS D:\zhuangyunweishi> flutter run -d emulator-5554 Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! Launching lib\main.dart on sdk gphone64 x86 64 in debug mode... Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! SourceNodeId()J (unsupported,test-api, reflection, allowed) W/ample.loadguard( 4563): Accessing hidden method Landroid/view/accessibility/AccessibilityRecord;->getSourceNodeId()J (unsupported, reflection, allowed) W/ample.loadguard( 4563): Accessing hidden field Landroid/view/accessibility/AccessibilityNodeInfo;->mChiW/ample.loadguard( 4563): Accessing hidden method Landroid/util/LongArray;->get(I)J (unsupported, reflection, allowed) W/HWUI ( 4563): Unknown dataspace 0 Syncing files to device sdk gphone64 x86 64... 349ms Flutter run key commands. r Hot reload. R Hot restart. h List all available interactive commands. d Detach (terminate "flutter run" but leave application running). c Clear the screen q Quit (terminate the application on the device). A Dart VM Service on sdk gphone64 x86 64 is available at: http://127.0.0.1:59853/CVGpwsWg3j8=/ The Flutter DevTools debugger and profiler on sdk gphone64 x86 64 is available at: http://127.0.0.1:9102?uri=http://127.0.0.1:59853/CVGpwsWg3j8=/ I/Choreographer( 4563): Skipped 61 frames! The application may be doing too much work on its main thread. I/WindowExtensionsImpl( 4563): Initializing Window Extensions, vendor API level=6, activity embedding enabled=true W/HWUI ( 4563): Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... W/HWUI ( 4563): Failed to initialize 101010-2 format, error = EGL_SUCCESS I/Gralloc4( 4563): mapper 4.x is not supported I/ample.loadguard( 4563): Compiler allocated 5174KB to compile void android.view.ViewRootImpl.performTraversals() I/ample.loadguard( 4563): Compiler allocated 5417KB to compile void android.view.ViewRootImpl.performTraversals() I/Choreographer( 4563): Skipped 96 frames! The application may be doing too much work on its main thread. D/ProfileInstaller( 4563): Installing profile for com.example.loadguard I/Choreographer( 4563): Skipped 58 frames! The application may be doing too much work on its main thread. D/EGL_emulation( 4563): app_time_stats: avg=72.81ms min=12.28ms max=215.51ms count=13 W/WindowOnBackDispatcher( 4563): sendCancelIfRunning: isInProgress=false callback=io.flutter.embedding.android.FlutterActivity$1@a62fe0a D/EGL_emulation( 4563): app_time_stats: avg=39.17ms min=3.82ms max=387.11ms count=26 D/EGL_emulation( 4563): app_time_stats: avg=100.25ms min=29.67ms max=506.91ms count=10 D/EGL_emulation( 4563): app_time_stats: avg=25.05ms min=7.17ms max=82.55ms count=33 D/EGL_emulation( 4563): app_time_stats: avg=53.35ms min=18.07ms max=178.05ms count=19 W/WindowOnBackDispatcher( 4563): sendCancelIfRunning: isInProgress=false callback=io.flutter.embedding.android.FlutterActivity$1@a62fe0a D/EGL_emulation( 4563): app_time_stats: avg=171.16ms min=11.99ms max=1100.23ms count=11 I/flutter ( 4563): [LOG] _loadPresetData called, template: 平板车 I/flutter ( 4563): [LOG] after _loadPresetData: productCode=LLD-7042, batchNumber=250615F10422, quantity=20 I/flutter ( 4563): [LOG] build: productCode=LLD-7042, batchNumber=250615F10422, quantity=20 D/EGL_emulation( 4563): app_time_stats: avg=104.12ms min=6.13ms max=1251.53ms count=14 W/WindowOnBackDispatcher( 4563): sendCancelIfRunning: isInProgress=false callback=io.flutter.embedding.android.FlutterActivity$1@a62fe0a I/flutter ( 4563): [LOG] _batchNumberController: "250615F10422" I/flutter ( 4563): [LOG] _batchFocusNode.hasFocus: "true" I/flutter ( 4563): [LOG] _batchFocusNode 获得焦点,重置输入法连接 I/flutter ( 4563): [LOG] _batchNumberController: "250615F10422" D/EGL_emulation( 4563): app_time_stats: avg=87.36ms min=5.70ms max=980.71ms count=16 I/ImeTracker( 4563): com.example.loadguard:a4714024: onRequestShow at ORIGIN_CLIENT reason SHOW_SOFT_INPUT fromUser false D/InputMethodManager( 4563): showSoftInput() view=io.flutter.embedding.android.FlutterView{343be5b VFE...... .F....ID 0,0-1344,2992 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT D/InputConnectionAdaptor( 4563): The input method toggled cursor monitoring on D/InsetsController( 4563): show(ime(), fromIme=true) W/InteractionJankMonitor( 4563): Initializing without READ_DEVICE_CONFIG permission. enabled=false, interval=1, missedFrameThreshold=3, frameTimeThreshold=64, package=com.example.loadguard D/EGL_emulation( 4563): app_time_stats: avg=122.23ms min=9.35ms max=322.95ms count=8 I/ImeTracker( 4563): com.example.loadguard:a4714024: onShown D/EGL_emulation( 4563): app_time_stats: avg=1130.69ms min=2.70ms max=10409.28ms count=10 I/flutter ( 4563): [LOG] _batchNumberController: "250615F1042" I/flutter ( 4563): [LOG] onChanged batchNumber: 250615F1042 I/flutter ( 4563): [LOG] _batchNumberController: "250615F104" I/flutter ( 4563): [LOG] onChanged batchNumber: 250615F104 I/flutter ( 4563): [LOG] _batchNumberController: "250615F10" I/flutter ( 4563): [LOG] onChanged batchNumber: 250615F10 I/flutter ( 4563): [LOG] _batchNumberController: "250615F1" I/flutter ( 4563): [LOG] onChanged batchNumber: 250615F1 D/EGL_emulation( 4563): app_time_stats: avg=89.75ms min=11.73ms max=260.84ms count=11 I/flutter ( 4563): [LOG] _batchNumberController: "250615F" I/flutter ( 4563): [LOG] onChanged batchNumber: 250615F I/flutter ( 4563): [LOG] _batchNumberController: "250615" I/flutter ( 4563): [LOG] onChanged batchNumber: 250615 I/flutter ( 4563): [LOG] _batchNumberController: "25061" I/flutter ( 4563): [LOG] onChanged batchNumber: 25061 I/flutter ( 4563): [LOG] _batchNumberController: "2506" I/flutter ( 4563): [LOG] onChanged batchNumber: 2506 D/EGL_emulation( 4563): app_time_stats: avg=286.45ms min=234.33ms max=332.40ms count=4 I/flutter ( 4563): [LOG] _batchNumberController: "250" I/flutter ( 4563): [LOG] onChanged batchNumber: 250 D/EGL_emulation( 4563): app_time_stats: avg=480.30ms min=474.05ms max=492.52ms count=3 D/EGL_emulation( 4563): app_time_stats: avg=500.04ms min=500.03ms max=500.05ms count=2 D/EGL_emulation( 4563): app_time_stats: avg=500.02ms min=499.29ms max=501.43ms count=3 D/EGL_emulation( 4563): app_time_stats: avg=499.61ms min=499.27ms max=500.01ms count=3 D/EGL_emulation( 4563): app_time_stats: avg=509.42ms min=500.94ms max=517.91ms count=2 I/flutter ( 4563): [LOG] _quantityController: "20" I/flutter ( 4563): [LOG] _batchFocusNode.hasFocus: "false" I/flutter ( 4563): [LOG] _quantityFocusNode.hasFocus: "true" I/flutter ( 4563): [LOG] _quantityFocusNode 获得焦点,重置输入法连接 I/flutter ( 4563): [LOG] _quantityController: "20" I/ImeTracker( 4563): com.example.loadguard:3fa548c6: onRequestShow at ORIGIN_CLIENT reason SHOW_SOFT_INPUT fromUser false D/InputMethodManager( 4563): showSoftInput() view=io.flutter.embedding.android.FlutterView{343be5b VFE...... .F...... 0,0-1344,2992 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT D/InputConnectionAdaptor( 4563): The input method toggled cursor monitoring on D/InputConnectionAdaptor( 4563): The input method toggled cursor monitoring off D/InputConnectionAdaptor( 4563): The input method toggled cursor monitoring on D/InsetsController( 4563): show(ime(), fromIme=true) I/ImeTracker( 4563): com.example.loadguard:3fa548c6: onCancelled at PHASE_CLIENT_APPLY_ANIMATION D/EGL_emulation( 4563): app_time_stats: avg=132.37ms min=24.18ms max=498.39ms count=10 I/flutter ( 4563): [LOG] _quantityController: "2" I/flutter ( 4563): [LOG] onChanged quantity: 2 I/flutter ( 4563): [LOG] setState in onChanged quantity, value: 2 I/flutter ( 4563): [LOG] build: productCode=LLD-7042, batchNumber=250, quantity=2 D/EGL_emulation( 4563): app_time_stats: avg=118.76ms min=5.83ms max=501.22ms count=11 D/EGL_emulation( 4563): app_time_stats: avg=499.52ms min=499.51ms max=499.54ms count=3 D/EGL_emulation( 4563): app_time_stats: avg=499.96ms min=499.33ms max=500.58ms count=2 D/EGL_emulation( 4563): app_time_stats: avg=500.42ms min=498.21ms max=501.73ms count=3 I/flutter ( 4563): [LOG] _quantityFocusNode.hasFocus: "false" I/ImeTracker( 4563): com.example.loadguard:bb1c0f0b: onRequestHide at ORIGIN_CLIENT reason HIDE_SOFT_INPUT fromUser false D/InsetsController( 4563): hide(ime(), fromIme=true) D/InputConnectionAdaptor( 4563): The input method toggled cursor monitoring off D/EGL_emulation( 4563): app_time_stats: avg=8097.52ms min=16.38ms max=16178.67ms count=2 D/EGL_emulation( 4563): app_time_stats: avg=210.48ms min=22.28ms max=383.62ms count=5 I/ImeTracker( 4563): com.example.loadguard:3160c9a6: onRequestHide at ORIGIN_CLIENT reason HIDE_SOFT_INPUT_ON_ANIMATION_STATE_CHANGED fromUser false I/ImeTracker( 4563): com.example.loadguard:bb1c0f0b: onHidden D/EGL_emulation( 4563): app_time_stats: avg=199.13ms min=29.11ms max=877.45ms count=6 I/flutter ( 4563): [LOG] build: productCode=LLD-7042, batchNumber=250715F10422, quantity=20 W/WindowOnBackDispatcher( 4563): sendCancelIfRunning: isInProgress=false callback=io.flutter.embedding.android.FlutterActivity$1@a62fe0a D/EGL_emulation( 4563): app_time_stats: avg=71.67ms min=6.31ms max=892.22ms count=16 I/flutter ( 4563): [LOG] _batchNumberController: 250715F10422 I/ImeTracker( 4563): com.example.loadguard:64b38682: onRequestShow at ORIGIN_CLIENT reason SHOW_SOFT_INPUT fromUser false D/InputMethodManager( 4563): showSoftInput() view=io.flutter.embedding.android.FlutterView{343be5b VFE...... .F...... 0,0-1344,2992 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT D/EGL_emulation( 4563): app_time_stats: avg=23.28ms min=2.54ms max=224.42ms count=29 D/InputConnectionAdaptor( 4563): The input method toggled cursor monitoring on D/InsetsController( 4563): show(ime(), fromIme=true) D/EGL_emulation( 4563): app_time_stats: avg=776.08ms min=10.58ms max=3659.82ms count=5 I/ImeTracker( 4563): com.example.loadguard:64b38682: onShown I/flutter ( 4563): [LOG] _batchNumberController: 250715F1042 I/flutter ( 4563): [LOG] onChanged batchNumber: 250715F1042 D/EGL_emulation( 4563): app_time_stats: avg=120.61ms min=16.27ms max=495.79ms count=11 I/flutter ( 4563): [LOG] _batchNumberController: 250715F104 I/flutter ( 4563): [LOG] onChanged batchNumber: 250715F104 I/flutter ( 4563): [LOG] _batchNumberController: 250715F10 I/flutter ( 4563): [LOG] onChanged batchNumber: 250715F10 I/flutter ( 4563): [LOG] _batchNumberController: 250715F1 I/flutter ( 4563): [LOG] onChanged batchNumber: 250715F1 I/flutter ( 4563): [LOG] _batchNumberController: 250715F I/flutter ( 4563): [LOG] onChanged batchNumber: 250715F I/flutter ( 4563): [LOG] _batchNumberController: 250715 I/flutter ( 4563): [LOG] onChanged batchNumber: 250715 I/flutter ( 4563): [LOG] _batchNumberController: 25071 I/flutter ( 4563): [LOG] onChanged batchNumber: 25071 D/EGL_emulation( 4563): app_time_stats: avg=108.70ms min=13.49ms max=248.17ms count=10 I/flutter ( 4563): [LOG] _batchNumberController: 2507 I/flutter ( 4563): [LOG] onChanged batchNumber: 2507 I/flutter ( 4563): [LOG] _batchNumberController: 250 I/flutter ( 4563): [LOG] onChanged batchNumber: 250 D/EGL_emulation( 4563): app_time_stats: avg=358.31ms min=157.83ms max=537.44ms count=4 D/EGL_emulation( 4563): app_time_stats: avg=489.67ms min=460.90ms max=506.42ms count=3 D/EGL_emulation( 4563): app_time_stats: avg=499.17ms min=496.25ms max=502.55ms count=3 D/EGL_emulation( 4563): app_time_stats: avg=498.30ms min=495.33ms max=500.43ms count=3 D/EGL_emulation( 4563): app_time_stats: avg=499.64ms min=497.64ms max=501.15ms count=3 D/EGL_emulation( 4563): app_time_stats: avg=501.02ms min=499.58ms max=502.46ms count=2 D/EGL_emulation( 4563): app_time_stats: avg=499.58ms min=498.45ms max=500.49ms count=3这段日志,在输入框中删除正常,无法输入信息,输入法可以调出,你能看出来问题在哪里吗?
最新发布
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值