1

我在发送带有待处理意图的附加内容时遇到问题。我在我的StateCh服务中添加额外的字符串并发送到我的MainActivity. MainActivity按预期开始,但我放在那里的额外字符串总是丢失。

MainActivity.java:

public class MainActivity extends Activity {

 public void onResume() {
    super.onResume();

 String recMessage = this.getIntent().getStringExtra("message");

 if(recMessage.equals("")) {
    Log.v("recMessage", "none");
  } else {
   Log.v("recMessage", "something");
  }
    // ..
 }
}

StateCh.java:

public class StateCh extends Service {

//...

   private void notificationU(String title, String text)  {

    //The intent to launch when the user clicks the expanded notification
    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra("message", "ssss");
    intent.setAction("actionstring" + System.currentTimeMillis());

    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

     Notification noti2 = new NotificationCompat.Builder(this)
     .setContentTitle(title)
     .setContentText(text)
     .setSmallIcon(R.drawable.warning)
     .setContentIntent(pendIntent)
     .build();

     mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
     mNotificationManager.notify(123456, noti2);
    }

    // ...      

}
4

2 回答 2

1

检查使用TextUtils

if (!TextUtils.isEmpty(recMessage)) {

// here your require condition

}
于 2013-05-14T05:48:13.593 回答
0

我已经找到了我的问题的正确答案,在另一个主题中再问一次,更准确地说:只有在活动暂停时才会收到待处理的意图额外内容。也许它会对某人有所帮助。

于 2013-05-19T16:33:08.237 回答