捆绑类是不可变的并且可以安全地在firebase分析中重用吗?

时间:2018-04-06 06:58:29

标签: android firebase firebase-analytics

firebase事件的docs表示每次要记录事件时都应创建一个新的包:

Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, id);
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image");
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);

如果多次记录相同的捆绑数据,那么创建捆绑包一次并保持它是安全的:

// Do this once in the constructor
bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, id);
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image");

// Reuse the bundle to log multiple events
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);

0 个答案:

没有答案