Android - 切换到 Activity 而不重新启动它

发布于 2024-12-23 08:54:13 字数 384 浏览 4 评论 0原文

我正在为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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与酒说心事 2024-12-30 08:54:13

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文