Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Optimize code Java in activity and long operation

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Optimize code Java in activity and long operation

    hello I have a problem with java and android develop a dual timer with the Runnable class.
    By means of a call first the activity mRunnable and then the mRunnable1 at a distance of a few seconds. The problem is that when viewing the screen "DownTot.setText (a);" show me for a moment and then subsequently rxbytes the difference (rxbytes - rxbytes1). This is done as if the operation was slow. is there a way to optimize my code?
    Here is the code below:




    public class MainActivity extends Activity implements OnClickListener  {
     
        TextView DownTot;
        private long rxBytes;
        private long rxBytes1;
    private final Runnable mRunnable = new Runnable() {
        	public void run() {
            mHandler.postDelayed(mRunnable1, 1000);
            TextView DownTot = (TextView)findViewById(R.id.downtot);
            rxBytes = (TrafficStats.getTotalRxBytes()- StartDown);
        	long a = rxBytes - rxBytes1;
        	DownTot.setText(a);
        	}
        };
     
        private final Runnable mRunnable1 = new Runnable() {
        	public void run() {
            mHandler.postDelayed(mRunnable1, 1000);
            TextView DownTot = (TextView)findViewById(R.id.downtot);
            rxBytes1 = (TrafficStats.getTotalRxBytes()- StartDown);
        	long a = rxBytes1 - rxBytes;
        	DownTot.setText(a);
        	}
        };
     
    ......


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Optimize code Java in activity and long operation

    I do not understand what the code is supposed to do. Post enough code to see the plan and try to explain what it should do, or what you want it to do.

Similar Threads

  1. error when switch activity in android
    By yefta in forum Android Development
    Replies: 3
    Last Post: October 26th, 2011, 10:50 AM
  2. Optimize/Improvements/Suggestions for my code
    By JimmyNeutron in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 29th, 2011, 02:57 PM
  3. Java File Operation
    By tcstcs in forum Java Theory & Questions
    Replies: 2
    Last Post: March 28th, 2011, 07:54 AM
  4. [SOLVED] Please Review My Code (Long Integer Addition)
    By Saradus in forum Java Theory & Questions
    Replies: 10
    Last Post: July 4th, 2009, 12:55 PM
  5. [SOLVED] Medication of ArrayDemo.java to include iterative menu
    By xyldon27 in forum Loops & Control Statements
    Replies: 8
    Last Post: June 30th, 2009, 02:10 AM