我的活动启动模式设置为 android:launchMode="singleTask"
当我调用startActivity()从另一个活动启动它时,它会将它从上次状态带到顶部。
设想:
活动 A 启动活动 B
活动 B 启动活动 A
活动 A 带有旧数据
我使用什么标志来强制它开始干净并调用onCreate()?
知道我必须使用android:launchMode="singleTask"来维护常规的应用程序流并且不能切换到android:launchMode="singleTop"
谢谢
编辑(1):
launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Run Code Online (Sandbox Code Playgroud)
随着 android:launchMode="singleTask"
它解决了我要问的问题,但它造成了一个最糟糕的问题
现在,当我完成活动 A(由活动 A 启动的活动 B 启动)时,我发现自己最终到达了我使用的最后一个应用程序,它应该登陆活动 B。
我试图在 Excel 中完成一项相当简单的任务,但没有得到我想要的结果。我有一个简单的时间表,通过填写一个简单的表格,我将一组教练分配给一系列比赛。这是缩小版:
Match | John | Pete | Chris |
-------|------|------|-------|-------
1 | X | | | John
2 | | X | | Pete
3 | A | | X | Chris
4 | X | | A | Chris (!)
5 | | X | A | Pete
Run Code Online (Sandbox Code Playgroud)
图例:X:将担任教练;答:可用。
我使用该表来登记可用性,然后将每行中的一个 A 更改为 X,以选择实际指导比赛的人。
为了进行概述,我决定添加一个列,其中将显示所选教练。我对第 2 行使用了以下公式:=LOOKUP("X"; B2:D2; B$1:D$1)并将其复制到其他行,以便每行的行号与放置公式的行相对应。
令我惊讶的是,第 4 场比赛被分配给了 Chris,而 John 有一个 X,而 Chris 只有一个 A。
当我阅读Microsoft 关于 LOOKUP 的文档时,我注意到了一些事情:
我有日期字符串,例如03/10/1999格式是dd/MM/yyyy(pt-BR格式)。
而且我需要将此日期转换为类似SQL的格式yyyy-MM-dd HH:mm:ss.fff。
我尝试使用Parse和ParseExact函数,但到目前为止没有成功。我将下面的结果...
使用解析
var BrazilianDate = "03/10/1999";
var Parse = DateTime.Parse(BrazilianDate, new CultureInfo("pt-BR"));
Console.WriteLine("Parsed date: " + Parse);
Run Code Online (Sandbox Code Playgroud)
输出: Parsed date: 10/3/1999 12:00:00 AM
没有连字符或毫秒...
使用ParseExact
var BrazilianDate = "03/10/1999";
var ParseExact = DateTime.ParseExact(BrazilianDate, "yyyy-MM-dd HH:mm:ss.fff", new CultureInfo("pt-BR"));
Console.WriteLine(ParseExact);
Run Code Online (Sandbox Code Playgroud)
输出:
运行时异常(第-1行):字符串未被识别为有效的DateTime。
堆栈跟踪:
[System.DateTimeParse.ParseExact(String s,字符串格式,DateTimeFormatInfo dtfi,DateTimeStyles样式),位于System.DateTime.ParseExact(String s,字符串格式,IFormatProvider提供者)处的[System.FormatException:字符串未被识别为有效的DateTime。]在Program.Main()
我正在尝试使用固定在屏幕顶部的“X”按钮来设置布局,然后在视图中居中放置两个元素。一个回收器视图,然后固定在回收器视图下方,一个用于表单提交的按钮。我目前工作的布局,直到回收站视图超出其边界。然后提交按钮被推到视图边界下方,回收器视图不会留在布局内。如果回收器视图变大,如何将两个回收器视图和按钮视图居中,但不让按钮越过视图边界?
View With Small Recycler View 显示为(它应该居中。我的例子有点偏离。)
视图应该如何与更大的回收器视图一起出现(回收器视图的内容太大而无法滚动)
视图实际上如何在更大的回收器视图中出现(回收器视图确实滚动,但现在它将按钮推离视图底部,这显示为按钮被切断)
XML 布局的相关代码块
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.45"
android:orientation="vertical"
android:background="@color/backgroundLightSecondary"
android:padding="20dp" >
<Button
android:id="@+id/bt_close"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="end"
android:background="@drawable/ic_close"
android:textColor="@color/textLightPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center_vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_item_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/bt_order"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_weight="0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:background="@drawable/bt_rounded_corner"
android:fontFamily="@font/microbrew_two"
android:padding="3dp"
android:text="@string/btn_add_to_order"
android:textColor="@color/backgroundLightSecondary"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我用来Coroutines处理异步作业:
viewModelScope.launch {
val userResponse = getUsers() //suspendable function
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是停止所有现有/正在进行的协程作业。想法是我单击不同的选项卡。如果getUsers()需要长达 5 秒的时间并且用户从“用户”选项卡单击到“作业”选项卡,我希望停止现有的 API 调用并且不会观察到响应。
我尝试做viewModelScope.cancel(),但这似乎不起作用。
问题是 - 如何在单击按钮时取消现有作业?
我在布局中添加了一个 FloatingActionButton,其唯一的父级是 CoordinatorLayout,所以我不明白 backgroundTint 颜色来自哪里。
我尝试更改颜色以匹配内圆,但它将整个按钮更改为纯色。
我还应用了不同的样式,但它根本没有改变按钮。我过去解决过这个问题,但我不记得我是怎么做到的。
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="@drawable/ic_action_add"
app:layout_anchor="@+id/edit_layout"
app:layout_anchorGravity="bottom|right|end" />
Run Code Online (Sandbox Code Playgroud)