Android的:如何不保存实例状态? [英] Android: How NOT to save instance state?

查看:154
本文介绍了Android的:如何不保存实例状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序已登录,一旦授予访问权限,它会创建一个新的HTML文件到SD卡,输出或HTML文件的外观取决于帐户记录的。

写作后,应用程序进入到下一个活动。

 意图nextActivity =新意图(MyMainAct.this,AppView.class);
        startActivity(nextActivity);

在APPVIEW类是下一个活动中,用户界面​​是网页视图。它认为在登录时创建的HTML。

当我点击登录为不同的用户按钮,我回去的主要活动是MyMainAct。我用下面的code:

 意图nextActivity =新意图(AppView.this,MyMainAct.class);
        startActivity(nextActivity);

当我登录一次(不同的用户),我期望的不同的UI,因为创建的HTML是不同的。但它并没有发生。第一记录器相同的HTML是web视图psented $ P $。

我看到由第二记录器创建的HTML code,它是从第一个不同。但web视图presents第一记录器的HTML。

这是关于实例的状态?这就是我想,这就是为什么我不希望保存实例状态(包)。

编辑:

我怎么不理我的应用程序的savedInstanceState?

我MainActivity:

 公共无效的onCreate(捆绑冰柱){
    super.onCreate(冰柱);

我APPVIEW活动:

 公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);


解决方案

确认,当用户选择登录为不同的用户选项,显示HTML活动是完成 ED(即调用完成它方法)。如果再忽视它的的onCreate 事件 savedInstanceState 参数(你可能做的,我presume)这项活动在下次启动时这将是它全新的实例。

My app has login, once the access is granted, it creates a new html file to the sdcard, the output or the appearance of that html file depends on the account of the logger.

After writing, the app goes to the next activity

        Intent nextActivity = new Intent(MyMainAct.this, AppView.class);
        startActivity(nextActivity);

the AppView class is the next activity in which the UI is a webview. It views the html created on login.

When I click "login as different user" button, I go back to the Main Activity which is MyMainAct. I use the following code:

        Intent nextActivity = new Intent(AppView.this, MyMainAct.class);
        startActivity(nextActivity);

When I logged in again (as different user), I expected a different UI since the html created is different. But it did not happen. The same html of the first logger is presented by the webview.

I looked into the html code created by the second logger, it is different from the first. but the webview presents the html of the first logger.

Is it about instance state? That's what I think, that's why I don't want to save instance state (bundle).

EDIT:

How do I ignore savedInstanceState of my App?

my MainActivity:

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

my AppView Activity:

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

解决方案

Make sure that when user chooses the "login as different user" option, activity showing the HTML is finished (i.e. call the finish method on it). If you then ignore the savedInstanceState parameter in its onCreate event (which you likely do, I presume), the next time this activity is started it will be totally new instance of it.

这篇关于Android的:如何不保存实例状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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