How to do bulk (multi row) inserts with JpaRepository?

To get a bulk insert with Spring Boot and Spring Data JPA you need only two things: set the option spring.jpa.properties.hibernate.jdbc.batch_size to appropriate value you need (for example: 20). use saveAll() method of your repo with the list of entities prepared for inserting. Working example is here. Regarding the transformation of the insert statement into … Read more

Singleton object becomes null after app is resumed

You’re getting crashes because you initialize those variables in one Activity, and expect it to be set always, in the other Activity. But Android doesn’t work like that, you can easily end up crashing because after low memory condition happens, only the current Activity gets recreated at first, previous Activity is recreated on back navigation, … Read more

How to parse JSON in Kotlin?

There is no question that the future of parsing in Kotlin will be with kotlinx.serialization. It is part of Kotlin libraries. Version kotlinx.serialization 1.0 is finally released https://github.com/Kotlin/kotlinx.serialization import kotlinx.serialization.* import kotlinx.serialization.json.JSON @Serializable data class MyModel(val a: Int, @Optional val b: String = “42”) fun main(args: Array<String>) { // serializing objects val jsonData = JSON.stringify(MyModel.serializer(), … Read more

Android: How to Enable/Disable Wifi or Internet Connection Programmatically

I know of enabling or disabling wifi: WifiManager wifiManager = (WifiManager)this.context.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(status); where status may be true or false as per requirement. Edit: You also need the following permissions in your manifest file: <uses-permission android:name=”android.permission.ACCESS_WIFI_STATE”/> <uses-permission android:name=”android.permission.CHANGE_WIFI_STATE”/>

How to make an Android device vibrate? with different frequency?

Try: import android.os.Vibrator; … Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 500 milliseconds if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE)); } else { //deprecated in API 26 v.vibrate(500); } Note: Don’t forget to include permission in AndroidManifest.xml file: <uses-permission android:name=”android.permission.VIBRATE”/>