Code is getting stuck in TimerTask and JSON string not being recieved
<p>Hi I'm trying to send a json string to a server and get json in return to populate a listview.  I'm trying to figure out why my code is getting stuck on this line:</p>

<pre><code>sendBytes(ConvertStringToByteArray(outputJSONserv), 0, ConvertStringToByteArray(outputJSONserv).length);
</code></pre>

<p>and why I'm not getting any json back on this line of code:</p>

<pre><code>inputJSON = ConvertByteArrayToString(getBytesFromInputStream(inputStr));
</code></pre>

<p>The json string I'm trying to send is in the variable "outputJSONserv".  inputJSON is the variable that is suppose to store the json received from the server using inputStr as an InputStream.  refreshViewModels is suppose to refresh the listview with the json string from the server.  I'm using a timer task to send and receive json strings and refresh the listview every X seconds.  I'm struggling to fix this issue with populating the listview.  The code tends to be getting hung up all the time in the TimerTask.  If anyone code provide to proper code to help me accomplish this it would be greatly appreciated.  I'm also available on chat if need to discuss anything. Any pointers would be helpful.</p>

<p>Here is my code:</p>

<pre><code>public class AndroidClient extends ProfileActivity {

private TextView textIn;

public Thread rt;
//public RepeatingThread rt;
public Socket socket = null;
public PrintWriter outputstrwr;
public OutputStream out = null; 
public DataOutputStream dataOutputStream = null;
public DataInputStream dataInputStream = null;
public DataInputStream dis = null;

public InputStream inputStr = null;

private final static String LOG_TAG = AndroidClient.class.getSimpleName();
private final Handler handler = new Handler();
private List&lt;Profile&gt; serviceInfoList = new ArrayList&lt;Profile&gt;();

private Map&lt;Integer, Profile&gt; posMap = new HashMap&lt;Integer, Profile&gt;();
private Map&lt;String, Integer&gt; addressMap = new HashMap&lt;String, Integer&gt;();

private static String profilePicBase64Str="";
private String inputJSON = "";
private String outputJSON = "";
private String outputJSONserv = "";
private Profile p;
//String urlInputStream = "";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Log.e(LOG_TAG, "Before OnCreate() Try");
    try {
        Log.e(LOG_TAG, "In OnCreate() Try");
        socket = new Socket("23.23.175.213", 9000);  //Port 1337
        Log.e(LOG_TAG, "Created Socket");
        dataOutputStream = new DataOutputStream(socket.getOutputStream());
        Log.e(LOG_TAG, "Created DataOutputStream");
        dataInputStream = new DataInputStream(socket.getInputStream());
        Log.e(LOG_TAG, "Created DataInputStream");

        //out = new OutputStream();
        out = socket.getOutputStream();
        inputStr = socket.getInputStream();

        //Thread readjsonthrd = new Thread(new ReadJSONThread());
        //inputstrrd = new InputStreamReader(socket.getInputStream());

        p = new Profile();
        Log.e(LOG_TAG, "Created Profile Instance");

        //Gets the local profile via JSON and converts into Profile type
        Gson gson = new Gson();
        Log.e(LOG_TAG, "Created Gson Instance" + "GetProfileJSONStr:" + p.getProfileJSONStr());
        p = gson.fromJson(p.getProfileJSONStr(), Profile.class);
        setProfile(p);
        Log.e(LOG_TAG, "Converted Profile to JSON");

        //Gson gson = new Gson();
        Log.e(LOG_TAG, "Before: outputJSON = gson.toJson(p);");
        outputJSON = gson.toJson(p).toString();
        outputJSON = removeExcessStr(outputJSON);
        Log.e(LOG_TAG, "ProfilePicStr Base64:"+p.getProfilePicStr());

        outputJSON = outputJSON.replace("Name","name");
        outputJSON = outputJSON.replace("TagLine","message");
        outputJSON = outputJSON.replace("Title","title");
        outputJSON = outputJSON.replace("Company", "company");
        outputJSON = outputJSON.replace("Industry","industry");
        outputJSON = outputJSON.replace("WhatIDo","whatido");
        outputJSON = outputJSON.replace("WhoDoIWantToMeet","meetwho");
        outputJSON = outputJSON.replace("WHOOZNEAR_PROFILEPIC","photo");
        outputJSON = outputJSON.replaceAll("[c][o][n][t][e][n][t][:][/][/][a-zA-Z0-9]+[/][a-zA-Z0-9]+[/][a-zA-Z0-9]+[/][a-zA-Z0-9]+[/][a-zA-Z0-9]+", getPicBase64Str()); /*"helloworld2"*/

        if (!outputJSON.contains(",\"photo\":")) { 
            outputJSON = outputJSON.replace("}",",\"photo\":"+"\"IconnexUs\"}");
            outputJSON = outputJSON.replace("}",",\"photo\":"+"\""+getPicBase64Str()+"\"}");
            outputJSON = outputJSON.replace("}",",\"status\":\"enabled\"}");
        }
        else { 
            outputJSON = outputJSON.replace("}",",\"status\":\"enabled\"");
        }

        outputJSONserv = "{\"to\":\"broadcast\",\"type\":\"1\",\"payload\":"+outputJSON+"}";

        Log.e(LOG_TAG, "Created outputJSON:" + outputJSON);
        Log.e(LOG_TAG, "Created outputJSON Server:" + outputJSONserv);
        JSONObject outObject = new JSONObject();
        try {
            outObject.put("photo", "hello");
            outObject.put("type", "50");
            outObject.put("payload", outputJSON);
            outputJSON = gson.toJson(outObject).toString();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Log.e(LOG_TAG, "Value of PROFILEPIC STRING FROM PROFILEMAP: ");
        p.setProfilePicStr(ConvertandSetImagetoBase64(profileMap.get("WHOOZNEAR_PROFILEPIC")));
        //String headerJSON = gson.toJson(outObject).toString();
        outputJSON = outputJSON.substring(nthOccurrence(outputJSON, '{', 2)-1, nthOccurrence(outputJSON, '}', 1)-1);

        String input = "["+"Ryan"+"[";
        //"[foo".replaceAll(Pattern.quote("["), "\""); 
        String result = input.replaceAll(Pattern.quote("["), "\"");
        Log.e(LOG_TAG, "REGEX REPLACEALL:"+result);

        outputstrwr = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
        outputstrwr.write(outputJSONserv);

        Log.e(LOG_TAG, "Base64 String:"+p.getProfilePicStr());
        Log.e(LOG_TAG, "Sent dataOutputStream");
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Log.e(LOG_TAG, "Before initEventHandlers");
    initEventHandlers();
    Log.e(LOG_TAG, "After initEventHandlers");
    //refreshViewModels();

    /*Log.e(LOG_TAG, "Start Repeat Thread");
    rt = new Thread(new RepeatingThread());
    //rt = new RepeatingThread();
    rt.start();
    Log.e(LOG_TAG, "Started Repeat Thread");*/

    Log.e(LOG_TAG, "Start Repeat Timer");
    TimerTask task = new RepeatingTask();
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(task, 0, 3000);
    Log.e(LOG_TAG, "Started Repeat Timer");
}

@Override
public void onDestroy() {
    super.onDestroy();
    //rt.stop();
    try {
        //socket.close();
        dataOutputStream.close();
        dataInputStream.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

@Override
public void onPause() {
    super.onPause();
    //rt.stop();
}

@Override
public void onResume() {
    super.onResume();
    /*if (rt.isAlive() == false) {
        //rt.start();
    }*/
}

@Override
public void onStop() {
    super.onStop();
    //rt.stop();
    try {
        //socket.close();
        dataOutputStream.close();
        dataInputStream.close();
        inputStr.close();
        dis.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
public static String removeExcessStr(String json_excess) {      
    //String myString = myString.replace("=\"ppshein\"", "");
    String json_excess1 = json_excess.replace("\"nameValues\":{", "");
    String myString = json_excess1.replace(",\"profileId\":1,\"valid\":false}", "");
    return myString;
}
public static String adddblquotattr(String attr) { 
    String result = attr.replaceAll(Pattern.quote("["), "\"");
    return result;
}

public static String adddblquotval(String val) { 
    String result = val.replaceAll(Pattern.quote("["), "\"");
    return result;
}

public static int nthOccurrence(String str, char c, int n) {
    int pos = str.indexOf(c, 0);
    while (n-- &gt; 0 &amp;&amp; pos != -1)
        pos = str.indexOf(c, pos+1);
    return pos;
}

public void setPicBase64Str(String profilePicBase64Str) {
    this.profilePicBase64Str = profilePicBase64Str;
}

public String getPicBase64Str() {
    return profilePicBase64Str;
}

public String ConvertandSetImagetoBase64(String imagePath) { 
    String base64 = null;
    byte[] input = null;

    try{
        FileInputStream fd = new FileInputStream(imagePath);
        Bitmap bmt = BitmapFactory.decodeFileDescriptor(fd.getFD());

        try{                
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            Bitmap tmp = ProfileActivity.scaleDownBitmap(bmt, 10, this);
            tmp.compress(Bitmap.CompressFormat.JPEG, 10, stream);
            input = stream.toByteArray();
            base64 = Base64.encodeToString(input, Base64.DEFAULT);
            //LocalProfileActivity.input = input;
        }catch(Exception e){
            Log.e(LOG_TAG,"[ONACTIVITYRESULT] Could not bind input to the bytearray: " + e.getMessage());
        }
    }
    catch (Exception e){
        Log.e("LocalProfile", "ConvertandSetImagetoBase64: Could not load selected profile image");
    }
    return base64;
}

public String getStringFromBuffer(InputStreamReader inputstrread) {
    BufferedReader bRead = new BufferedReader(inputstrread);
    String line = null;
    StringBuffer jsonText = new StringBuffer();
    try {
        while((line=bRead.readLine())!=null){
           jsonText.append(line);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return jsonText.toString();
}

public String ConvertByteArrayToString(byte[] b) { 
    // byte[] to string
    String input = new String(b);
    return input;
}

public byte[] ConvertStringToByteArray(String str) { 
    // string to byte[]
    byte[] bytes = str.getBytes();
    return bytes;
}

public static byte[] getFileBytes(InputStream is) throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    BufferedInputStream fin = new BufferedInputStream(is);
    //byte buf[] = new byte[8192];
    byte buf[] = new byte[500000];
    int ret = 0;
    while ((ret = fin.read(buf)) != -1) {
    bout.write(buf, 0, ret);
    }
    fin.close();
    return bout.toByteArray();
}

public byte[] readBytes(InputStream in) throws IOException {
    Log.e(LOG_TAG, "readBytes1");
    in = socket.getInputStream();
    Log.e(LOG_TAG, "readBytes2");
    DataInputStream dis = new DataInputStream(in);
    Log.e(LOG_TAG, "readBytes3");
    int len = dis.readInt();
    Log.e(LOG_TAG, "readBytes4");
    byte[] data = new byte[len];
    Log.e(LOG_TAG, "readBytes5");
    if (len &gt; 0) {
        Log.e(LOG_TAG, "readBytesIF1");
        dis.readFully(data);
        Log.e(LOG_TAG, "readBytesIF2");
    }
    Log.e(LOG_TAG, "readBytes6");
    return data;
}

public void sendBytes(byte[] myByteArray, int start, int len) throws IOException {
    if (len &lt; 0)
        throw new IllegalArgumentException("Negative length not allowed");
    if (start &lt; 0 || start &gt;= myByteArray.length)
        throw new IndexOutOfBoundsException("Out of bounds: " + start);
    // Other checks if needed.

    // May be better to save the streams in the support class;
    // just like the socket variable.

    OutputStream out = socket.getOutputStream(); 
    DataOutputStream dos = new DataOutputStream(out);

    dos.writeInt(len);
    if (len &gt; 0) {
        dos.write(myByteArray, start, len);
    }

    //OutputStream out = socket.getOutputStream(); //COMMENTED THIS OUT

    //DataOutputStream dos = new DataOutputStream(out); //COMMENTED THIS OUT

    /*dataOutputStream.writeInt(len);    //COMMENTED THIS OUT
    if (len &gt; 0) {
        dataOutputStream.write(myByteArray, start, len);
    }*/
}

public byte[] getBytesFromInputStream(InputStream is) throws IOException {
        //BEGINNING OF ADDED CODE FOR LENGTH
        dis = new DataInputStream(is);
        int length = dis.readInt();
        //END OF ADDED CODE FOR LENGTH

        // Get the size of the file
        //int length = is.available();

        if (length &gt; Integer.MAX_VALUE) {
        // File is too large
        }

        // Create the byte array to hold the data
        byte[] bytes = new byte[(int) length];

        // Read in the bytes
        int offset = 0;
        int numRead = 0;
        while (offset &lt; bytes.length
        &amp;&amp; (numRead = is.read(bytes, offset, bytes.length - offset)) &gt;= 0) {
        offset += numRead;
        }
        // Ensure all the bytes have been read in
        if (offset &lt; bytes.length) {
        throw new IOException("Could not completely stream ");
        }
        // Close the input stream and return bytes
        is.close();
        return bytes;
}

public static String writeFile(Bitmap finalBitmap) { 
    String filePath = "";

    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/saved_images");    
        myDir.mkdirs();
        Random generator = new Random();
        int n = 10000;
        n = generator.nextInt(n);
        String fname = "Image-"+ n +".jpg";
        File file = new File (myDir, fname);
        if (file.exists ()) file.delete (); 
        try {
               FileOutputStream outFile = new FileOutputStream(file);
               finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, outFile);
               outFile.flush();
               outFile.close();

        } catch (Exception e) {
               e.printStackTrace();
        }
    filePath = root+"/saved_images/"+fname;
    return filePath;
}

public class RepeatingTask extends TimerTask {
     //private int len = 0; 
     //private byte[] input = new byte[len];

     public RepeatingTask() {
            Log.e(LOG_TAG, "In RepeatingTask()");
            Log.e(LOG_TAG, "Before inputJSON String");

            String hello = "hello world";
            //String inputJSON = getStringFromBuffer(new InputStreamReader(socket.getInputStream()));
            try {
                Log.e(LOG_TAG, "Hello String:"+inputStr);
                sendBytes(ConvertStringToByteArray(outputJSONserv), 0, ConvertStringToByteArray(outputJSONserv).length);
                inputJSON = ConvertByteArrayToString(getBytesFromInputStream(inputStr));
                Log.e(LOG_TAG, "Hello String2:"+inputJSON);

                Log.e(LOG_TAG, "Hello String3:"+hello);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            //Convert 
            Log.e(LOG_TAG, "After inputJSON String:" + inputJSON); 


         //LOOK HERE FIRST  
         //inputJSON is what is received back from the server - Take the inputJSON 
         //String and use regular expressions HERE to remove all the other characters in the 
         //string except the payload JSON.
         //refreshViewModels(inputJSON);
     }

     @Override
     public void run() { 
          /*try {
              Log.e(LOG_TAG, "IN REPEATINGTHREAD-INPUTJSON");
              //outputstrwr.write(outputJSONserv);  //UNCOMMENT IF NEED TO SEND DATA TO GET JSON BACK
              //inputJSON = ConvertByteArrayToString(getBytesFromInputStream(inputStr));
              inputJSON = ConvertByteArrayToString(getFileBytes(inputStr));
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }

          Log.e(LOG_TAG, "IN REPEATINGTHREAD-INPUTJSON2:" + inputJSON);
          refreshViewModels(inputJSON);*/

      try {
          Log.e(LOG_TAG, "IN REPEATINGTHREAD-INPUTJSON");
          //outputstrwr.write(outputJSONserv);  //UNCOMMENT IF NEED TO SEND DATA TO GET JSON BACK
          //byte[] = myByteArray = readBytes(inputStr);
          sendBytes(ConvertStringToByteArray(outputJSONserv), 0, ConvertStringToByteArray(outputJSONserv).length);
          //sendBytes(myByteArray, 0, myByteArray.length);
          Log.e(LOG_TAG, "AFTER SENDING DATA");
          //inputJSON = ConvertByteArrayToString(getBytesFromInputStream(inputStr));
              inputJSON = ConvertByteArrayToString(getBytesFromInputStream(inputStr));
              Log.e(LOG_TAG, "IN REPEATINGTHREAD-INPUTJSON2:" + inputJSON);
      } 
      catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
      }

      Log.e(LOG_TAG, "IN REPEATINGTHREAD-INPUTJSON3:" + inputJSON);
      //refreshViewModels(inputJSON);   //UNCOMMENT THIS AFTER I GET IT WORKING
     }
}

/*public class RepeatingThread extends Thread implements Runnable {

     private final Handler mHandler = new Handler();
     private int len = 0; 


     private byte[] input = new byte[len];


     public RepeatingThread() {
         //try {
            Log.e(LOG_TAG, "Before inputJSON String");
            //inputJSON = dataInputStream.readUTF();
            //URL url = new URL("tcp://23.23.175.213:1337");
            //inputJSON = dataInputStream.readUTF();
            //inputstrrd = new InputStreamReader(socket.getInputStream());
            String hello = "hello world";
            //String inputJSON = getStringFromBuffer(new InputStreamReader(socket.getInputStream()));
            try {
                outputstrwr = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            //Convert 
            Log.e(LOG_TAG, "After inputJSON String:" + inputJSON); 
         /*}
         catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }*/

         //LOOK HERE FIRST  
         //inputJSON is what is received back from the server - Take the inputJSON 
         //String and use regular expressions HERE to remove all the other characters in the 
         //string except the payload JSON.
         //refreshViewModels(inputJSON);
/*         }

     @Override
     public void run() { 
          try {
              Log.e(LOG_TAG, "IN REPEATINGTHREAD-INPUTJSON");
              outputstrwr.write(outputJSONserv);  //UNCOMMENT IF NEED TO SEND DATA TO GET JSON BACK
              Log.e(LOG_TAG, "AFTER SENDING DATA");
              //inputJSON = ConvertByteArrayToString(getBytesFromInputStream(inputStr));
              inputJSON = ConvertByteArrayToString(readBytes(inputStr));
              Log.e(LOG_TAG, "IN REPEATINGTHREAD-INPUTJSON2:" + inputJSON);
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }

          Log.e(LOG_TAG, "IN REPEATINGTHREAD-INPUTJSON3:" + inputJSON);
          refreshViewModels(inputJSON);
          mHandler.postDelayed(this, 3000);       
     }
}*/

    public void refreshViewModels(String inputJSON) {

        try {
            ListView servicesListView = (ListView) this
                    .findViewById(R.id.profilesListView);

            String[] from = new String[] { "profilePic", "neighborName",
                    "tagLine" };
            int[] to = new int[] { R.id.avatar, R.id.username, R.id.email };

            // prepare the list of all records
            List&lt;HashMap&lt;String, Object&gt;&gt; fillMaps = new ArrayList&lt;HashMap&lt;String, Object&gt;&gt;();
            List&lt;Profile&gt; profiles = new ArrayList&lt;Profile&gt;();

            // Clear the position mapping list and reset it
            this.posMap.clear();
            Log.i(LOG_TAG, "NEW inputJSON: " + inputJSON);
            inputJSON = getPayloadStr(inputJSON);
            Log.i(LOG_TAG, "NEW inputJSON2: " + inputJSON);
            JSONArray profileArray = new JSONArray(inputJSON);

            for (int i=0; i&lt;profileArray.length(); i++) { 
                JSONObject jsonObject = profileArray.getJSONObject(i);
                Gson gson = new Gson(); 
                Profile p = gson.fromJson(gson.toJson(jsonObject).toString(), Profile.class);
                profiles.add(p);
            }

            int pos = 0;

            // Creates the fillMaps list for the listAdapter
            Log.i(LOG_TAG, "Profiles size: " + profiles.size());
            //showToast("Profiles size: " + profiles.size());
            for (Profile p : profiles) {
                // Create mapping for list adapter
                HashMap&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();
                map.put("profilePic",
                        p.getAttributeValue("photo")== null? "Not Set" : p
                                .getAttributeValue("photo"));
                map.put("neighborName",
                        p.getAttributeValue("Name") == null? "Not Set" : p
                                .getAttributeValue("Name"));
                map.put("tagLine",
                        p.getAttributeValue("TagLine") == null? "Not Set" : p
                                .getAttributeValue("TagLine"));
                fillMaps.add(map);

                // Reset the postion mapping
                this.posMap.put(pos++, p);

            }

            ListAdapter servicesListAdapter = new myAdapter(this, fillMaps,
                    R.layout.listitem, from, to);
            servicesListView.setAdapter(servicesListAdapter);

        } catch (Exception e) {
            Log.e(LOG_TAG, "Error making list adapter: " + e.getMessage());
        }

    }

    public String getPayloadStr(String profileString) {
        Log.e("LOG_TAG", "Profile Str:"+profileString);
        Pattern pattern = Pattern.compile(".*?payload\":(.*)\\}");

        Log.e("LOG_TAG", "I got here 1");
        Matcher matcher = pattern.matcher(profileString);
        Log.e("LOG_TAG", "I got here 12");
        //Matcher m = responseCodePattern.matcher(firstHeader);
        matcher.matches();
        matcher.groupCount();
        //matcher.group(0);
        Log.e("LOG_TAG", "I got here 2"+matcher.group(1));
        return matcher.group(1);
    }

     private class myAdapter extends SimpleAdapter {

            public myAdapter(Context context, List&lt;? extends Map&lt;String, ?&gt;&gt; data,
                    int resource, String[] from, int[] to) {
                super(context, data, resource, from, to);

            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {

                if (convertView == null) {
                    convertView = getLayoutInflater().inflate(R.layout.listitem,
                            null);
                }

                HashMap&lt;String, Object&gt; data = (HashMap&lt;String, Object&gt;) getItem(position);

                ((TextView) convertView.findViewById(R.id.username))
                        .setText((String) data.get("neighborName"));

                ((TextView) convertView.findViewById(R.id.email))
                .setText((String) data.get("tagLine"));
                // Convert a string representing an image back to an image
                String base64 = ((String)data.get("profilePic"));
                byte[] picBytes = Base64.decode(base64, Base64.DEFAULT);  
                Bitmap bitmap = BitmapFactory.decodeByteArray(picBytes, 0, picBytes.length);
                if (bitmap==null){
                    ((ImageView) convertView.findViewById(R.id.avatar)).setImageResource(R.drawable.btn_whooznear);
                }else{
                    ((ImageView) convertView.findViewById(R.id.avatar)).setImageBitmap(bitmap);
                }

                return convertView;
            }

        }

     public void callProfileActivity(int position) { 
         // Catch the case when service info is empty
         if(serviceInfoList.size()==0){
             return;
         }
         Profile profClick = posMap.get(position);
         String b64Str = profClick.getAttributeValue("photo");

         Intent startViewActivity = new Intent();
         startViewActivity.putExtra("TransProfile", (Profile)posMap.get(position));
         startViewActivity.putExtra("PhotoBase64", b64Str);
         if(serviceInfoList.size()&gt;position){
             //DO SOMETHING HERE
         }else{
             Log.e(LOG_TAG,"Profile doesn't exist in sevice infoList? Selecting first one");
         }
         startViewActivity.setClass(this, ViewProfileActivity.class);
         startActivity(startViewActivity);
     }
    /**
     * Initialize the event handlers
     */
    public void initEventHandlers() {
        // Service List View
        ListView servicesListView = (ListView) this
                .findViewById(R.id.profilesListView);
        servicesListView
                .setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    public void onItemClick(AdapterView&lt;?&gt; arg0, View v,
                            int position, long id) {
                        Profile clickedProfile = posMap.get(position);
                        //showToast("Clicked Pos: " + position);

                        /*Intent intent = new Intent(ConnectActivity.this, ViewProfileActivity.class);
                        intent.putExtra("ClickProfile", posMap.get(position));*/

                        callProfileActivity(position);  
                    }
                });
    }

    /*@Override 
    public void onBackPressed() { // do something on back.
         super.onBackPressed();
         Intent myIntent = new Intent(AndroidClient.this, ProfileActivity.class);
         startActivity(myIntent);
         return; 
    }*/
}
</code></pre>

<p>Here is the logcat:</p>

<pre><code>E/AndroidClient( 2649): Before OnCreate() Try
E/AndroidClient( 2649): In OnCreate() Try
E/AndroidClient( 2649): Created Socket
E/AndroidClient( 2649): Created DataOutputStream
E/AndroidClient( 2649): Created DataInputStream
E/AndroidClient( 2649): Created Profile Instance
E/AndroidClient( 2649): Created Gson InstanceGetProfileJSONStr:{"nameValues":{"Name":"Ryan","TagLine":"Ho","Title":"Hll","Company":"Dbnbj","Industry":"Comp","What I Do":"Amdroid","Who do I want to meet":"Bye","WHOOZNEAR_PROFILEPIC":"content://media/external/images/media/4"},"profileId":1,"valid":false}
E/ProfileActivity( 2649): profile map data after update: {Name=Ryan, TagLine=Ho, Title=Hll, Company=Dbnbj, Industry=Comp, What I Do=Amdroid, Who do I want to meet=Bye}null
E/AndroidClient( 2649): Converted Profile to JSON
E/AndroidClient( 2649): Before: outputJSON = gson.toJson(p);
E/AndroidClient( 2649): ProfilePicStr Base64:null
E/AndroidClient( 2649): Created outputJSON Server:{"to":"broadcast","type":"1","payload":{"name":"Ryan","message":"Ho","title":"Hll","company":"Dbnbj","industry":"Comp","What I Do":"Amdroid","Who do I want to meet":"Bye","photo":"/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAoHBwgHBgoICA
E/AndroidClient( 2649): Sent dataOutputStream
E/AndroidClient( 2649): Start Repeat Timer
E/AndroidClient( 2649): In RepeatingTask()
E/AndroidClient( 2649): Before inputJSON String
E/AndroidClient( 2649): Hello     String:org.apache.harmony.luni.net.SocketInputStream@45a16410
D/dalvikvm( 2649): GC_FOR_MALLOC freed 162 objects / 808880 bytes in 171ms
E/AndroidClient( 2649): Hello String2:hello world
D/dalvikvm(30894): GC_FOR_MALLOC freed 5341 objects / 506600 bytes in 120ms
</code></pre>
