Skip to content

Commit b8685c1

Browse files
author
longtv6
committed
fix show survey when app is not resumed
1 parent e8fba6f commit b8685c1

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

android/src/main/java/com/formbricks/android/model/error/SDKError.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ object SDKError {
1919
val surveyNotDisplayedError = RuntimeException("Survey was not displayed due to display percentage restrictions.")
2020
val unableToRefreshEnvironment = RuntimeException("Unable to refresh environment state.")
2121
val missingSurveyId = RuntimeException("Survey id is mandatory to set.")
22+
val surveyIsStateSaved = RuntimeException("app is not resumed")
2223
val invalidDisplayOption = RuntimeException("Invalid Display Option.")
2324
val unableToPostResponse = RuntimeException("Unable to post survey response.")
2425
val surveyNotFoundError = RuntimeException("No survey found matching the action class.")

android/src/main/java/com/formbricks/android/webview/FormbricksFragment.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import android.widget.FrameLayout
2727
import androidx.activity.result.contract.ActivityResultContracts
2828
import androidx.fragment.app.FragmentManager
2929
import androidx.fragment.app.viewModels
30+
import androidx.lifecycle.Lifecycle
3031
import com.formbricks.android.Formbricks
3132
import com.formbricks.android.R
3233
import com.formbricks.android.databinding.FragmentFormbricksBinding
@@ -325,12 +326,16 @@ class FormbricksFragment(val hiddenFields: Map<String, Any>? = null) : BottomShe
325326
surveyId: String,
326327
hiddenFields: Map<String, Any>? = null
327328
) {
328-
val fragment = FormbricksFragment(hiddenFields).apply {
329-
arguments = Bundle().apply {
330-
putString(ARG_SURVEY_ID, surveyId)
329+
if (childFragmentManager.isStateSaved) {
330+
Formbricks.callback?.onError(SDKError.surveyIsStateSaved)
331+
} else {
332+
val fragment = FormbricksFragment(hiddenFields).apply {
333+
arguments = Bundle().apply {
334+
putString(ARG_SURVEY_ID, surveyId)
335+
}
331336
}
337+
fragment.show(childFragmentManager, TAG)
332338
}
333-
fragment.show(childFragmentManager, TAG)
334339
}
335340
}
336341
}

0 commit comments

Comments
 (0)