如何检查已打开的活动是否已关闭?

问题描述 投票:-6回答:1

如下面的代码所示,我想在使用Activity(app info)退出App info Intent(ACTION_APPLICATION_DETAILS_SETTINGS)后运行我的函数。但是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();
            }
        }

    }
}
android android-studio
1个回答
0
投票

活动生命周期方法onDestroy在活动结束时调用。因此,在您的活动中覆盖onDestroy方法,并执行您希望在活动关闭时执行的任何操作。

© www.soinside.com 2019 - 2024. All rights reserved.