Skip to content

Commit

Permalink
feat : 메인 액티비티 백스택 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
m6z1 committed Mar 28, 2024
1 parent 8338ffa commit 3f06eb4
Showing 1 changed file with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.dongyang.android.youdongknowme.service
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.TaskStackBuilder
import android.content.Context
import android.content.Intent
import android.media.RingtoneManager
Expand Down Expand Up @@ -39,23 +40,33 @@ class FCMService : FirebaseMessagingService() {
notificationManager.createNotificationChannel(channel)
}

// Intent 및 PendingIntent 생성
val intent = if (url.isNullOrEmpty().not()) {
DetailActivity.newIntent(this, url).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
// MainActivity를 시작하는 Intent 생성
val mainIntent = Intent(this, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
}

// DetailActivity를 열기 위한 Intent 생성
val detailIntent = if (!url.isNullOrEmpty()) {
DetailActivity.newIntent(this, url)
} else {
Intent(this, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
}
null // URL이 없는 경우에는 null 할당
}

val pendingIntent = PendingIntent.getActivity(
this,
0,
intent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
// PendingIntent 생성
val pendingIntent = if (detailIntent != null) {
TaskStackBuilder.create(this).run {
addNextIntent(mainIntent)
addNextIntentWithParentStack(detailIntent) // DetailActivity를 부모 스택으로 추가
getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)
}
} else {
PendingIntent.getActivity(
this,
0,
mainIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
}

// 알림 생성
val builder = NotificationCompat.Builder(this, channelId)
Expand Down

0 comments on commit 3f06eb4

Please sign in to comment.