[英]Android sentIntent of smsManager.sendTextMessage makes UI refresh
Did anyone had this problem before or can someone explain me what's happening? 有人以前有这个问题吗?或者有人可以向我解释发生了什么事?
Code description: Following code takes some information from my object ContactFromXML and sends some textmessages where it needs to. 代码描述:以下代码从我的对象ContactFromXML中获取一些信息,并在需要的地方发送一些文本消息。
Code: 码:
PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
for (int i=0; i<contactsCount;i++){
while(contactsIt.hasNext()){
ContactFromXML contact = contactsIt.next();
if (mTeam.equals(contact.mTeam)){
smsMessage = String.format(getResources().getString(R.string.mess_sms_message), contact.mVoornaam, mTimeOfArrival);
smsManager.sendTextMessage(contact.mTel, null, smsMessage, pi , null);
}
}
}
Problem: For every textmessage that my code sends, it sort of refreshes the UI. 问题:对于我的代码发送的每个文本消息,它都会刷新UI。 First I tought it would be because the messages where sent from my UI thread, so I've put it into a AsyncTask.
首先,我要强调一下,这是因为消息是从UI线程发送的,所以我将其放入AsyncTask中。 But that didn't solve anything.
但这并没有解决任何问题。 After some testing, I found out that it was because of de SentItent 'pi'.
经过一些测试,我发现这是由于de SentItent'pi'引起的。 If I don't you use one, it gives no problem.
如果我不使用它,那没有问题。
Question: Can anyone explain this? 问题:有人可以解释吗? I would really like to use the feature to see if a text message was actually sent, without that users notice a UI refresh.
我真的很想使用该功能来查看是否确实发送了一条短信,而用户不会注意到UI刷新。
According to Android Developer Site , the sentIntent
which is a PendingIntent
is sent when the message is successfully sent, or failed.
根据Android开发者网站 ,
when the message is successfully sent, or failed.
PendingIntent
的sentIntent
when the message is successfully sent, or failed.
Here you are setting an activity in the PendingIntent
, so whenever your message is sent
or failed
to be sent, your PendinfIntent
is activated, and that refreshes your activity. 在这里,您正在
PendingIntent
中设置一个活动,因此,无论何时sent
或sent
消息failed
, PendinfIntent
激活您的PendinfIntent
,并刷新您的活动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.