简体   繁体   English

从第一个活动切换到第二个活动时如何暂停第一个活动而不破坏第一个活动?

[英]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.

相关问题 将 EditText 在第一个活动中放入 TextView 在第二个活动中 - Put EditText in First Activity to TextView on Second Activity 从第二个活动导航到第一个活动时如何使图像在第一个活动中不可见 - how to make image invisble in first activity when navigating from second activity to first activity 使用Android导航组件从第一个活动导航到第二个活动时如何关闭/完成第一个活动 - How to close/finish the first activity when navigating from first activity to second activity using android navigation component 通过Activity进行首次安装:如何销毁它? - First installation by Activity: how to destroy that? 第二活动开始时,第一活动未停止 - First Activity not stopped when Second Activity started 将价值从第二活动传递到第一活动 - Pass value from second activity to first activity 将数据从第二个活动移到第一个活动 - Move Data from Second Activity to first Activity 如何接受第二项活动的意图 - how to recieve the second activity intent on first activity 使用layoutInflater从第一个布局切换到第二个布局:onclicklistner使活动崩溃 - Switching from first layout to second using layoutInflater: onclicklistner crashing the activity 当setResult()从第二个Activity返回第一个Activity时,将重新创建第一个Activity - First Activity is recreating when setResult() back to first Activity from second Activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM