[英]How can I put the first activity on pause when switching from the first activity to the second one and not destroy first activity?
I have the first activity and a button on it , when I click the button , I go to the second activity .我有第一个活动和一个按钮,当我单击按钮时,我转到第二个活动。 And when I moved / am on the second activity I would like the first activity not to be destroyed but to pause(FirstActivity.Pause).当我移动/在第二个活动中时,我希望第一个活动不被破坏而是暂停(FirstActivity.Pause)。 Tell me if there are ways to implement this ?告诉我是否有办法实现这一点?
I want to implement this so that the data from the first activity is not deleted.我想实现这一点,以便不会删除第一个活动中的数据。
Thanks!谢谢!
its the defualt behavior to pause first activty you didn't call finish() on it .它是暂停第一次活动的默认行为,您没有在其上调用 finish() 。 your Intent should be like this Intent i= new Intent(context, secondActivity.class); startActivity(i);
你的意图应该是这样的Intent i= new Intent(context, secondActivity.class); startActivity(i);
Intent i= new Intent(context, secondActivity.class); startActivity(i);
please share your code to find issue .请分享您的代码以查找问题。
Your activity is supposed to pause.您的活动应该暂停。 You should add this line of code to your on create method:您应该将这行代码添加到您的 on create 方法中:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(FirstActivity.this, SecondaryActivity.class));
}
});
Your Main activity is going to be paused whilst you are on your secondaryActivity.当您处于次要活动时,您的主要活动将暂停。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.