ubu
11/21/2019, 4:29 PMCyberpunk Keanu
11/22/2019, 10:58 AMDuchynko
11/22/2019, 1:00 PM@Entity(tableName = "students")
data class Student(
@PrimaryKey(autoGenerate = true)
val id: Int? = null,
var studentName: String,
val studentId: String,
var purchaseDate: String,
val comment: String
)
DAO
@Dao
interface StudentDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun upsert(student: List<Student>)
@Query("select * from students")
fun getStudents(): LiveData<List<Student>>
}
Repository methods for upserting and getting List of Students
private fun persistFetchedStudents(fetchedStudents: StudentsResponse) {
GlobalScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
Log.i("StudentRepositoryImpl", "Called from persistFetchedStudents: fetchedStudents.students.size = " + fetchedStudents.students.size)
studentsDao.upsert(fetchedStudents.students)
}
}
Log -> fetchedStudents.students.size = 140
private fun isFetchStudentNeeded(): Boolean {
Log.i("StudentRepositoryImpl", "Called from isFetchStudentNeeded: studentsDao.getStudents().value = " + studentsDao.getStudents().value)
return studentsDao.getStudents().value.isNullOrEmpty()
}
Log -> studentsDao.getStudents().value = null
Is there anything I'm doing wrong? I can't see any issue myself.
Thanks for any help 🙂Soumik
11/23/2019, 7:13 PMvpriscan
11/24/2019, 12:18 PMdave08
11/24/2019, 5:22 PMlifecycleScope.launch { }
in a LifecycleService
when handling intents, or will it leak?dave08
11/24/2019, 5:23 PMrunBlocking {}
isn't possible anymore, since you can't use the lifecycleScope
with it...Md Razon Hossain
11/25/2019, 1:59 AMKstabks
11/25/2019, 12:07 PMpetermonteer
11/25/2019, 1:19 PMmelatonina
11/26/2019, 12:05 AMAiden
11/26/2019, 10:23 AMimplements
word.
1. Why the ProductDatabase can use abstract
to initialize interface
class? abstract fun productDao(): ProductDao
2. What does the line of code means and trying to do?
@Database(entities = [Product::class], version = 1)
abstract class ProductDatabase : RoomDatabase() {
abstract fun productDao(): ProductDao
}
@Dao
interface ProductDao {
@Insert
fun insert(product: Product)
@Update
fun update(product: Product)
@Delete
fun delete(product: Product)
@Query("SELECT * FROM products")
fun all(): LiveData<Array<Product>>
@Query("SELECT * FROM products WHERE id = :id")
fun get(id: Int): Product
}
Ayden
11/26/2019, 4:36 PMJava::class.java
and Java::class
?
Why sometime I need to passing the first option as a parameter but sometime I need to pass the second option?Arslan Mushtaq
11/26/2019, 8:03 PMrodrigo
11/26/2019, 8:52 PMonActivityCreated
I have a field reference_field.addTextChangedListener()
and then I navigate to a different screen (Fragment), however when I navigate back the listener no longer works and I think it has something to do with how Kotlin Android Extensions use cached views, on the other hand if I replace reference_field.addTextChangedListener()
with view?.findViewById<EditText>(R.id.reference_field)?.addTextChangedListener()
then navigate to a different screen and return to the previous screen the listener does work as intended. Perhaps when the view gets destroyed and recreated Kotlin synthetic is referring to a cached reference which no longer exists 🤔. Has anyone experienced this before?Rafa
11/27/2019, 12:42 AMUnable to load class 'kotlin.coroutines.Continuation'
on the task :app:kaptGenerateStubsDevDebugKotlin
When I revert back to kotlin 1.3.50, it builds fine and everything works. Is there anything about 1.3.60 that might be causing this to happen?gabin
11/27/2019, 10:07 AMGuilherme Krzisch
11/27/2019, 8:32 PMjava.lang.AbstractMethodError: abstract method "void android.os.Parcelable.writeToParcel(android.os.Parcel, int)"
when putting the app in background, after saving a parcelable (using Parcelize
) in onSaveInstanceState
:
override fun onSaveInstanceState(outState: Bundle) {
outState.putParcelable("test", Test())
super.onSaveInstanceState(outState)
}
@Parcelize
data class Test(val test: String = "test"): Parcelable
It does not occur on configuration changes though. I'm using AS 4.0 Canary 4, with kotlin 1.3.60-eap-25
. Any idea of what am I doing wrong here?Ive Vasiljevic
11/28/2019, 3:38 PMvoben
11/28/2019, 5:47 PMDiego Almeida de Oliveira
11/28/2019, 9:02 PMFreedom
11/28/2019, 9:23 PMdarkmoon_uk
11/30/2019, 6:53 AMkotlin.test
classes; Android Studio doesn't provide the same IDE integration as when using JUnit classes.
Specifically: Right-click execution of test classes & individual tests, and capturing the results of the tests in the IDE UI. Is this expected? Seems like a surprising omission.tjohnn
11/30/2019, 7:06 AMKV
12/01/2019, 2:27 PMfileContent = readFileFromRawDirectory(R.raw.demoFile) . ---> This is the file inside the /raw folder
private fun readFileFromRawDirectory(resourceId: Int): String {
val iStream: InputStream = context?.resources.openRawResource(resourceId)
var byteStream: ByteArrayOutputStream? = null
try {
val buffer = ByteArray(iStream.available())
iStream.read(buffer)
byteStream = ByteArrayOutputStream()
byteStream.write(buffer)
byteStream.close()
iStream.close()
} catch (e: IOException) {
e.printStackTrace()
}
return byteStream.toString()
}
Now I want to add the data inside the same demoFile.txt
This below code is for writing the string inside the demoFile.txt
private fun writeDataIntoFile(searchText: String) {
val file = context?.filesDir?.absolutePath + "/demoFile.txt"
try {
val fileout: FileOutputStream? = context?.openFileOutput(file, MODE_PRIVATE)
val outputWriter = OutputStreamWriter(fileout)
outputWriter.write(searchText)
outputWriter.close()
fileout?.close()
} catch (e: Exception) {
e.printStackTrace()
}
}
Arjun Achatz
12/02/2019, 5:19 AMMatej Drobnič
12/02/2019, 6:53 AMMullisgabriele
12/02/2019, 9:35 AMJoey
12/03/2019, 8:35 AMfetchHeartbeat()
in my MapsActivity.kt
Nikola Milovic
12/03/2019, 9:56 AMType inference failed: fun <T : Any!> getSystemService(context: Context, serviceClass: Class<T!>): T?
cannot be applied to
(String)
Type mismatch: inferred type is String but Context was expected
I just used the code provided here https://developer.android.com/guide/topics/text/copy-paste
var clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
var pasteData: String = ""
And i get this errorNikola Milovic
12/03/2019, 9:56 AMType inference failed: fun <T : Any!> getSystemService(context: Context, serviceClass: Class<T!>): T?
cannot be applied to
(String)
Type mismatch: inferred type is String but Context was expected
I just used the code provided here https://developer.android.com/guide/topics/text/copy-paste
var clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
var pasteData: String = ""
And i get this errorwasyl
12/03/2019, 9:59 AMgetSystemService
from core-ktx library and it’s a function with reified generic parameter. So you need to instead wrote getSystemService<ClipboardManager>()
Nikola Milovic
12/03/2019, 10:46 AMwasyl
12/03/2019, 11:11 AMNikola Milovic
12/03/2019, 11:26 AMoverride fun quoteClicked(quote: Quote) {
viewModel.copyText(quote)
}
in my fragment, but now I need a way to copy text in the viewmodel. Any pointers/ help/ article would be appreciated. Not sure what to do
Thanks by the way @wasylMark Murphy
12/03/2019, 12:15 PMClipboardManager
so you can supply a mock version in testing. Otherwise, you could have your viewmodel extend AndroidViewModel
and use the application
to call getSystemService()
.Nikola Milovic
12/03/2019, 12:49 PM