首页 > 解决方案 > 如何检查打开的活动是否关闭?

问题描述

如下代码所示,我想在 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();
            }
        }

    }
}

标签: androidandroid-studio

解决方案


onDestroy活动关闭时调用的活动生命周期方法。因此,在您的活动中覆盖onDestroy方法并做任何您想做的事情,它将在活动关闭时执行。


推荐阅读