gpt4 book ai didi

android - 使用 onStop 进行解绑服务

转载 作者:行者123 更新时间:2023-11-29 15:51:44 26 4
gpt4 key购买 nike

我有一个 Activity,我想在不调用 onDestroy() 的情况下关闭它。所以我使用 onStop(); 看起来像

@Override
public void onStop(){
super.onStop();
try{
unbindService(mServerConn);
}
catch(Exception e){
e.printStackTrace();
}
}

我运行了代码,但 Activity 在屏幕上仍然可见

你能帮我把它藏起来吗?谢谢!

最佳答案

onStop() 的用法在那种情况下是不正确的。如果您需要关闭 Activity ,请使用 finish()

Intent openStartingPoint = new Intent(this, MainActivity.class);
openStartingPoint.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(openStartingPoint);
finish();

这应该可以正常工作。

关于android - 使用 onStop 进行解绑服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29664887/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com