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 3603862
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:55:30+00:00 2026-05-18T20:55:30+00:00

Don’t you know why it is possible to invoke onClickListener only once, on second

  • 0

Don’t you know why it is possible to invoke onClickListener only once, on second attempt I should turn on and turn off the Wifi connection on my device. After first click I can’t browse web and read email – so internet connection is blocked.

Code:
package je.net.ua;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class App extends Activity {

    Button button;
    TextView tv;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        button = (Button) findViewById(R.id.Button01);
        tv = (TextView) findViewById(R.id.TextView01);
        Log.d("Dev", "Application started");
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    BufferedReader in;
                    HttpClient client = new DefaultHttpClient();
                    HttpPost request = new HttpPost("http://www.snee.com/xml/crud/posttest.cgi");

                    List<NameValuePair> postParameters = new ArrayList<NameValuePair>();

                    postParameters.add(new BasicNameValuePair("fname", "First name"));
                    postParameters.add(new BasicNameValuePair("lname", "Last name"));

                    UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(
                            postParameters);

                    request.setEntity(formEntity);

                    HttpResponse response = client.execute(request);

                    in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

                    StringBuffer sb = new StringBuffer("");
                    String line = "";
                    String NL = System.getProperty("line.separator");
                    while ((line = in.readLine()) != null) {
                        Log.d("Dev", "Line = " + line);
                        sb.append(line + NL);
                    }
                    in.close();
                    tv.setText(line);
                } catch (Exception ex) {
                }

            }
        });


    }
}

Debug:

12-27 21:39:16.936: DEBUG/Dev(6568): Line = <html><head><title>posted data</title></head><body><h1>posted data</h1><p>First name: "First+name"</p><p>Last name: "Last+name"</p><p>REQUEST_URI: "/xml/crud/posttest.cgi"</p><p>QUERY_STRING: ""</p><p>CONTENT_LENGTH: "32"</p><p>content passed via STDIN: "fname=First+name&lname=Last+name"</p></body></html>
12-27 21:39:25.566: DEBUG/dalvikvm(85): GC_FOR_MALLOC freed 28784 objects / 1536696 bytes in 109ms
12-27 21:39:34.106: DEBUG/dalvikvm(6072): GC_EXPLICIT freed 1097 objects / 213648 bytes in 67ms
12-27 21:39:42.476: DEBUG/dalvikvm(5056): GC_EXPLICIT freed 1749 objects / 72040 bytes in 53ms
12-27 21:39:47.516: DEBUG/dalvikvm(29993): GC_EXPLICIT freed 1378 objects / 67232 bytes in 91ms
12-27 21:39:50.136: WARN/GTalkService(21165): [GTalkConnection.11] doConnect: caught XMPPError connecting to mtalk.google.com:5228.: (502)
12-27 21:39:50.136: WARN/GTalkService(21165):   -- caused by: java.net.SocketException: The operation timed out
  • 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-18T20:55:31+00:00Added an answer on May 18, 2026 at 8:55 pm

    It seems as if your OnClickListener is blocked while it waits for a response from http://www.snee.com/xml/crud/posttest.cgi. Turning the WiFi off breaks the socket connection, so your OnClickListener is no longer blocked at that point.

    If you were to run the main part of this handler as an AsyncTask, I think you’d find that you can click on the button any number of times (and deluge your server with POSTs as you do so 😉


    Update

    Responding to your update, especially that web and email are blocked: It seems like there have been other issues with sending POSTs via DefaultHttpClient. I suggest you look into using AndroidHttpClient, if you’re targeting Froyo and later releases, and be sure to invoke its close() method when you’re finished with the connection. Or, if you need to stick with DefaultHttpClient because you need to support earlier releases, try calling client.getConnectionManager().shutdown() when you’re done with the connection. I can’t promise that these steps would help, but they seem to be good steps to take regardless.

    (From my comment, below: What happens if you turn off WiFi before starting the program? Does it still block your ability to browse and send email? Also, are you seeing the returned HTML after you call tv.setText(line)? Lastly, I suggest putting Log.d calls inside of your exception handler and after the readLine() loop, and see if either of them are reached.)

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

Sidebar

Related Questions

I don't know if this is possible. I display a table of results and
I don't know when to add to a dataset a tableadapter or a query
I don't know if anyone has seen this issue before but I'm just stumped.
Don't let below code scare you away . The question is really simple, only
I don't know why i can't match url when url is http://localhost:8000/home/CPM%201.6.1001 since i
I don't know Regex very well, and I'm trying to get all of the
I don't know if thats right but for some reason my stored procedure is
I don't know if i am doing it right, this is what I got:
I don't think this should be in my view, but instead handled by the
I don't understand why my output is not how I think it should be.

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.