how to delete all current and previoues messages from specific number
<p>This code only deletes the last message form specific number not all message from specific number what i do so its delete all messages? </p>

<p>If i send 3 messages before running the application then running the application when a new message is received will stop the application. I</p>

<p>f i delete all messages from inbox manually then sent SMS from specific number after start application then its work fine so how i modify this code to check previous messages also with specific number in inbox and delete them all.</p>

<pre><code>public class SmsReceiver extends BroadcastReceiver {    
String specificPhoneNumber = "15555215554";

public void onReceive(Context context, Intent intent) {

    abortBroadcast();
    //---get the SMS message passed in---
    Bundle bundle = intent.getExtras();        
    SmsMessage[] msgs = null;
    String str = "";     
    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]);                

            String phNum = msgs[i].getOriginatingAddress();  

            str += msgs[i].getMessageBody().toString();
            if (specificPhoneNumber.equals(phNum)){
                Uri uri = Uri.parse("content://sms/inbox");
                ContentResolver contentResolver = context.getContentResolver();
                String where = "address="+phNum;
                Cursor cursor = contentResolver.query(uri, new String[] { "_id", "thread_id"}, where, null,null);
                while (cursor.moveToNext()) {               
                long thread_id = cursor.getLong(1);
                    where = "thread_id="+thread_id;
                    Uri thread = Uri.parse("content://sms/inbox");
                    context.getContentResolver().delete(thread, where, null);

                }
                  Intent l = new Intent(context,AgAppMenu.class);
                  l.putExtra("msg",str);
                  l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(l);                   
        }}}
</code></pre>
