Skip to content

Commit

Permalink
Fix issue 2864 (Ivy-Apps#2867)
Browse files Browse the repository at this point in the history
* Replace startActivityAndCollapse(Intent) with startActivityAndCollapse(PendingIntent) to launch RootActivity

* refactor code
  • Loading branch information
mahdi-hosseinnion authored Jan 8, 2024
1 parent 938620a commit 7e16445
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions app/src/main/java/com/ivy/wallet/PaymentTileService.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.ivy.wallet

import android.annotation.SuppressLint
import android.app.PendingIntent
import android.content.Intent
import android.os.Build
import android.service.quicksettings.TileService
import timber.log.Timber

class PaymentTileService : TileService() {
// Called when the user adds your tile.
Expand All @@ -24,17 +26,24 @@ class PaymentTileService : TileService() {
override fun onClick() {
super.onClick()

try {
val i = Intent(applicationContext, RootActivity::class.java)
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivityAndCollapse(i)
} catch (e: Exception) {
Timber.tag("debug").d("Exception %s", e.toString())
}
startRootActivity()
}

// Called when the user removes your tile.
override fun onTileRemoved() {
super.onTileRemoved()
}

@SuppressLint("StartActivityAndCollapseDeprecated")
private fun startRootActivity() {
val intent = Intent(applicationContext, RootActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
val pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)
startActivityAndCollapse(pi)
} else {
startActivityAndCollapse(intent)
}
}
}

0 comments on commit 7e16445

Please sign in to comment.