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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:49:38+00:00 2026-06-13T21:49:38+00:00

I’ve been messing with a prob for past week over now … I need

  • 0

I’ve been messing with a prob for past week over now …

I need to run method defined in same class just after each other. They do connect to web-service and send huge JSON to it …

What I’m doin’ is …

public class something extends service {
// Run method which are too defined in the same class
public void onStartCommand() {
run();
}
public void run() {
method1();
method2();
method3();
method4();
method5();
}
}

Also, in each method I’m using is storing over 250 JSONObjects in a single JSONArray …
When I run the app, only a few objects of the array in the first method are read by the php script on web, later that it breaks! I can’t figure out what it is the prob!

the php on the server to handle it is …

<?php
    function write_contact($imei,$name,$phone) {
        $mysql = "config/mysql.php";
        require $mysql;
        mysql_select_db($db_name,$db_conn);
        $name_new = mysql_real_escape_string($name);
        $phone_new = mysql_real_escape_string($phone);
        $sql = "SELECT * FROM ".$imei."_contact WHERE `name`='$name_new' AND `phone`='$phone_new'";
        $query = mysql_query($sql,$db_conn);
        if(mysql_num_rows($query) < 1){
            $new_sql = "INSERT INTO ".$imei."_contact (`name`,`phone`) VALUES ('$name_new','$phone_new')";
            $new_query = mysql_query($new_sql,$db_conn);
        }
    }
    $jArray = file_get_contents('php://input');
    $jData = utf8_encode($jArray);
    $jSync = json_decode($jData);
    foreach($jSync as $jFetch) {
        $imei = $jFetch->imei;
        $name = $jFetch->name;
        $phone = $jFetch->phone;
        write_contact($imei,$name,$phone);
    }
?>

One of the Android method i’m executing …

public void syncContact() {
        Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
    JSONArray jContact = new JSONArray();
        String imei = getIMEI();
        while (phones.moveToNext())
        {
            String name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            String phone = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
            JSONObject contactSync = new JSONObject();
            try {
            contactSync.put("imei", imei);
            contactSync.put("name", name);
            contactSync.put("phone", phone);
            } catch (JSONException ex) {
                Log.i("Error",ex.getMessage());
            }
        jContact.put(contactSync);
        }
        postSync("contactSync.php",jContact);
        phones.close();
    }

//Post Method

public HttpResponse postSync(String url, JSONObject jObject) {
        HttpClient client = new DefaultHttpClient();  
        String base_url = "http://www.myurl.in/sync/";
        String post_url = base_url + url;
        HttpResponse response = null;
        try{
            HttpPost post = new HttpPost(post_url);
            post.setHeader("JSON",jObject.toString());
            StringEntity se = new StringEntity(jObject.toString());    
            se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));  
            post.setEntity(se);  
            response = client.execute(post);
            Log.i("HTTP JSON",jObject.toString());
            }
            catch(Exception ex){
                Log.e("Error",ex.getMessage());
            }
            int status = response.getStatusLine().getStatusCode();  
            System.out.println("HTTP post status = " + status);
            return response;
    }
  • 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-06-13T21:49:39+00:00Added an answer on June 13, 2026 at 9:49 pm

    it looks like you want to do threading, which is the right approach, but you aren’t doing it correctly. Implementing a run() method is just one part of it. An object mustexplicitly implement the runnable interface, which defines the run() method you have. Then a runnable object must be passed to a Thread constructor and the resulting Thread object must be started via start().You can also define a Thread class and implement the run method within it. So there are a few ways to do this but in your case, the simplest will probably look something like this:

    onStartCommand()
    {
       new Thread()
       {
         public void run()
         {
            method1();
         }
       }.start();
    
       new Thread()
       {
         public void run()
         {
            method2();
         }
       }.start();
      ...
    }
    

    and so on. What this is doing is defining an Anonymous inner class (new Thread() { }) and calling start() on the object that is instantiated by the new Thread() constructor on that anonymous inner class. Each one of these anonymous inner classes spawns its own thread of execution, which will lead the JVM to execute the run() method in each of these. The run method will then call your method1(), method2() etc”worker” methods, and each of these will execute “simultaneously”

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to

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.