Android - 切换到 Activity 而不重新启动它
我正在为android 编写一个聊天程序。
我将联系人列表作为一项活动,将聊天窗口作为第二项活动。 我使用 startActivity 切换到聊天活动,但聊天活动每次都会重新加载。因此屏幕被清除。
有没有办法切换到正在运行的活动而无需重新启动它?
private Intent myIntent = null;
……
if (myIntent == null)
myIntent = new Intent(HanasuAndroidActivity.activity, ChatWindow.class);
this.startActivity(myIntent);
I am programming a chat program for android.
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
FLAG_ACTIVITY_REORDER_TO_FRONT
添加到您的Intent
中。这会将现有的活动实例带到前台(如果存在),或者创建一个新的活动实例(如果不存在)。Add
FLAG_ACTIVITY_REORDER_TO_FRONT
to yourIntent
. That will bring the existing activity instance to the foreground if it exists or create a new one if it does not exist.