Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4557300
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:29:23+00:00 2026-05-21T17:29:23+00:00

How to load file from URL on every 2s (over and over )? Do

  • 0

How to load file from URL on every 2s (over and over )? Do I need to close connection or to stay connected ( I load one time with this code ) ? Do I need to use synchronized somewhere ?

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextView txt=(TextView)this.findViewById(R.id.lbl);
    try {

            URL url = new URL("http://10.0.2.2/test/dynamic/test.json");
            URLConnection urlconnection = url.openConnection();
            long l = urlconnection.getContentLength();

            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            StringBuffer buffer=new StringBuffer();
            while ((line = in.readLine()) != null)
            {
               buffer.append(line);
            }
            in.close();
            System.out.println("bufer="+buffer.toString());
            txt.setText(buffer.toString());
            Object obj = JSONValue.parse(buffer.toString());
            JSONArray array = (JSONArray) obj;


            for(Object o:array){
                JSONObject element_json = (JSONObject)o;

                int id=Integer.parseInt(""+element_json.get("id"));
                int type=Integer.parseInt(""+element_json.get("type"));
                int device_type=Integer.parseInt(""+element_json.get("device_type"));

            }

        } catch (Exception exc) {

           exc.printStackTrace();

        }  
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:29:23+00:00Added an answer on May 21, 2026 at 5:29 pm

    You should be using an AsyncTask. The way you’re doing it you’re gonna get the “Application Is Not Responding” error because you’re blocking the UI thread. Any long-running operations (e.g. getting something from the cloud) should be done in the background. Once your asynctask completes, you can schedule another run in the onPostExecute method.

    Also, I would recommend using RoboAsyncTask from the RoboGuice library, since it provides a much more developer (and newbie) friendly version of AsyncTask.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to load a .xml file from a URL adress into an NSData
I need to load xml file from specified url using javascript. Here is what
I need to load a file from an umounted TrueCrypt disk into memory. Is
I am completely new to flash. We need to load a binary file from
I have developed a VB.Net code for retrieving data from excel file .I load
If I load an image from a file like this Image1.Picture.LoadFromFile(imagePath); and the JPEG
I'm tryinig to load a file from a web server with a request URL
can I load a ps1 file from within a ps1 file. The end goal
We are receiving an XML file from our client. I want to load the
I'm running jquery from a file. And I'm trying to load a svg file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.