title: Android Kotlin custom BottomSheetDialog automatically open when I insert something to Room Database
body: <p>In my custom <em>BottomSheetDialog</em>, I've made a pop up to register something. But when I insert data from dialog to Room Database, The <em>BottomSheetDialog</em> again appear on the top of screen elements !! But I didn't wrote any code for re-opening the <em>BottomSheetDialog</em>!!</p>
  <p><em><strong>Here is the Entity and Dao class:</strong></em></p>
  <p><strong>Category2Entity</strong></p>
  <pre><code>@Entity(tableName = &quot;categories_2&quot;)
  data class Category2Entity(
  
  @PrimaryKey
  @ColumnInfo(name = &quot;id&quot;)
  val id: Int = 0,
  
  @ColumnInfo(name = &quot;name&quot;)
  val name: String = &quot;&quot;,
  
  @ColumnInfo(name = &quot;image&quot;)
  val image: String = &quot;&quot;
  )
  </code></pre>
  <p><strong>Category2Dao</strong></p>
  <pre><code>@Insert(onConflict = OnConflictStrategy.REPLACE)
  suspend fun insert(category2Entity: Category2Entity)
  </code></pre>
  <p><strong>The insert method</strong></p>
  <pre><code>binding.btnAddInput.setOnClickListener {
      val category2Dao = (activity.application as UserApp).db.category2Dao()
  
      lifecycleScope.launch {
          category2Dao.insert(Category2Entity(id, name, &quot;ic_fish&quot;))
  
          Toast.makeText(context, &quot;Done&quot;, Toast.LENGTH_SHORT).show()
      }
  }
  </code></pre>
  <p><em><strong>This time, after inserting data, the BottomSheetDialog re-open on the top of every dialogs..!!</strong></em></p>
  <hr />
  <p>-&gt; After that, I've inserted my registered data to another Entity and Dao class for solving the problem, and after inserting data, no <em>BottomSheetDialog</em> appear again!!</p>
  <p><em><strong>Here is the Entity and Dao class</strong></em></p>
  <p><strong>CategoryEntity</strong></p>
  <pre><code>@Entity(tableName = &quot;categories&quot;)
  data class CategoryEntity(
  
  @PrimaryKey
  @ColumnInfo(name = &quot;id&quot;)
  val id: Int = 0,
  
  @ColumnInfo(name = &quot;name&quot;)
  val name: String = &quot;&quot;,
  
  @ColumnInfo(name = &quot;image&quot;)
  val image: String = &quot;&quot;
  )
  </code></pre>
  <p><strong>CategoryDao</strong></p>
  <pre><code>@Insert(onConflict = OnConflictStrategy.REPLACE)
  suspend fun insert(categoryEntity: CategoryEntity)
  </code></pre>
  <p><strong>The insert method</strong></p>
  <pre><code>binding.btnAddInput.setOnClickListener {
  val categoryDao = (activity.application as UserApp).db.categoryDao()
  
  lifecycleScope.launch {
      categoryDao.insert(CategoryEntity(id, name, &quot;ic_fish&quot;))
  
      Toast.makeText(context, &quot;Done&quot;, Toast.LENGTH_SHORT).show()
  }
  </code></pre>
  <p>}</p>
  <p><em><strong>This time, after inserting data, no BottomSheetDialog appear on the top..!!</strong></em></p>
  <hr />
  <p><strong>Now my question is, Why The BottomSheetDialog appear on the top when I insert data to Category2Entity?</strong></p>
  <p><em>[Note: I didn't wrote any code to show the BottomSheetDialog again. Also my data inserting works good with both Entities. just Entity2 re-open the BottomSheetDialog]</em></p>
  <hr />
  <p><strong>BottomSheetDialog function :</strong></p>
  <pre><code> private fun sheetDialog() {
       val inputSheet = BottomSheetDialog(context, R.style.Bottom_Sheet)
       val binding = SheetInputBinding.inflate(layoutInflater)
       inputSheet.setContentView(binding.root)
  
       showDialog()
  
       inputSheet.show()
  
  }
  </code></pre>
  <p><strong>Dialog function :</strong></p>
  <pre><code> private fun showDialog() {
       val addDialog = Dialog(context, R.style.Theme_Dialog)
       val binding = DialogAddMoreBinding.inflate(layoutInflater)
       addDialog.setContentView(binding.root)
  
       binding.btnAddInput.setOnClickListener {
       val category2Dao = (activity.application as UserApp).db.category2Dao()
  
       lifecycleScope.launch { category2Dao.insert(Category2Entity(id, name, &quot;ic_fish&quot;))
  
       Toast.makeText(context, &quot;Done&quot;, Toast.LENGTH_SHORT).show()
       }
       
       addDialog.show()
  
  }
  </code></pre>