大家好,我用计时器构建类以将数据发送到 Flurry Server。它解决了我所有的问题。
public class TimerFlurry {
private static final String TAG = "TIMER FLURRY";
private Handler handler = new Handler();
private Runnable runnable = null;
private boolean stop = false;
public TimerFlurry(final Context ctx) {
Log.d(TAG, "TimerFlurry.TimerFlurry()");
runnable = new Runnable() {
boolean inicializou = false;
@Override
public void run() {
if (stop) {
Log.d(TAG, "parou Handler!!!");
FlurryAgent.onEndSession(ctx);
inicializou = false;
return;
}
Log.d(TAG, "!!!!!!!!!!!!!!!!!!! .run() now: " + new Date());
if (!inicializou) {
Log.d(TAG, ">>>>> inicializou Flurry Session!!!");
FlurryAgent.setContinueSessionMillis(5000);
FlurryAgent.onStartSession(ctx, "XXXXXXXXXXXXXXXXXXXX");
FlurryAgent.setLogEnabled(true);
FlurryAgent.setLogLevel(Log.DEBUG);
inicializou = true;
handler.postDelayed(runnable, 60000);
} else {
Log.d(TAG, "!!!!!!!!!!!!! finalizou Flurry Session!!!");
FlurryAgent.onEndSession(ctx);
inicializou = false;
handler.postDelayed(runnable, 10000);// inicializa em 10 s
// novamente para
// dar o timeout do
// flurry
}
}
};
handler.postDelayed(runnable, 5000);
}
public void stop() {
stop = true;
}
}