Results 1 to 3 of 3
  1. #1
    bizkit1 is offline Member
    Join Date
    May 2012
    Posts
    1
    Rep Power
    0

    Smile java execute command every 10 seconds

    Hello guys. I have this code, for a android app i'm working on. It reads from a .php page and outputs the text

    Java Code:
    package com.exercise.AndroidInternetTxt;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.MalformedURLException;
    import java.net.URL;
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.TextView;
    
    public class AndroidInternetTxt extends Activity {
    
        TextView textMsg, textPrompt, textSite;
        final String textSource = "http://www.xxx/s.php";
    
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            textPrompt = (TextView)findViewById(R.id.textprompt);
            textMsg = (TextView)findViewById(R.id.textmsg);
            textSite = (TextView)findViewById(R.id.textsite);
    
            //textPrompt.setText("Asteapta...");
    
    
            URL textUrl;
            try {
                textUrl = new URL(textSource);
                BufferedReader bufferReader = new BufferedReader(new InputStreamReader(textUrl.openStream()));
                String StringBuffer;
                String stringText = "";
                while ((StringBuffer = bufferReader.readLine()) != null) {
                    stringText += StringBuffer;
                }
                bufferReader.close();
                textMsg.setText(stringText);
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                textMsg.setText(e.toString());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                textMsg.setText(e.toString());
            }
    
    
            //textPrompt.setText("Terminat!");
    
        }
    
    }
    It works fine but I would like it to "autorefresh" every 10 seconds, because the text from the php script is always changing. Sincerely i don`t know how to do that. Can you please help me solve this out? Thanks!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: java execute command every 10 seconds

    Quote Originally Posted by bizkit1 View Post
    Hello guys. I have this code, for a android app
    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: java execute command every 10 seconds

    im not that familiar with the psuedo-java android apps use... but is there a repaint(); method or something similar you can use? in applets that forces a repaint of your window...

Similar Threads

  1. Replies: 8
    Last Post: 03-13-2011, 11:03 AM
  2. Execute Cygwin command from Java app
    By ZebraIzToronto in forum Advanced Java
    Replies: 1
    Last Post: 01-21-2011, 05:51 AM
  3. Replies: 0
    Last Post: 06-26-2008, 07:32 PM
  4. Execute a jar command from a java program
    By apremanandh in forum New To Java
    Replies: 3
    Last Post: 05-21-2008, 02:04 PM
  5. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •