android - 面对谷歌播放服务7.5.0中的ANR问题

android - 面对谷歌播放服务7.5.0中的ANR问题,第1张

这是我的本地课程,我在其中初始化跟踪器实例以及谷歌分析。

public class Analytics     
{
    private Context mContext;
    private GoogleAnalytics mAnalytics;
    private Tracker mTracker;
    public static boolean analytics_enabled = false;
    public static int lastTabStripPositionValue = -1;
    private SharedPreferences sPrefs;

    public Analytics(Context context, String screenName) 
    {
        mContext = context;
        mAnalytics = GoogleAnalytics.getInstance(mContext);
        mAnalytics.setLocalDispatchPeriod(1800);
        sPrefs = context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
        mTracker = mAnalytics.newTracker(mContext.getString(R.string.analyticsAppTrackingId));
        int consumer_id =sPrefs.getInt(context.getString(R.string.consumer_id),-1);
        //sets the user id with this instance of tracker object.
        if(consumer_id!=-1)
        {
            mTracker.set("&uid",consumer_id "");
        }
        mTracker.setScreenName(screenName);
        //mTracker.enableExceptionReporting(true);
        mTracker.enableAdvertisingIdCollection(true);
        mTracker.enableAutoActivityTracking(false);
    }

    public GoogleAnalytics getGoogleAnalyticsInstance() 
    {
        return mAnalytics;
    }

    public Tracker getTrackerInstance() 
    {
        return mTracker;
    }
}

我在各个活动的onCreate()方法中初始化跟踪器实例。

analytics = new Analytics(this, getString(R.string.D_L_Activity));
    t = analytics.getTrackerInstance();

我的应用程序在大多数情况下工作正常,但有时会进入ANR状态。以下图像android - 面对谷歌播放服务7.5.0中的ANR问题,enter image description here,第2张(从ANR报告中提取)似乎提供了根本原因。我无法解决它背后的问题,所以请帮助。

最佳答案:

1 个答案:

答案 0 :(得分:0)

找到拖延的实际代码行:df1 <- structure(list(ID = c("ID1", "ID1", "ID1", "ID1", "ID1", "ID1", "ID1", "ID1", "ID2", "ID2", "ID2", "ID2", "ID2", "ID2", "ID2" ), Day = c(1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 1L, 2L, 2L, 2L, 2L, 3L, 3L), v = c("v1", "v1", "v2", "v1", "v3", "v3", "v3", "v3", "v4", "v5", "v5", "v4", "v1", "v3", "v4")), .Names = c("ID", "Day", "v"), class = "data.frame", row.names = c(NA, -15L)) 放在任何地方。

解决方法/也许是实际上正确的方法:不是直接初始化onCreate中的分析,而是启动一个新线程,该线程在完成时通过回调对其进行初始化,并且仅在执行时执行相关操作回调到了。

新线程中的init()代码片段:

Log.e
本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复