如下面的代码所示,我想在使用Activity
(应用信息)退出应用信息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();
}
}
}
}
答案 0 :(得分:0)
每当活动关闭时,就会调用活动生命周期方法onDestroy
。
因此,请在您的活动中覆盖onDestroy
方法,并在活动结束时执行将要执行的任何操作。