好吧,我有一个扩展广播接收器的类,它正在监听消息。现在,每当它收到一条消息时,我都会创建我的应用程序的一个新实例。所以当我关闭它时,我必须点击返回按钮 2 次。谁能帮我?
public class SMSReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle myBundle = intent.getExtras();
SmsMessage [] messages = null;
String strMessage = "";
String phoneNumber = "";
if (myBundle != null) {
Object [] pdus = (Object[]) myBundle.get("pdus");
messages = new SmsMessage[pdus.length];
for (int i = 0; i < messages.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
strMessage += "SMS From: " + messages[i].getOriginatingAddress();
strMessage += " : ";
strMessage += messages[i].getMessageBody();
strMessage += "\n";
phoneNumber = messages[i].getDisplayOriginatingAddress();
}
if (phoneNumber.equals("T-Mobile")) {
Toast.makeText(context, strMessage, Toast.LENGTH_SHORT).show();
abortBroadcast();
}
}
}
}