kotlin

How to use Android AlarmManager in Fragment in Kotlin?

六月ゝ 毕业季﹏ 提交于 2021-01-12 06:30:21
问题 I can't seem to get the AlarmManager to work inside a Fragment. My receiver's onReceive() method never gets executed. I assume that I might use context in a wrong way but then again I also couldn't get it to work inside an Activity. I've also registered the receiver in my manifest. MyFragment.kt class MyFragment : Fragment() { ... override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) var alarmMgr: AlarmManager? = null lateinit var

How to use Android AlarmManager in Fragment in Kotlin?

非 Y 不嫁゛ 提交于 2021-01-12 06:29:15
问题 I can't seem to get the AlarmManager to work inside a Fragment. My receiver's onReceive() method never gets executed. I assume that I might use context in a wrong way but then again I also couldn't get it to work inside an Activity. I've also registered the receiver in my manifest. MyFragment.kt class MyFragment : Fragment() { ... override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) var alarmMgr: AlarmManager? = null lateinit var

How to use Android AlarmManager in Fragment in Kotlin?

时光毁灭记忆、已成空白 提交于 2021-01-12 06:27:08
问题 I can't seem to get the AlarmManager to work inside a Fragment. My receiver's onReceive() method never gets executed. I assume that I might use context in a wrong way but then again I also couldn't get it to work inside an Activity. I've also registered the receiver in my manifest. MyFragment.kt class MyFragment : Fragment() { ... override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) var alarmMgr: AlarmManager? = null lateinit var

Springboot+Kotlin+mybatis 构建RESTFUL

 ̄綄美尐妖づ 提交于 2021-01-10 16:49:52
java 大多数代码写了很多沉长的getter 以及setter,似乎kotlin改造了这些东西,简化了实体类的写法。其语法类似于scala ,其实两者写起来感觉没多大区别。遵循大佬就是牛逼的原则,我更偏向于kotlin,毕竟人家手里有android,而且其语法最初也是支持android。 对于代码的编写其实并无多大区别,说下主要注意的地方;代码会在文章末尾奉上,文章在于辅助代码理解,如果你不想看这些可以直接跳到末尾查看源码。 实体类: 实体类的写法更加简单,但是有利必定有弊。其中遇到的坑Integer ,和时间date的转化。Integer 的区别在于int 还是Integer, Date 不管你使用 java.utils 还是 java.sql 都会报错,其中报错语句大致如下: matching [java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang. 所以现在的解决办法就是 所有时间戳类的都转化为timeStamp,至于Int 型 那么就是int? 这样就是一个简单的实体类就出来了,少了getter 少了setter。 剩下的就是老规矩,Controller,Services,Mapper,Xml

android kotlin java.io.FileNotFoundException: /storage/emulated/0/number.txt: open failed: EACCES (Permission denied)

孤人 提交于 2021-01-10 01:38:33
问题 I'm writing an app for Android 10 using kotlin. The app has to read file named number.txt from internal storage. But it always fails to do so: java.io.FileNotFoundException: /storage/emulated/0/number.txt: open failed: EACCES (Permission denied) Here what I have in my manifest: ... <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> ... I have to only read the file, so there is no write permission in manifest. Here is my code, as you can see I use runtime permissions:

push notification enable and disable by using switch

ぃ、小莉子 提交于 2021-01-09 12:57:04
问题 im using firebase push notification(FCM)..and i want to enable and disable notifications by switch button for that i have shared preferences to enable and disable notifications but it seems my logic is not at all working if turn on and off switch still it is receiving notifications need help thanks activity:-- val sharedPreferences = getSharedPreferences("myname", MODE_PRIVATE) simpleSwitch.setChecked(sharedPreferences.getBoolean("SWITCH_PARTIDOS_STATE", false)) simpleSwitch

push notification enable and disable by using switch

拈花ヽ惹草 提交于 2021-01-09 12:55:27
问题 im using firebase push notification(FCM)..and i want to enable and disable notifications by switch button for that i have shared preferences to enable and disable notifications but it seems my logic is not at all working if turn on and off switch still it is receiving notifications need help thanks activity:-- val sharedPreferences = getSharedPreferences("myname", MODE_PRIVATE) simpleSwitch.setChecked(sharedPreferences.getBoolean("SWITCH_PARTIDOS_STATE", false)) simpleSwitch

push notification enable and disable by using switch

穿精又带淫゛_ 提交于 2021-01-09 12:46:56
问题 im using firebase push notification(FCM)..and i want to enable and disable notifications by switch button for that i have shared preferences to enable and disable notifications but it seems my logic is not at all working if turn on and off switch still it is receiving notifications need help thanks activity:-- val sharedPreferences = getSharedPreferences("myname", MODE_PRIVATE) simpleSwitch.setChecked(sharedPreferences.getBoolean("SWITCH_PARTIDOS_STATE", false)) simpleSwitch

push notification enable and disable by using switch

ε祈祈猫儿з 提交于 2021-01-09 12:45:58
问题 im using firebase push notification(FCM)..and i want to enable and disable notifications by switch button for that i have shared preferences to enable and disable notifications but it seems my logic is not at all working if turn on and off switch still it is receiving notifications need help thanks activity:-- val sharedPreferences = getSharedPreferences("myname", MODE_PRIVATE) simpleSwitch.setChecked(sharedPreferences.getBoolean("SWITCH_PARTIDOS_STATE", false)) simpleSwitch

使用 Jetpack DataStore 进行数据存储

白昼怎懂夜的黑 提交于 2021-01-09 08:55:19
作者 / Android 开发技术推广工程师 Florina Muntenescu 与 Google 软件工程师 Rohit Sathyanarayana 欢迎使用 Jetpack DataStore,这是一个经过改进的全新数据存储解决方案,旨在替代原有的 SharedPreferences。Jetpack DataStore 基于 Kotlin 协程和 Flow 开发,并提供两种不同的实现: Proto DataStore 和 Preferences DataStore 。其中 Proto DataStore ,可以存储带有类型的对象 (使用 protocol buffers 实现); Preferences DataStore ,可以存储 键值对 。在 DataStore 中,数据以异步的、一致的、事务性的方式进行存储,克服了 SharedPreferences 的大部分缺点。 SharedPreferences 和 DataStore 对比 SharedPreferences 有一个看上去可以在 UI 线程安全调用的同步 API,但是该 API 实际上执行了磁盘 I/O 操作。此外,apply() 方法会在 fsync() 阻塞 UI 线程。在您应用的任何地方,每当 Service 或 Activity 启动或停止时,就会触发等待 fsync() 的调用。由 apply()