隐藏在机器人活动 [英] hide activity in android

查看:124
本文介绍了隐藏在机器人活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个Android应用程序两项活动,每个人都有一个按钮,转到其他活动(由 startActivity()法)。在第二个活动,我有一个编辑的文本(URL地址栏)和Web视图。

I have two activities in an android application, each has a button that goes to the other activity (by startActivity() method). In the second activity, I have an edit text (URL address bar) and a web view.

所以,当我点击活动1的按钮启动活性2,我得到活性2与Web视图。然后,我键入 cnn.com (例如)在地址栏和我的Web视图显示 cnn.com 网​​络现场。在那之后,我按一下按钮,从活性2去活动1。 如果我再次点击活动1的按钮,我开始活性2。但是,活性2刚刚创建的,我的意思是,编辑文本和Web视图是空的。

So, when I click on the button of activity1 to start activity2, I get activity2 with the web view. Then I type cnn.com (for example) in the address bar and my web view displays the cnn.com web site. After that, I click on the button to go from activity2 to activity1. If I click again on the button of activity1, I start activity2. But activity2 has just been created, I mean, the edit text and the web view are empty.

我要的是:如果我从相关活动,回到活性2,我想活性2保留最近的状态:编辑文本应保持 cnn.com 和Web视图应持续显示美国有线电视新闻网网站。 因此,我需要的不是退出活性2启动相关活动,之前的事,但像刚才隐藏它,并开始活性2,因此,如果我回到了一遍,我得到其最后的状态。 (就像当我点击主页按钮。)我怎样才能做到这一点?

What I want is: if I return from activity1 to activity2, I want activity2 to keep the last state: the edit text should keep cnn.com and the web view should keep displaying the CNN web site. So what I need is not to quit activity2 before starting activity1, but something like just hiding it and starting activity2, so that if I return to it again, I get its last state. (Like when I click on the home button.) How can I achieve this?

推荐答案

下面是建议,以解决您的问题。

Here is suggestion to solve your problem .

当你从巴顿是在活动二而现在你在活动一确保当你从活动二搬到之一,它不应该完成活动二。去

when you go from Button that is in Activity two .and now you are in Activity one make sure that when you move from activity two to one ,it should not finish activity two.

现在。

            Intent mIntent=new Intent(yourActivityOne1.this, YourActivity2.class);
    mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    mIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(mIntent);

所以这是什么code做的是它会使活动先过来,而无需创建活动的新实例,你可以看到你的最后一个加载的网站在那里。

so what this code do is it will make Activity to come over first without creating new instance of activity and you can see that your last loaded website it there.

这篇关于隐藏在机器人活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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