Android:如何不保存实例状态?
我的应用程序已登录,一旦授予访问权限,它就会在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保当用户选择“以不同用户身份登录”选项时,显示 HTML 的活动已完成(即调用其上的完成方法)。如果您随后忽略其
onCreate
事件中的savedInstanceState
参数(我猜您可能会这样做),那么下次启动此 Activity 时,它将是它的全新实例。Make sure that when user chooses the "login as different user" option, activity showing the HTML is
finish
ed (i.e. call thefinish
method on it). If you then ignore thesavedInstanceState
parameter in itsonCreate
event (which you likely do, I presume), the next time this activity is started it will be totally new instance of it.试试这个,看看是否有效。
Try this and see if it works.