Android - switch to activity without restarting it(Android - 切换到活动而不重新启动它)
问题描述
我正在为 android 编写一个聊天程序.
I am programming a chat program for android.
我将联系人列表作为一项活动,将聊天窗口作为第二项活动.我使用 startActivity 切换到聊天活动,但聊天活动每次都会重新加载.因此屏幕被清除.
I have the contact list as one activity and the chat windows as a second activity. I use startActivity to switch to the chat activity, but the chat activity gets reloaded every time. Therefore the screen gets cleared.
有没有办法切换到正在运行的活动而无需重新启动它?
Is there a way to switch to a running activity without having to restart it?
private Intent myIntent = null;
…
if (myIntent == null)
myIntent = new Intent(HanasuAndroidActivity.activity, ChatWindow.class);
this.startActivity(myIntent);
推荐答案
将 FLAG_ACTIVITY_REORDER_TO_FRONT
添加到您的 Intent
.这会将现有的活动实例(如果存在)带到前台,如果不存在则创建一个新实例.
Add FLAG_ACTIVITY_REORDER_TO_FRONT
to your Intent
. That will bring the existing activity instance to the foreground if it exists or create a new one if it does not exist.
这篇关于Android - 切换到活动而不重新启动它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android - 切换到活动而不重新启动它


基础教程推荐
- 如何使用 YouTube API V3? 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- LocationClient 与 LocationManager 2022-01-01