我在发送带有待处理意图的附加内容时遇到问题。我在我的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);
}
// ...
}