小编Moc*_*cas的帖子

当应用程序不在后台时,没有得到大图标

我通过使用以下代码为推送通知设置大图标。

 new NotificationCompat.Builder(this, channelId)
                    .setSmallIcon(R.drawable.logo)
                    .setContentTitle(notification.getTitle())
                    .setContentText(notification.getBody())
                    .setAutoCancel(true)
                    .setColor(getResources().getColor(R.color.green))
                    .setSound(defaultSoundUri)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logo))
                    .setPriority(Notification.PRIORITY_MAX)
                    .setContentIntent(pendingIntent);
Run Code Online (Sandbox Code Playgroud)

这可以正常工作,并largeIcon在应用程序位于前景中时显示,但在应用程序不在前景中时,它不会显示大图标。

我正在测试应用程序 samsung s7(oreo)

android push-notification android-intent

5
推荐指数
2
解决办法
432
查看次数

为什么仍然可以将 null 分配给不可为 null 的引用类型?

我很迷惑。我认为启用 c# 8 和可为空的引用类型将阻止将 null 分配给不可为空的引用类型,但显然这只是编译时的警告,我知道您可以将其强制为错误并停止构建,但我认为这不仅仅是编译器检查。

看这个例子 https://dotnetfiddle.net/4eCs5L

如果运行,仍然可以将 null 分配给不可为 null 的引用类型,为什么在运行时不会抛出错误?

c#-8.0 nullable-reference-types

5
推荐指数
2
解决办法
1458
查看次数

感到困惑的是C#lambda表达式

我一直在学习lambda表达式,当我终于可以阅读/理解=>运算符时,我很高兴,这对我来说意味着"在哪里"

List<int> a = new List<int>(){0,1,2,1,3,4,5,6,7,8,9};
IEnumerable<int> b = a.FindAll(x => x>=5);
foreach (int x in b)
Console.WriteLine(x);
Run Code Online (Sandbox Code Playgroud)

阅读上面这一行,个人有意义地把它读作"从这个列表中查找所有x的WHERE x大于或等于5",非常好.但后来我遇到了使用Select方法对lambda表达式的不同用法.

List<int> a = new List<int>(){0,1,2,1,3,4,5,6,7,8,9};
IEnumerable<int> b1 = a.Select(x => x*2);
foreach (int x in b)
Console.WriteLine(x);
Run Code Online (Sandbox Code Playgroud)

有了这个,之前读取这个操作符的方法没有意义,因为对我来说这个代码做了"For each x return x*2",这与前一个案例中的同一个操作符的功能非常不同. .我知道.FindAll和.Select之间的区别在于处理输入和输出参数的不同方式,但我在谈论在lambda表达式中使用operator =>.

c# lambda

-3
推荐指数
1
解决办法
1002
查看次数