本文详细介绍终端性能监控 Pro SDK 的各功能接口,帮助您更加灵活、深度的使用 SDK。
添加页面切换行为
业务可以根据自己使用的框架,添加页面切换行为,RumPro 最多保存256条记录。在发生错误时会自动上报,您可以在现场数据 > 页面跟踪中查看。
Bugly.addPageAction('pageAction');
监听生命周期
在 App 中设置
BuglyNavigatorObserver 。class _MyAppState extends State<MyApp> with WidgetsBindingObserver {@overridevoid initState() {super.initState();}@overrideWidget build(BuildContext context) {return MaterialApp(home: Scaffold(appBar: AppBar(title: const Text('APM Example'),),body: Center(child: MyHome(),),),// 添加 BuglyNavigatorObservernavigatorObservers: [BuglyNavigatorObserver()],routes: {'MainPage': (context) => MainPage(),'FirstPage': (context) => FirstPage(),'SecondPage': (context) => SecondPage(),},);}}
如果是接入了 TRouter 等混合栈框架,由于其接管了原生的 Navigator,需要将
BuglyNavigatorObserver 设置到混合栈框架中,如下所示。runApp(MaterialApp(home: TRouteContainer(navigatorObservers: BuglyNavigatorObserver(),),));
注意:
TRouter 需要使用2.5.7+ 版本,否则部分生命周期会丢失。
设置启动监控埋点
启动监听需要在 Native 打开 Flutter 页面时,设置下进入 Flutter 页面埋点。
Android:
Intent intent = new Intent(MainActivity.this, TestFlutterActivity.class);MainActivity.this.startActivity(intent);FlutterLaunchMonitor.onEnterFlutter();
iOS:
[[TFlutterLaunchMonitor sharedInstance] onEnterFlutter];
设置用户 ID
由于部分 App 无法在初始化时设置 UserID,可调用
Bugly#setUserId 进行设置。Bugly.setUserId('your_user_id');
设置 Log
组件内部 Log 默认通过 print 打印,不会进行落地,业务可通过设置 BuglyOptions.logger 接管到自己的日志系统。
BuglyOptions.logger = MyLogger