Я нашел решение.Использование метода onReceive BroadcastReceiver
`
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = SmsMessage.createFromPdu((byte[])pdus[0]);
Log.i(TAG, msgs.getMessageBody());
Intent intent2 = new Intent("com.uba.messagereceived");
str = "SMS From "+msgs.getOriginatingAddress()+":"+msgs.getMessageBody().toString()+"...";
intent2.putExtra("letter", str);
intent2.putExtra("address", msgs.getOriginatingAddress());
intent2.putExtra("txt", msgs.getMessageBody().toString());
context.sendBroadcast(intent2);
}
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
if(yMsg == msgg && xNum == no)
{
setStatus("valid");
Intent mp = new Intent(context,UserMainPage.class);
context.startActivity(mp );
Toast.makeText(context,"The Validation completed: "+this.getStatus(), Toast.LENGTH_SHORT).show();
}
else
{
setStatus("not Valid");
Toast.makeText(context,"The Validation completed: "+this.getStatus(), Toast.LENGTH_SHORT).show();
}
}
`