Registration activity freezing on phones

I'm stuck at registration page of my app. I've tested it on AVD and it works fine there but it is to be noted that logcat is heavily stormed by system logs.

The scene right now is that when I test my app on phone the login activity works just fine but when I go to registration page the activity freezes & I have no option other than force closing it myself or wait for my phone to ask me if I want to force close it. Here is the code of my registration page.

The activity name is Enroll.java

package com.example.dell.iblood; import android.content.Intent; import android.os.Bundle; import android.os.StrictMode; import android.support.v7.app.ActionBarActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.Spinner; import android.widget.Toast; import org.apache.http.HttpEntity; 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 org.json.JSONArray; import org.json.JSONObject; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class enroll extends ActionBarActivity implements View.OnClickListener,AdapterView.OnItemSelectedListener { EditText Name, Passwordone, Passwordtwo, Age, Address,Phone, Email; Button REGISTER, RESET; Spinner States,City,Bloodgroup; String val = ""; InputStream is = null; String ip = "http://iblood.byethost3.com/spdemo.php"; String line = null; String result = null; List<String> list,list1; String name; String paso; String past; String age; String bgroup; int code; String add; String state; String city; String phone; String email; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_enroll); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); REGISTER = (Button) findViewById(R.id.Regbutton); RESET = (Button) findViewById(R.id.Resbutton); Name = (EditText) findViewById(R.id.nameU); Passwordone = (EditText) findViewById(R.id.passUone); Passwordtwo = (EditText) findViewById(R.id.passUtwo); Age = (EditText) findViewById(R.id.ageU); Bloodgroup = (Spinner) findViewById(R.id.bgroupU); Address = (EditText) findViewById(R.id.addressU); States = (Spinner) findViewById(R.id.stateU); City = (Spinner) findViewById(R.id.cityU); States = (Spinner) findViewById(R.id.stateU); Phone = (EditText) findViewById(R.id.mobU); Email = (EditText) findViewById(R.id.mailU); Bloodgroup.setOnItemSelectedListener(this); States.setOnItemSelectedListener(this); City.setOnItemSelectedListener(this); Selectall(); ArrayAdapter<String> adp = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list); // set list into ArrayAdapter States.setAdapter(adp); // Set SelectBg(); ArrayAdapter<String> adp3 = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list); // set list into ArrayAdapter Bloodgroup.setAdapter(adp3); // Set REGISTER.setOnClickListener(this); RESET.setOnClickListener(this); } @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { val = States.getSelectedItem().toString(); selectcity(); ArrayAdapter<String> adp1 = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list1); // set list into ArrayAdapter City.setAdapter(adp1); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } private void Selectall() { // TODO Auto-generated method stub try { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(ip); HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch (Exception e) { Log.e("Webservice 1", e.toString()); } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); } catch (Exception e) { Log.e("Webservice 2", e.toString()); } try { JSONArray ja = new JSONArray(result); JSONObject jo = null; list = new ArrayList<String>(); for (int i = 0; i < ja.length(); i++) { jo = ja.getJSONObject(i); list.add(jo.getString("nameofstate")); } } catch (Exception e) { Log.e("Webservice 3", e.toString()); } } private void selectcity() { ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("city",val)); try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://iblood.byethost3.com/cities.php"); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); Log.e("pass 1", "connection success "); } catch(Exception e) { Log.e("Fail 1", e.toString()); Toast.makeText(getApplicationContext(), "Invalid IP Address", Toast.LENGTH_LONG).show(); } try { BufferedReader reader = new BufferedReader (new InputStreamReader(is,"iso-8859-1"),8); StringBuilder sb = new StringBuilder(); while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); Log.e("pass 2", "connection success "); } catch(Exception e) { Log.e("Fail 2", e.toString()); } try { JSONArray ja = new JSONArray(result); JSONObject jo = null; list1 = new ArrayList<String>(); for (int i = 0; i < ja.length(); i++) { jo = ja.getJSONObject(i); list1.add(jo.getString("cityname")); } } catch (Exception e) { Log.e("Webservice 13", e.toString()); } } private void SelectBg() { // TODO Auto-generated method stub try { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost("http://iblood.byethost3.com/bloodgroup.php"); HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch (Exception e) { Log.e("Webservice 1", e.toString()); } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); } catch (Exception e) { Log.e("Webservice 2", e.toString()); } try { JSONArray ja = new JSONArray(result); JSONObject jo = null; list = new ArrayList<String>(); for (int i = 0; i < ja.length(); i++) { jo = ja.getJSONObject(i); list.add(jo.getString("Bloodgroup")); } } catch (Exception e) { Log.e("Webservice 3", e.toString()); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_enroll, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override public void onClick(View view) { int i = view.getId(); name = Name.getText().toString(); paso = Passwordone.getText().toString(); past = Passwordtwo.getText().toString(); age = Age.getText().toString(); bgroup=Bloodgroup.getSelectedItem().toString(); add = Address.getText().toString(); state= States.getSelectedItem().toString(); city=City.getSelectedItem().toString(); phone = Phone.getText().toString(); email = Email.getText().toString(); switch (i) { case R.id.Regbutton: insert(); break; case R.id.Resbutton: Name.setText(" "); Passwordone.setText(""); Passwordtwo.setText(""); Age.setText(" "); Bloodgroup.setSelection(0); Address.setText(" "); States.setSelection(0); City.setSelection(0); Phone.setText(" "); Email.setText(" "); break; } } public void insert() { ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("nameU", name)); nameValuePairs.add(new BasicNameValuePair("passUone", paso)); nameValuePairs.add(new BasicNameValuePair("passUtwo", past)); nameValuePairs.add(new BasicNameValuePair("ageU", age)); nameValuePairs.add(new BasicNameValuePair("bloodgroup",bgroup )); nameValuePairs.add(new BasicNameValuePair("addressU", add)); nameValuePairs.add(new BasicNameValuePair("nameofstate", state)); nameValuePairs.add(new BasicNameValuePair("cityname", city)); nameValuePairs.add(new BasicNameValuePair("mobU", phone)); nameValuePairs.add(new BasicNameValuePair("mailU", email)); try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://iblood.byethost3.com/reg.php"); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); Log.e("pass 11", "connection success "); } catch (Exception e) { Log.e("Fail 1", e.toString()); Toast.makeText(getApplicationContext(), "Invalid IP Address"+e, Toast.LENGTH_LONG).show(); } try { BufferedReader reader = new BufferedReader (new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); Log.e("pass 12", "connection success "); } catch (Exception e) { Log.e("Fail 2", e.toString()); } try { JSONObject json_data = new JSONObject(result); code=(json_data.getInt("code")); if (code == 1) { Intent l = new Intent(this, Mainpage.class); startActivity(l); Toast.makeText(getBaseContext(), "Registered Successfully \n Please Login", Toast.LENGTH_SHORT).show(); } else { Intent la = new Intent(this, Mainpage.class); startActivity(la); Toast.makeText(getBaseContext(), "Sorry, Try Again", Toast.LENGTH_LONG).show(); } } catch (Exception e) { Log.e("Fail 3", e.toString()); } } }

-------------Problems Reply------------

As mentioned by @TomRichardson your basic problem is that you are doing time consuming operations on the UI thread of the activity.

As with most modern environments the 'main' thread of your activity should always be available to process user input making your program responsive. If you want to do something time consuming (such as making an HTTP request) you need to do that in a different background thread.

Typically this sequence goes something like this: 1. UI thread pops up a progress spinner to show it's working and starts the task thread. 2. Task thread works and on completion signals the UIthread 3. The UI thread clears the progress spinner and does whatever it needs to next.

If this all sounds a bit complex then try reading up about Android's ASyncTask class which implements most of these bits for you in a direct and easy way to understand.

ASyncTask has serious issues and as your knowledge of android develops you might consider leaving it behind but it is a good easy place to start with a task like yours.

Category:java Views:5 Time:2018-06-08

Related post

  • Activation freeze after re-install Windows XP Professional 2013-02-17

    Original Title: Activation freeze I had to completely re-install Windows XP Professional. I reformatted my hard disk and re-installed without a single error, but when the install started Windows a dialog came up saying it must be activated. I clicked

  • When I click on link in my gmail message it should open an activity on my phone 2010-12-03

    Is their a way to format a link in a gmail, which when opened in a browser or a app, when clicked opens a different activity on a phone? I mean let's say in an email you send a link and link has some formatting like YouTube and this when clicked open

  • How to implement a registration activity in android that works only for once? 2012-01-26

    I'm designing an application that has an activity for registration process, this activity launches on default. I want this activity to be disabled forever once the registration process has been completed successfully and then it should be replaced by

  • Activated a new phone... 2012-01-21

    i previously synced my old old phone and all my contacts/texts is in my account... i just activated my new phone...if i sync my account wit the new phone all my information from my my phone account transfers to my new phone? or does the phone deletes

  • i have xp pro i activated it by phone went through all the steps said windows activated the it took me to the log in screen but when i try to log in it tells me that i need to activated windows 2012-06-27

    i have xp pro i activated it by phone went through all the steps said windows activated the it took me to the log in screen but when i try to log in it tells me that i need to activated windows so i click activate the itr tells me windows is already

  • how to activ my windows phone 2012-07-07

    how to activ my windows phone --------------Solutions------------- Please be much more specific. If you need an activation code, please check any of the other answered questions on this topic: http://answers.microsoft.com/en-us/Search/Search?SearchTe

  • I want to active code windows phone lumia 710... 2013-03-21

    I want to active code windows phone lumia 710... --------------Solutions------------- Hi Nidapa Kamklan, I'm not sure what you are requesting. If you want to unlock your Nokia Lumia 710, you'll need to contact the Phone Carrier to which the phone is

  • I have HTC HD7 and zune will freeze my phone forcing me to take out the battery. Any ideas? 2013-08-14

    I have HTC HD7 and zune will freeze my phone forcing me to take out the battery. If my phone is locked and I try to play music the phone will freeze. I'm about to unsubscribe if there is not a solution to this issue. --------------Solutions----------

  • Android activity freezing, need assistance interpreting log 2011-04-15

    These events have recently been linked to the call mSurfaceHolder.unlockCanvasAndPost(canvas); Hey guys, been working on this app for a while now and every now-and-then it will simply freeze on me, sometimes returning normally and others simply crash

  • changed motherboard and now unable to active even by phone. 2012-12-18

    I have recently changed my motherboard, now I am unable to activate my windows, I even tried the phone option but it does not work. I have been trying to call customer services in India but they do not pick the call and simply disconnect the call. My

  • Joomla: localizing user registration, activation email & messages 2010-05-08

    I need to know please, where to localize the messages that are displayed when registering new user ?? for ex" Joomla User successfully registered." or "Your Account has been successfully activated. You can now log in using the username and password y

  • Equals sign in django-registration activation url 2010-11-27

    I am using django-registration and for some reason, when it sends the activation email, it inserts an equals sign in the third to last character as such: http://example.com/accounts/activate/a65b4aca5156211bc522e29f3e872290544d14= e4/ This means the

  • Activity lifecycle during phone display timeouts 2011-01-30

    Today I noticed something rather interesting. The activity lifecycle seems to have a slight discrepancy when the phone display times out. Let me explain with an example. I have an activity that uses the accelerometer to vibrate the phone. In the onPa

  • Monitor network activity in Android Phones 2011-02-25

    HI everyone, I would like to monitor network traffic of my Android Phone. I was thinking using tcpdump for Android, but I'm not sure If I have to cross-compile for the phone. Another question is the following, If I want to monitor the trafic data for

  • Is it possible to launch an android application activity when the phone starts? 2011-09-13

    Im attempting to build an android application and one of the key features to this application is for it to be able to launch an activity automatically when the phone starts, I see some apps on my phone that already do this, any help would be great so

  • How to prevent collisions when generating registration activation keys? 2011-11-11

    I'm working on a big project's registration system. After successful signup, the server generates some activation key, adds it to user's row and sends it to user by email. Using some password generator class for this purpose. The question is (I know

  • Keep agent active in windows phone 2011-11-17

    I want a service to be active always in the background. Is this possible in the new SDK 7.1 I read through the Background File Transfers, Agents, and Alarms. I think these are only active for a period of time. --------------Solutions------------- Sho

  • active sync, 2 phones, 1 computer 2012-08-09

    I have an HTC Tytn with WM6pro and an HTC Tytn II with WM 6.1 I need to be able to sync both phones up with different identities in outlook for contacts and calendars on one computer. However active sync will only recognise one phone so I have to del

  • Activation my Windows Phone 7 2012-03-21

    Hi, I have windows phone 7 and when I sign in the marketplace with my Windows Live ID it show me "Activation Failed". I need a help to solve this issue.. please. --------------Solutions------------- On Mon, 17 Jan 2011 21:45:14 +0000, David A Matson

  • ActiveSync 4.5 only finds my Treo 700WX as a Guest after 2nd reload of the Active Sync. Phone has WM 5.0 Treo Software Ver. 1.17-SPNT 2012-08-18

    I just got this phone a few days ago from a friend. The phone is over 1 year old but looks like a new one. I installed the Active Sync 4.5 from the website and it worked perfect. The software found my phone and lt let me sync up to my outlook and my

  • Activation Code Windows Phone 7 2012-08-23

    Where can i find my activation code for my phone... I upgraded from HTC HD2 Wm6.5 to HTC HD7 Wp7 but when i put my windows live id in, it asks me for an activation code, why.... It is a new phone and i have never had this problem before...A few of my

  • Internet Explorer 11 browser activity while cell phone is charging 2012-11-02

    Try this experiment: I did with my old and new cell phone, two different brands of android phones and two different carriers (even though one phone is connected to the internet via my Belkin Wi-fi router to the Internet as it no longer has dedicated

  • I have the original/authentic XP install disc and product code. Is activating it by phone the only option? 2013-01-21

    The title says it all. The reason I ask is that I'm in a third world country and my mobile phone does not connect well, in terms of voice quality, to overseas locations. Thank you. --------------Solutions------------- How to activate Windows XP http:

  • activation code windows phone htc hd2 2013-03-31

    hi im chirag --------------Solutions------------- Hi Ramanujchirag, The HTC HD2 is not an phone that is officially supported for an activation code for Windows Phone 7. The HTC HD7 is. Sir Im Asking For Activation Code of my HTC Hd7

  • Stupid activation process disconnects phone in India. 2013-07-04

    I had to reset my windows 8 pro installation due to some faulty drivers and windows was asking me to activate again now. I got an error 0xc004c008 and it says its already activatedon another pc. I only have one pc. I tried calling phone activation nu

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.138 (s). 11 q(s)