Мне нужно создать новый объект, когда пользователь приходит от push notification
.Как определить, какой вид onResume произошел
Когда пользователь нажимает на уведомление, onResume
запускается (по назначению). В методе onResume
мне нужно сделать вызов на сервер и создать объект на основе ответа. Однако я не могу понять, как определить, был ли вызван onResume
уведомлением или чем-то другим, например, включением экрана.
Я не очень разбираюсь в Intent flags
, но, возможно, решение может лежать там.
Это код, который настраивает и запускает push notification
:
private void sendNotification(String message, String topic) {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("resumeType", "BattleNotification");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
String contentTitle = "Message from Maguss";
switch (topic){
case "battle":
contentTitle = "Your battle was accepted";
break;
}
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setContentTitle(contentTitle)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}