我想返回上一个活动,用户在关闭应用程序之前已关闭。我已经实现了这种方法来传达3个活动,但在我的代码中有错误。你有什么想法来解决这个问题吗?返回上一个活动(PreferenceManager)
MenuActivity(打开时应用启动)
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String lastActivity = ((Intent) PreferenceManager.getDefaultSharedPreferences(this)).getStringExtra("sent");
if (lastActivity != null && lastActivity.equals("activity_2")){
{
Intent myIntentActivity1 = new Intent(menu.this,activity_2.class);
startActivity(myIntentActivity1);
}
}
if (lastActivity != null && lastActivity.equals("activity_3")){
{
Intent myIntentActivity2 = new Intent(menu.this,activity_3.class);
startActivity(myIntentActivity2);
}
}
else {
Intent myIntentActivity3 = new Intent(menu.this,menu.class);
startActivity(myIntentActivity3);
}
活动2
//一些代码
@Override
public void onResume(){
super.onResume();
Editor e = PreferenceManager.getDefaultSharedPreferences(this).edit();
((Intent) e).putExtra("sent", "activity_2");
e.commit();
}
活动3
//一些代码
@Override
public void onResume(){
super.onResume();
Editor e = PreferenceManager.getDefaultSharedPreferences(this).edit();
((Intent) e).putExtra("sent", "activity_3");
e.commit();
}
我已经离开了空白页,就好像它重复同样的动作不起作用返回菜单(也许) –
我删除的其他内容和现在的作品感谢朋友 –