Hi guys I am developing an app to display data rate on status bar like this.
My code is :
private class DataStatUtil implements Runnable {
private long startRX = 0;
private long lastRx = 0;
private Handler mHandler;
private Context context;
private Intent actionIntent;
public DataStatUtil(Context context ,Handler handler) {
this.context = context;
mHandler = handler;
startRX = TrafficStats.getTotalRxBytes();
}
@Override
public void run() {
long rxBytes = (TrafficStats.getTotalRxBytes()- startRX)/1024;
startRX = TrafficStats.getTotalRxBytes();
//my method to display on status bar
notifyOnStatusBar(rxBytes);
mHandler.postDelayed(this, 1000);
}
}
}
I am asking is this is the right way?