【问题标题】:send SMS- pending intent/put extras?发送短信 - 未决意图/放置额外内容?
【发布时间】:2011-10-01 04:54:49
【问题描述】:

我正在使用代码

private void sendSms(String phoneNo, String message){
    PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MainScreen.class), 0);
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNo, null, message, pi, null);
}

我已经使用 onSaveInstanceState 来保存诸如文本和微调器位置之类的值,这将在接收意图、导航离开活动等时保持保存并保持一致

不确定我是否可以在未决意图中添加额外内容,以便当它开始我的主要活动时,我可以使用这些额外内容。因为不知何故,当挂起的意图通过时,我需要它恢复到调用意图之前的状态

【问题讨论】:

    标签: android lifecycle android-pendingintent


    【解决方案1】:

    你可以..但是你必须清除之前的待处理意图或在构建待处理意图时使用一次性标志..像这样

    Intent sentIntent = new Intent(SENT_SMS_ACTION);
    sentIntent.putExtra(MESSAGE_ID_TAG, messageId);
    PendingIntent sentPendingIntent = PendingIntent.getBroadcast(this, 0, sentIntent, PendingIntent.FLAG_ONE_SHOT);
    

    【讨论】:

    • 我差点 PM'd 你 b'c 它不起作用,但在运行代码一段时间后,我意识到我在声明之前尝试 spinner.setSelection(int position)数组和数组适配器... doh。谢谢 Rejinderi!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-05
    • 1970-01-01
    • 2016-11-22
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    相关资源
    最近更新 更多