java - Switch Case 语句或其替代 If Condition 在 android 中不起作用
问题描述
我使用 switch case 进行条件检查。它不工作。这里我是如何实施的。
@Override
public void onReceiveNotification(String notificationType, String message, String flag) {
super.onReceiveNotification(notificationType, message, flag);
Log.d("tag", "==onReceive Notivation====1===" + notificationType);
if (notificationType.equalsIgnoreCase("MULTIPART_TYPES"))
{
Log.d("tag", "==onReceive Notivation===2====" + notificationType);
}
switch (notificationType) {
case "MULTIPART_TYPES":
Log.d("tag", "==onReceive Notivation=======" + message);
break;
}
}
这是我的日志输出
==onReceive Notivation====1=== MULTIPART_TYPES
但是,它正在使用受尊重的字符串消息进入该方法。但它不是进入切换或if条件。
解决方案
您的 notificationType 前面有一个空格。删除它或为您的支票添加修剪。像这样的东西。
if (notificationType.trim().equalsIgnoreCase("MULTIPART_TYPES"))
{
Log.d("tag", "==onReceive Notivation===2====" + notificationType);
}
推荐阅读
- python - TemplateDoesNotExist at / index.html Django
- html - Flexbox 重叠高度布局
- javascript - 如何使用 redux 更新状态
- eiffel - 通过线程将创建的 DB_SERVICES 和其他实例重用到 EWF_APP 的策略
- reactjs - React ApolloClient useQuery 两次获取数据
- c# - 标签没有获得价值
- kubernetes - Kubernetes liveness probe重启容器一直无法访问某些资源
- mongodb - 从 Mongo 组聚合返回嵌入字段
- java - 返回 true 时键盘未显示在 EditText 上
- c - Bios/Real 模式下的 C 编译器?