Android:如何不保存实例状态?

发布于 2024-11-13 07:46:56 字数 1023 浏览 2 评论 0原文

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

写入后,应用程序将转到下一个 Activity

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

,AppView 类是下一个 UI 为 Web 视图的 Activity。它查看登录时创建的 html。

当我单击“以不同用户身份登录”按钮时,我返回到主活动,即 MyMainAct。我使用以下代码:

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

当我再次登录(作为不同的用户)时,我期望看到不同的 UI,因为创建的 html 不同。但它并没有发生。第一个记录器的相同 html 由 webview 呈现。

我查看了第二个记录器创建的 html 代码,它与第一个记录器不同。但 webview 显示第一个记录器的 html。

与实例状态有关吗?这就是我的想法,这就是为什么我不想保存实例状态(包)。

编辑:

我如何忽略我的应用程序的savedInstanceState?

我的 MainActivity:

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

我的 AppView 活动:

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

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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

花开雨落又逢春i 2024-11-20 07:46:56

确保当用户选择“以不同用户身份登录”选项时,显示 HTML 的活动已完成(即调用其上的完成方法)。如果您随后忽略其 onCreate 事件中的 savedInstanceState 参数(我猜您可能会这样做),那么下次启动此 Activity 时,它将是它的全新实例。

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.

隐诗 2024-11-20 07:46:56

试试这个,看看是否有效。

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

Try this and see if it works.

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