我们在Android 6和7上有很多特定于小米手机的崩溃:
Fatal Exception: android.app.RemoteServiceException: Bad notification posted from package x.y.z: Couldn't create icon: StatusBarIcon(icon=Icon(typ=RESOURCE pkg=x.y.z id=0x7f0200ad) visible user=0 )
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1715)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6358)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
Run Code Online (Sandbox Code Playgroud)
我在网上发现了很多类似的崩溃报告和文章.这里有几个:
如何解决:android.app.RemoteServiceException:不良通知从包贴*:无法创建图标:StatusBarIcon
https://medium.com/@Miqubel/the-story-of-a-hard-to-fix-bug-ac6ed819cb49
但区别在于我们仅在小米手机(Android 6和7)上存在这些问题,并且可能在更新期间没有,因为相同的用户在同一版本中多次发生崩溃.
有趣的是,在这个特定情况下,我在网上找不到任何东西,我们周围没有任何小米手机.
我将通知设置如下:
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, importance);
notificationChannel.enableLights(true);
notificationManager.createNotificationChannel(notificationChannel);
}
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setContentText(body == null ? "" …Run Code Online (Sandbox Code Playgroud) 我尝试将其转换为 Kotlin:
applicationVariants.all { variant ->
def flavor = variant.productFlavors[0]
def mergedFlavor = variant.getMergedFlavor()
mergedFlavor.manifestPlaceholders = [applicationLabel: "${variant.buildType.appName[flavor.name]}"]
}
Run Code Online (Sandbox Code Playgroud)
但是 manifestPlaceholder 是一个 val 并且不能重新分配,所以这会导致错误:
applicationVariants.forEach {variant->
val flavor = variant.productFlavors[0]
val mergedFlavor = variant.mergedFlavor
variant.mergedFlavor.manifestPlaceholders = mapOf("applicationLabel" to "${variant.buildType.appName[flavor.name]}")
}
Run Code Online (Sandbox Code Playgroud)
通常我可以在 buildTypes 闭包中设置它,但我不能在这里设置,因为 appName 是 buildTypes 中的映射,其中键是风味名称,因此 applicationLabel 取决于构建类型和风味。而且我认为您无法访问 buildTypes 中的风格,这就是您需要 applicationVariants 的原因。
我在库中有一个带注释的Activity,它是来自同一个库的EventBus事件的订阅者.它看起来像这样,大大简化了:
@EActivity(resName = "activity_foo")
public class Foo extends Activity {
public void onEvent(BarEvent event){
doSomething();
}
}
Run Code Online (Sandbox Code Playgroud)
它应该按照这个工作:
http://timnew.me/blog/2014/09/14/otto-and-android-annotations-compatibility-issue-analysis/
但实际上它会返回此错误:
无法启动活动... de.greenrobot.event.EventBusException:订阅者类com.foo.bar.activities.Foo_没有名为onEvent的公共方法
似乎EventBus没有查看父类.我想每个人都在谈论的@Subscribe注释仅在Guava和Otto中,而不是在EventBus中.没有人在谈论网络上的AA和Eventbus之间的兼容性问题,所以我必须遗漏一些东西.
我怎样才能做到这一点?
EventBus:2.4
AA:3.2
编辑:
在WonderCsabo的回答之后,我将EventBus更新到3.0 beta(包括订阅注释)和AA到3.3.1并且问题消失了,但还有另外一个:
java.lang.NoSuchFieldError
at libcore.reflect.AnnotationAccess.decodeValue(AnnotationAccess.java:688)
at libcore.reflect.AnnotationAccess.getDefaultValue(AnnotationAccess.java:361)
at java.lang.reflect.Method.getDefaultValue(Method.java:327)
at libcore.reflect.AnnotationFactory.getElementsDescription(AnnotationFactory.java:75)
at libcore.reflect.AnnotationFactory.<init>(AnnotationFactory.java:112)
at libcore.reflect.AnnotationFactory.createAnnotation(AnnotationFactory.java:94)
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:666)
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:641)
at libcore.reflect.AnnotationAccess.getDeclaredAnnotation(AnnotationAccess.java:170)
at java.lang.reflect.Method.getAnnotation(Method.java:301)
at de.greenrobot.event.n.b(SourceFile:133)
at de.greenrobot.event.n.a(SourceFile:79)
at de.greenrobot.event.c.a(SourceFile:135)
at com.babestudios.lib.lq.activities.f.onStart(SourceFile:515)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236)
at android.app.Activity.performStart(Activity.java:6006)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method) …Run Code Online (Sandbox Code Playgroud) 我知道如何在RxJava 2 中做到这一点。
而且我知道RxKotlin如何帮助解决类似问题。
但似乎 RxKotlin.Observables 没有列表重载的这个辅助函数,我无法弄清楚。你会怎么做?
我可以通过扩展ViewPager来禁用ViewPager以使用setPagingEnabled方法,但现在我只是想暂时禁用一个子节点.
我怀疑我必须通过访问ViewPager的setScrollState方法来覆盖OnPageScrolled并取消滚动,但我无法弄清楚如何.
我的 MVP Presenter 与 onResume 中的视图绑定,这样可以保证解除绑定。这意味着有时,例如当数据来自 onActivityResult() 时,视图未绑定,但我们仍然希望触摸视图,以显示进度等。到目前为止,我为此使用了一个标志并在bindView() 或 updateView() 中,当视图绑定时调用。
现在我正在使用 Kotlin,所以我想如果我在 BasePresenter 中使用 lambda 列表会怎样?这是我到目前为止所拥有的:
typealias AnyLambda = () -> Unit
private val deferredActions = mutableListOf<AnyLambda>()
private val funShowProgress : () -> Unit = {
view()?.showProgress() }
override fun updateView() {
deferredActions.forEach { anyLambda ->
anyLambda()
deferredActions.remove(anyLambda)
}
}
fun onSomethingFromActivity(x: List<Y>) {
...
deferredActions.add { funShowProgress }
}
Run Code Online (Sandbox Code Playgroud)
问题是 lambda 没有在 forEach 中调用。如果我在 lambda 中添加 funShowProgress() ,它就会起作用。另外,lambda 也在那里,因为它在 forEach 中只运行一次,但不会调用 view.showProgress() 。我对 lambda 做错了什么?
请注意,虽然我可以直接从视图调用 showProgress(),但我想避免这种情况。
我在 ViewPager 中有一个片段,其创建如下:
companion object {
fun newInstance(someData: SomeData): ViewPagerFragment {
val f = ViewPagerFragment()
val args = Bundle()
args.putParcelable("someData", someData)
f.arguments = args
return f
}
}
Run Code Online (Sandbox Code Playgroud)
它也是一个 Hilt 入口点,它创建自己的 ViewModel,但也需要父 Fragments ViewModel,因此该类的顶部如下所示:
@AndroidEntryPoint
class ViewPagerFragment : Fragment() {
private val parentViewModel: ParentViewModel by viewModels(
ownerProducer = { requireParentFragment() }
)
private val viewPagerViewModel: ViewPagerViewModel by viewModels()
Run Code Online (Sandbox Code Playgroud)
但是,找不到父 Fragment:
java.lang.IllegalStateException: Fragment ViewPagerFragment{b6d6157}
(e5f3fc7d-2ae4-4275-9763-22826a9be939) id=0x7f09017e} is not a child Fragment, it is
directly attached to
dagger.hilt.android.internal.managers.ViewComponentManager$FragmentContextWrapper@1852444
Run Code Online (Sandbox Code Playgroud)
我认为发生这种情况是因为添加 viewPagerViewModel 后生成的 ViewPagerFragment …
android android-fragments android-viewpager android-viewmodel dagger-hilt