Comments (6)
- 本地手动保存
allGranted
return
传递一个包含allGranted
的model
from android-startup.
你进入了一个误区,onDispatch()
方法并不是用来控制onDependenciesCompleted()
,它是用来控制依赖它的组件的onCreate()
方法的调用时机。每个组件真正的执行逻辑都应该放到onCreate()
方法中。
至于SampleAsyncSevenStartup
的onDependenciesCompleted()
为什么会提前回调,你可以仔细看下SampleManualDispatchStartup
的onCreate()
方法。
override fun create(context: Context): String? {
Thread {
Thread.sleep(2000)
// manual dispatch
onDispatch()
}.start()
return "manual dispatch"
}
from android-startup.
那大佬,我的需求有什么实现方式吗?
from android-startup.
我看了其他类似的issue,但是我这个result是异步的就很尴尬
from android-startup.
/**
* 重要的权限
*/
class ImportantPermissionStartup : AndroidStartup<Boolean>() {
private var allGranted = false
override fun callCreateOnMainThread() = true
override fun waitOnMainThread() = true
override fun create(context: Context): Boolean {
XXPermissions.with(context)
//读写文件权限
.permission(Permission.Group.STORAGE)
.request(object : OnPermissionCallback {
override fun onGranted(permissions: MutableList<String>?, all: Boolean) {
"onGranted:${all}\n${permissions.toString()}".logD()
allGranted = all
doManualDispatch()
}
override fun onDenied(permissions: MutableList<String>?, never: Boolean) {
"onDenied:${never}\n${permissions.toString()}".logD()
allGranted = false
doManualDispatch()
}
})
return allGranted
}
private fun doManualDispatch() {
Thread {
//要加个小延迟,不然会无法触发StartupListener.onCompleted回调
Thread.sleep(30)
onDispatch()
}.start()
}
override fun manualDispatch() = true
}
/**
* 统计库
*/
class AnalyticsStartup : AndroidStartup<Boolean>() {
//重要权限是否全部获取到
private var importantPermissionAllGranted: Boolean? = null
override fun callCreateOnMainThread() = false
override fun waitOnMainThread() = false
override fun dependencies(): List<Class<out Startup<*>>> =
listOf(ImportantPermissionStartup::class.java)
override fun onDependenciesCompleted(startup: Startup<*>, result: Any?) {
importantPermissionAllGranted = result as? Boolean
}
override fun create(context: Context): Boolean {
if (importantPermissionAllGranted != true) {
"重要权限没有全部获取到".logE(javaClass.simpleName)
}
//做一些操作
return true
}
}
这是我的代码
from android-startup.
from android-startup.
Related Issues (20)
- gradle依赖问题 HOT 1
- 一点建议,希望能结合provider初始化的优点 HOT 1
- LeakCanary报的内存泄露 HOT 3
- 在AndroidManifest中配置的StartupProviderConfig一定会被打进主dex包吗? HOT 3
- 初始化失败问题 HOT 2
- 小建议,dependencies能否不使用class HOT 3
- 延迟初始化的小疑问 HOT 2
- Remove Logging from library HOT 2
- 在Activity 中不能重复执行么? HOT 1
- 想问下大家这个库有用在大日活的生产环境吗? HOT 2
- 如果只想在主进程初始化,其他进程不初始化,该怎么配置呢 HOT 2
- initializeComponent 延迟接口是否有提供 HOT 1
- 能设置单个任务超时吗 HOT 1
- 两种注册方式的context有区别 HOT 1
- 是否支持分组启动任务 HOT 1
- manualDispatch的使用问题 HOT 5
- 如何实现初始化的暂停与恢复? HOT 2
- 关于主线程上有相互依赖的任务的执行问题 HOT 2
- CountDownLatch.await 报错 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-startup.