Skip to content

Commit

Permalink
Fix #2030 (or try to). Crash - BadTokenException unable to add window
Browse files Browse the repository at this point in the history
  • Loading branch information
tuomas2 committed Jan 18, 2024
1 parent 0b58668 commit d1be25f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/src/main/java/net/bible/android/BibleApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package net.bible.android

import android.annotation.SuppressLint
import android.app.Activity
import android.app.Application
import android.app.Notification
import android.app.NotificationChannel
Expand All @@ -41,7 +42,9 @@ import net.bible.android.control.backup.BackupControl
import net.bible.android.control.event.ABEventBus
import net.bible.android.control.event.ToastEvent
import net.bible.android.control.report.BugReport
import net.bible.android.view.activity.base.CurrentActivityHolder
import net.bible.android.view.activity.base.ErrorActivity
import net.bible.android.view.activity.page.currentActivity
import net.bible.android.view.util.locale.LocaleHelper
import net.bible.service.cloudsync.SYNC_NOTIFICATION_CHANNEL
import net.bible.service.common.BuildVariant
Expand Down Expand Up @@ -267,8 +270,10 @@ open class BibleApplication : Application() {
fun onEventMainThread(ev: ToastEvent) {
val duration = ev.duration ?: Toast.LENGTH_SHORT
val message = if (ev.messageId != null) getString(ev.messageId) else ev.message
val context = ev.context ?: CurrentActivityHolder.currentActivity?: return
if ((context as? Activity)?.isFinishing == true) return
try {
Toast.makeText(this, message, duration).show()
Toast.makeText(context, message, duration).show()
} catch (e: Exception) {
Log.e(TAG, "Error in showing toast $message", e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package net.bible.android.control.event

class ToastEvent(val message: String = "", val duration: Int? = null, val messageId: Int? = null) {
import android.content.Context

class ToastEvent(val message: String = "", val duration: Int? = null, val messageId: Int? = null, val context: Context? = null) {
constructor(message: String) : this(message, null)
constructor(messageId: Int) : this("", null, messageId)
}

0 comments on commit d1be25f

Please sign in to comment.