android - 如何检查打开的活动是否关闭?
问题描述
如下代码所示,我想在 App info Activity
(ACTION_APPLICATION_DETAILS_SETTINGS) 退出后使用Intent
(app info) 运行我的函数。而是mylocation()
与打开的活动一起运行。如何做到这一点?
@Override
public void onRequestPermissionsResult(int requestCode,String[] permissions,int[] grantResults) {
switch (requestCode){
case MY_PERMISSION_FINE_LOCATION:{
if (grantResults.length>0&&grantResults[0]==PackageManager.PERMISSION_GRANTED){
my_location();
}
else
{
Toast.makeText(getActivity(),"Location permission required for fetching your current location Permission>Enable location",Toast.LENGTH_LONG).show();
//redirect to app info
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:com.example.anonymous.trackerplus")));
my_location();
}
}
}
}
解决方案
onDestroy
活动关闭时调用的活动生命周期方法。因此,在您的活动中覆盖onDestroy
方法并做任何您想做的事情,它将在活动关闭时执行。
推荐阅读
- parallel-processing - MPI_SSEND :它如何保证发送者缓冲区的重用?
- python - NAO - 访问和使用虚拟 Nao
- javascript - React-router-dom 如何更新路由组件内的父状态
- android - 如何从 web 视图打开 Android 应用程序链接
- xcode - fastlane ** 存档失败 **
- javascript - 如何在 Inappbrowser Cordova 上将下载或响应作为文件处理
- r - 使用具有最小值/最大值的其他数据集将子集函数应用于列
- yocto - 如何从构建中删除 packagegroup-core-full-cmdline-sys-services
- php - 表单提交后传递变量PHP
- c# - AutoMapper 后缀无法识别