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 - 切换到活动而不重新启动它


- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- URL编码Swift iOS 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- UITextView 内容插图 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01