I'm currently experiencing the following problem:
What happens:
Could you please help?
Launcher Activity code:
if (getIntent().getExtras() != null) {
Bundle extras = getIntent().getExtras();
String title = (String) extras.get(Constants.TOPIC_KEY_TITLE);
String imageUrl = (String) extras.get(Constants.TOPIC_KEY_IMAGE_URL);
String url = (String) extras.get(Constants.TOPIC_KEY_URL);
String description = (String) extras.get(Constants.TOPIC_KEY_DESCRIPTION);
Long sentTime = (Long) extras.get(Constants.TOPIC_KEY_SENT_TIME);
if (Util.isStringsNotNull(description)) {
News news = new News();
news.setTitle(title);
news.setMessage(description);
news.setDescription(description);
news.setImageUrl(imageUrl);
news.setUrl(url);
news.setDate(sentTime);
news.save();
EventBus.getDefault().post(new OnNewsUpdatedEvent(news));
AppPreferences.incrementUnseenNewsCount(this);
}
}
String action = getIntent().getAction();
if (Util.isStringNotNull(action) && action.equals(ACTION_SEARCH)) {
startActivity(MainActivity.getIntentActionSearch(this));
} else {
startActivity(MainActivity.getIntent(this));
}
Custom FirebaseMessagingService code:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
LogUtil.log(BASIC_TAG, "onMessageReceived called!");
String description = null;
String imageUrl = null;
String url = null;
String title = null;
Map<String, String> dataMap = remoteMessage.getData();
if (dataMap != null && !dataMap.isEmpty()) {
description = dataMap.get(Constants.TOPIC_KEY_DESCRIPTION);
imageUrl = dataMap.get(Constants.TOPIC_KEY_IMAGE_URL);
url = dataMap.get(Constants.TOPIC_KEY_URL);
title = dataMap.get(Constants.TOPIC_KEY_TITLE);
}
if (Util.isStringNotNull(description)) {
RemoteMessage.Notification notification = remoteMessage.getNotification();
News news = new News();
news.setDate(remoteMessage.getSentTime());
news.setTitle(Util.isStringNotNull(title) ? title : notification.getTitle());
news.setMessage(notification.getBody());
news.setDescription(description);
news.setImageUrl(imageUrl);
news.setUrl(url);
news.save();
EventBus.getDefault().post(new OnNewsUpdatedEvent(news));
AppPreferences.incrementUnseenNewsCount(this);
}
}
I'm going to assume you have your launcher activity code in the onCreate() method of your activity. Once the activity is created and you click another notification the onCreate() will not be called again.
What you need to do to update the activity that is already visible to the user is override the onNewIntent(Intent intent) method of the activity in which the data is displayed and update your views there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.