Thursday, November 22, 2012

[android-developers] Auto refresh data from webserver to activity




 Hello.I want to make an application for get web data every x secs i try this code but no work...where is the mistake?Thanks.

 public class ReadWebpageAsyncTask extends Activity {   private TextView textView;     private final Handler handler = new Handler();     @Override   public void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);   setContentView(R.layout.activity_read_webpage_async_task);   textView = (TextView) findViewById(R.id.textView1);   }    private class DownloadWebPageTask extends AsyncTask<String, Void, String> {  @Override  protected String doInBackground(String... urls) {    String response = "";         .................      } catch (Exception e) {        e.printStackTrace();      }    }    return response;   }    @Override  protected void onPostExecute(String result) {    textView.setText(result);  }  }     public void readWebpage(View view) {      DownloadWebPageTask task = new DownloadWebPageTask();    task.execute(new String[] { "http://www.mysite.net/LEDstate.txt" });     }     private final Runnable refreshRunnable = new Runnable() {    public void run() {         DownloadWebPageTask task = new DownloadWebPageTask();       task.execute(new String[] { "http://www.mysite.net/LEDstate.txt" });       //new RefreshTask(param1, param2).execute();       long TIME_DELAY= 3000;      handler.postDelayed(refreshRunnable, TIME_DELAY);   }  };
 

 In main activity i have one text and two buttons the first button on click call readwebpage and work and the second button call refreshRunable and no work...

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate