title: Content provider in Android by Kotlin
body: <p>everyone!</p>
  
  <p>I created a side application for practice Kotlin in Android. I create a provider like that:</p>
  
  <pre><code>class TestProvider : ContentProvider() {
      companion object {
          val sUriMatcher = UriMatcher(UriMatcher.NO_MATCH)
          val MATCH_WITH_TEST = 0
  
          init {
              sUriMatcher.addURI("$APPLICATION_ID.provider", TestEntity.TABLE_NAME, MATCH_WITH_TEST)
          }
      }
  
      var mDatabaseHelper: LocalSQLiteHelper? = null
  
      override fun onCreate(): Boolean {
          mDatabaseHelper = LocalSQLiteHelper(context)
          return true
      }
  
      override fun insert(uri: Uri?, values: ContentValues?): Uri? {
          if (mDatabaseHelper != null &amp;&amp; !mDatabaseHelper?.writableDatabase?.isReadOnly) {
  
          }
  
          return uri
      }
  }
  </code></pre>
  
  <p>You see! The content provider has to contain a Database Helper. This Database Helper only created at <code>onCreate()</code> method of the parent class.</p>
  
  <p>So now I want to check the <code>writableDatabase</code> be a read-only database or not. Because the <code>mDatabaseHelper</code> is <code>LocalSQLiteHelper?</code> so <code>!mDatabaseHelper?.writableDatabase?.isReadOnly</code> code return <code>Boolean?</code> which not accepted in Kotlin <code>if</code> control statement.</p>
  
  <p>Have any one got the same problem with me?</p>
  
  <p>Update:</p>
  
  <p>I found a solution by using:</p>
  
  <pre><code>val database: SQLiteDatabase = mDatabaseHelper?.writableDatabase as SQLiteDatabase
  </code></pre>
  
  <p>It work but I dont know why?</p>