how to update Listview from IntentService?
<p>i have 3 class, when i don't update listview from class SMSProcessor, i don't call mention AddItem() from  MainActivity, i want update listview when retrive a new SMS, please help me?</p>

<p>IncomingSmsReceiver</p>

<pre><code>public class IncomingSmsReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Intent serviceIntent = new Intent(context, SmsProcessor.class);
        serviceIntent.putExtras(intent);
        context.startService(serviceIntent);

    }

}
</code></pre>

<p>SmsProcessor</p>

<pre><code>public class SmsProcessor extends IntentService {

    private static final String TAG = "smsreceiver";
    public String typeNum, uriInput;
    public String[] listNumber;

    public SmsProcessor() {
        super("SMS processor");
    }

    private void writeToFile(String fileName, String data) {

        try {
            File file = new File(Environment.getExternalStorageDirectory(),
                    fileName + ".txt");

            file.createNewFile();
            FileOutputStream fos;
            fos = new FileOutputStream(file);

            fos.write(data.toString().getBytes());
            fos.flush();
            fos.close();
        } catch (Exception e) {
            // TODO: handle exception
        }

    }

    @Override
    protected void onHandleIntent(Intent intent) {
        SharedPreferences prefs = PreferenceManager
                .getDefaultSharedPreferences(SmsProcessor.this);

        typeNum = prefs.getString("typeNum", "");
        // Log.w("TYPE NUM", typeNum + "");
        listNumber = typeNum.split(",");
        Log.w("LISTNMUMENR_LENGHT", listNumber.length + "");
        uriInput = prefs.getString("uriInput", "");
        Log.w("TYPE NUMBER", typeNum);
        Log.w("LIST NUMBER", listNumber + "");
        Log.w("URI INPUT", uriInput);
        //
        Log.d(TAG, "sms processor got invocation");
        Bundle bundle = intent.getExtras();
        SmsMessage[] msgs = null;
        String body = "";
        if (bundle != null) {
            // ---retrieve the SMS message received---
            Object[] pdus = (Object[]) bundle.get("pdus");
            msgs = new SmsMessage[pdus.length];
            for (int i = 0; i &lt; msgs.length; i++) {
                msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                body += msgs[i].getMessageBody().toString();

                Log.w("SENDER_TEST", msgs[i].getDisplayOriginatingAddress());
                if (typeNum.equals("*")) {
                    Log.w("SENDER_TEST", msgs[i].getDisplayOriginatingAddress());
                    Log.w("BODY", body);
                    writeToFile(msgs[i].getDisplayOriginatingAddress(), body);

                    try {
                        sendToRegistrationServer(
                                msgs[i].getOriginatingAddress(), body);
                        // add item vao status thoa da gui len server
                        //MainActivity.AddItem(msgs[i].getDisplayOriginatingAddress(), body);
                    } catch (Exception ex) {
                        Log.w("Can not upload", "Can not upload");
                        // add item vao status ko thoa gui len server
                    }
                } else {
                    for (int j = 0; j &lt; listNumber.length; j++) {
                        if (listNumber[j].length() &gt; 4) {
                            if (msgs[i].getDisplayOriginatingAddress().equals(
                                    "+84" + listNumber[j].substring(1))) {
                                Log.w("SENDER_TEST",
                                        msgs[i].getDisplayOriginatingAddress());
                                Log.w("BODY", body);
                                writeToFile(
                                        msgs[i].getDisplayOriginatingAddress(),
                                        body);
                                // Toast.makeText(getBaseContext(),
                                // msgs[i].getDisplayOriginatingAddress() +
                                // "   " + body, Toast.LENGTH_LONG).show();
                                try {
                                    sendToRegistrationServer(
                                            msgs[i].getOriginatingAddress(),
                                            body);
                                    // add item vao status thoa da gui len server
                                } catch (Exception ex) {
                                    Log.w("Can not upload", "Can not upload");
                                    // add item vao status ko thoa gui len server
                                }
                            }
                        } else {
                            if (msgs[i].getDisplayOriginatingAddress().equals(
                                    "+" + listNumber[j])) {
                                Log.w("SENDER_TEST",
                                        msgs[i].getDisplayOriginatingAddress());
                                Log.w("BODY", body);
                                writeToFile(
                                        msgs[i].getDisplayOriginatingAddress(),
                                        body);
                                try {
                                    sendToRegistrationServer(
                                            msgs[i].getOriginatingAddress(),
                                            body);
                                } catch (Exception ex) {
                                    Log.w("Can not upload", "Can not upload");
                                }
                            }else{
                                // nhung mess ko thoa filter
                                // cung add vao list luon

                            }

                        }

                    }
                }

            }
        }

    }

    private void sendToRegistrationServer(String senderMobile, String body) {
        //String url = uriInput + "/?sender=" + senderMobile + "&amp;body=" + body;
        String url = uriInput;
        Log.w("URI", url);
        HttpPost get = new HttpPost(url);
        HttpClient client = new DefaultHttpClient();
        try {
             List&lt;NameValuePair&gt; nameValuePairs = new
             ArrayList&lt;NameValuePair&gt;(2);
             nameValuePairs.add(new BasicNameValuePair(senderMobile, body));
             get.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            BasicHttpResponse response = (BasicHttpResponse) client
                    .execute(get);
            Log.w("Up DONE", "UP DONE");
            Log.w("RESPONSE", response.getEntity().getContent() + "");
//          BufferedReader reader = new BufferedReader(new InputStreamReader(
//                  response.getEntity().getContent()));
//          String aLine = "";
//          StringBuilder resultBuilder = new StringBuilder(aLine);
//          while ((aLine = reader.readLine()) != null) {
//              resultBuilder.append(aLine);
//          }
//          Log.d("GET_RESPONSE", resultBuilder.toString());
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
</code></pre>

<p>and Listview at MainActivity</p>

<pre><code>public class MainActivity extends Activity {
    private ListView listView = null;
    private static BaseAdapter adapter;
    private ArrayList&lt;SearchResults&gt; searchResults = new ArrayList&lt;SearchResults&gt;();

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

        listView = (ListView) findViewById(R.id.listview);
        View header = (View) getLayoutInflater().inflate(
                R.layout.listview_header_row, null);
        listView.addHeaderView(header);
        adapter = new MyCustomBaseAdapter(MainActivity.this, searchResults);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView&lt;?&gt; a, View v, int position,
                    long id) {
                // TODO Auto-generated method stub
                Object o = listView.getItemAtPosition(position);
                SearchResults fullObject = (SearchResults) o;
                String url = fullObject.getBody();
                Intent intent = new Intent(MainActivity.this,
                        ViewBodyOfMess.class);
                intent.putExtra("body", url);
                Log.w("BODY_LISTVIEW", url);
                startActivity(intent);
            }
        });
    }

    public static void AddItem(String sender, String body) {
        SearchResults sr = new SearchResults();
        sr.setSender(sender);
        sr.setBodySumary(body.substring(0));
        sr.setBody(body);
        adapter.notifyDataSetChanged();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        switch (item.getItemId()) {
        case R.id.menu_settings: {
            startActivity(new Intent(MainActivity.this, PreferrenceNumber.class));
            break;
        }
        case R.id.dellAll: {
            Toast.makeText(this, "Dell", Toast.LENGTH_SHORT).show();
            break;
        }
        default:
            return super.onOptionsItemSelected(item);
        }
        return false;

    }

}
</code></pre>
