如何在Kotlin中组合意图标志 [英] How to combine Intent flags in Kotlin

查看:97
本文介绍了如何在Kotlin中组合意图标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想像在android系统中那样将两个意图标志组合在一起

I want to combine two intent flags as we do bellow in android

Intent intent = new Intent(this, MapsActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);

我试图做这样的事情,但是对我来说没用

I tried doing something like this but it didn't work for me

val intent = Intent(context, MapActivity::class.java)
intent.flags = (Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)

推荐答案

说明:

应用于标志的操作是按位或.在Java中,您可以使用|运算符.

The operation that is applied to the flags is a bitwise or. In Java you have the | operator for that.

在[按Kotlin]的按位运算中,没有特殊字符 对他们来说,只是命名函数,可以以中缀形式调用.

As of bitwise operations [in Kotlin], there're no special characters for them, but just named functions that can be called in infix form.

来源

以下是IntLong

  • shl(bits) –有符号左移(Java的<<)
  • shr(bits) –带符号的右移键(Java的>>)
  • ushr(bits) –无符号右移(Java的>>>)
  • and(bits) –按位和(Java的&)
  • or(bits) –按位或(Java的|)
  • xor(bits) –按位异或(Java的^)
  • inv() –按位反转(Java的~)
  • shl(bits) – signed shift left (Java's <<)
  • shr(bits) – signed shift right (Java's >>)
  • ushr(bits) – unsigned shift right (Java's >>>)
  • and(bits) – bitwise and (Java's &)
  • or(bits) – bitwise or (Java's |)
  • xor(bits) – bitwise xor (Java's ^)
  • inv() – bitwise inversion (Java's ~)

解决方案:

因此,在您的情况下,您只需要像这样在参数之间调用or.

So, in your case you only need to call or in between your arguments like so.

intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK

这篇关于如何在Kotlin中组合意图标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆