android - Calculating data rate per second but the result always the same -


iam calculating cellular data rate per second using handler, code being executed every second , overall traffic been calculated suppose subtract old traffic since boot current traffic since boot current data rate per second.

the problem i'm facing current data rate value not correct, giving me total overall traffic since boot. may did wrong, i'm still beginner android. code below.

public class mainactivity extends appcompatactivity {

private double rxold;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);       final handler handler = new handler();     handler.postdelayed(new runnable() {           @override         public void run() {               ////////////////////////code executed every second////////////////////////////////////////              calendar c = calendar.getinstance();             int seconds = c.get(calendar.second);             double overalltraffic = trafficstats.getmobilerxbytes();              double currentdatarate = overalltraffic - rxold;              textview view1 = null;             view1 = (textview) findviewbyid(r.id.view1);             view1.settext("current data rate per second= " + currentdatarate);              double rxold = overalltraffic;              handler.postdelayed(this, 1000);         }     }, 1000 ); } 

the new code after rectification shall give current data rate per second

public class mainactivity extends appcompatactivity {  final double [] rxold = new double [1]; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);       final handler handler = new handler();     handler.postdelayed(new runnable() {           @override         public void run() {               ////////////////////////code executed every second////////////////////////////////////////              calendar c = calendar.getinstance();             int seconds = c.get(calendar.second);             double overalltraffic = trafficstats.getmobilerxbytes();              double currentdatarate = overalltraffic - rxold [0];              textview view1 = null;             view1 = (textview) findviewbyid(r.id.view1);             view1.settext("current data rate per second= " + currentdatarate);               rxold [0] = overalltraffic;              handler.postdelayed(this, 1000);         }     }, 1000 ); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -