意外的行为展开对话式的活动时, [英] Unexpected behavior when launching a dialog-style activity

查看:103
本文介绍了意外的行为展开对话式的活动时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从WhatsApp的这种行为观察:当有新邮件到达,WhatsApp的将启动一个对话式的活动,这样的活动可能被取消或确认用户

I observed from WhatsApp such behaviors: when a new message arrives, WhatsApp will launch a dialog-style activity and such a activity could be cancelled or confirmed by the user.

所以,我添加了一个类似的对话式的活动,我的应用程序。出于测试目的,我还添加了一个报警管理器和报警接收机,使得本次活动将通过报警接收器每隔10秒发射。

Therefore, I added a similar dialog-style activity to my app. For test purposes, I also added an alarm manager and an alarm receiver so that this activity will be launched every 10 seconds by the alarm receiver.

在code口用于启动对话式的活动是:

The code I used to launch the dialog-style activity is:

   Intent dialogIntent = new Intent(MyApplication.sharedApplication, MyDialogStyleActivity.class);
   dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   MyApplication.sharedApplication.startActivity(dialogIntent);

一切似乎都很正常,如果我的申请没有被启动。对话活动将表明,它的后面是主屏幕,就像WhatsApp的行为。

Everything looked fine if my application had not been launched. The dialog activity would show , behind which was the home screen, just like WhatsApp's behavior.

但是有一个问题,如果我的应用程序已经启动,并把在后台,然后报警触发启动对话框活动,此次推出的对话活动之前,我的应用程序的主要活动会回来到前台,并显示为好。

But there was a problem, if my application had been launched and put in the background, and then the alarm triggered the launch of the dialog activity, before the launch of the dialog activity, the main activity of my app would come back to foreground and show as well.

我很困惑,我所想的是,现在,即使我的应用程序已经启动,当事情触发对话式的活动,仅此对话式的活动将显示,没有任何主要活动或其他任何非相关的活动。

I'm confused, all I want for now is that, even if my application had been launched, when something triggers the dialog-style activity, only this dialog-style activity would show, no main activity or any other un-related activity.

任何人都可以帮忙吗?

推荐答案

您的应用程序维护活动栈。所以,你的主要活动A和您的对话活动B是psented为A-重新$ P $>乙在你的应用程序的活动堆栈。

Your application maintains an activity stack. So your main activity A and your dialog activity B is represented as A->B in your app's activity stack.

当你的应用程序启动并投入背景。当你的对话活动被调用,并带到前台,您的主要活动A仍然活着,因此将显示为好。也许你可以称之为一个完成()startActivity(dialogActivity)之后,以确保一个完成了又走了。

When your app is launched and put to background. When your dialog activity is invoked and brought to the foreground, your main activity A is still live and thus will be shown as well. Maybe you can call "finish()" in A after startActivity(dialogActivity) to make sure A is finished and goes away.

这篇关于意外的行为展开对话式的活动时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆