Skip to content

Commit

Permalink
fix: Attempting to launch an unregistered ActivityResultLauncher
Browse files Browse the repository at this point in the history
The ActivityResultLauncher must be initialized in the onCreate method, otherwise the app may crash
  • Loading branch information
g123k committed Mar 14, 2022
1 parent 96d0fe0 commit 51f7767
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.res.ResourcesCompat
import androidx.core.net.toUri
Expand Down Expand Up @@ -140,7 +141,7 @@ class SummaryProductFragment : BaseFragment(), ISummaryProductPresenter.View {
private lateinit var customTabActivityHelper: CustomTabActivityHelper

private lateinit var customTabsIntent: CustomTabsIntent

private lateinit var editProductLauncher: ActivityResultLauncher<Product>

private var hasCategoryInsightQuestion = false

Expand Down Expand Up @@ -189,6 +190,9 @@ class SummaryProductFragment : BaseFragment(), ISummaryProductPresenter.View {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mTagDao = daoSession.tagDao

editProductLauncher = registerForActivityResult(ProductEditActivity.EditProductContract())
{ isOk -> if (isOk) (activity as? ProductViewActivity)?.onRefresh() }
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
Expand Down Expand Up @@ -887,9 +891,6 @@ class SummaryProductFragment : BaseFragment(), ISummaryProductPresenter.View {
}, null))
}

private val editProductLauncher = registerForActivityResult(ProductEditActivity.EditProductContract())
{ isOk -> if (isOk) (activity as? ProductViewActivity)?.onRefresh() }

private fun editProduct() = editProductLauncher.launch(product)

private fun onBookmarkProductButtonClick() {
Expand Down

0 comments on commit 51f7767

Please sign in to comment.