我必须开发一个Android应用程序。
这里我有管理会话概念。
DetailDescription.class有一个提交按钮。如果我必须单击此按钮它将转到LoginPage.class.if客户成功登录意味着它转到AddList.class。
我必须单击后退按钮意味着它应该再次转到LoginPage.class。但我想要使用那些旧数据转到DetailDescription.class。我该怎么办?
AddList.class:
back = (Button) findViewById(R.id.back);
back.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(AddList.this,DetailDescription.class);
startActivity(intent);
}
});
DetailDescription.class有2个带数据的文本视图。
prod_name.setText(product_title);
pass_categoriesname.setText(subcategory_title);
现在我必须运行应用程序:
textview值显示从product_id上的xml feed depands动态获取。
现在我必须点击提交按钮,然后转到LoginPage。
如果成功登录意味着它转到AddList.class。
现在我必须单击AddList.class上的后退按钮,意味着它转到带有旧数据的DetailDescription.class。
我该怎么办????
请给我解决方案......
答案 0 :(得分:0)
更改后退按钮的代码
back = (Button) findViewById(R.id.back);
back.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
在您的登录活动中更改您的代码
Intent i=new Intent(Login.this,AddList.class);
startActivity(i);
finish();
更好的方法:
*从DetailDescription活动中打开AddList活动
使用函数startActivityForResult
代替startActivity
。这样您就可以处理AddList活动的返回值
*然后从AddList活动检查用户是否登录
*如果未使用startActivityForResult
打开登录活动。因此,无论用户登录成功与否,您都可以从登录活动中获取返回值。所以你可以决定采取进一步的行动
*在添加AddList活动的详细信息后,您可以在传递结果的同时完成AddList活动。
答案 1 :(得分:0)
与许多人会告诉你的不同,不更改此类任务的后退按钮的代码。有更优雅的方式比这更好,谷歌的代码越多越完好 - 它将带来更好的用户体验,并且没有必要纠结已经为你工作的东西
据我所知,你的问题(不是很清楚),最简单的解决方案就是添加
android:noHistory="true"
到你的登录活动的清单 - 这意味着一旦用户登录,后退将无法返回到登录屏幕,因为它没有存储在后台堆栈上,应用程序将转到之前的活动 - DetailDescription
。
至于保存数据,您应该查看SharedPreferences
,并在离开活动时将数据保存在表单中,以便在您返回时恢复它们