-6

As shown in below code, I want to run my function after the exit of App info Activity(ACTION_APPLICATION_DETAILS_SETTINGS) using Intent(app info). But mylocation() is running along with the opened activity. How to accomplish this?

@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();
            }
        }

    }
}
JARVIS
  • 501
  • 4
  • 9
  • what do you mean " after the exit of opened activity"??. and please clarify your question – Rubick Sep 11 '18 at 08:20
  • Your questions is unclear. But with what I understand, you should call your method from onDestroy if it has to be run just before closing the activity. Or if it has to be called only once, the you have to start the intent in last line of your method. – Mohammed Atif Sep 11 '18 at 08:37
  • check [this answer](https://stackoverflow.com/questions/5975811/how-to-check-if-an-activity-is-the-last-one-in-the-activity-stack-for-an-applica) You may find your solution in the selected answer. – Ankit Gupta Sep 11 '18 at 09:35
  • mylocation() function contains some activities that need location permission. And in the above code, I am letting the user to manually allow user permission by redirecting to app info activity. I need to run my_location() function only when user exit from app info activity but in my case function call is happening along with redirection to the activity. – JARVIS Sep 11 '18 at 10:06

1 Answers1

0

An activity life cycle method onDestroy called whenever activity is closed. So override onDestroy method in your activity and do whatever you want it will be executed when an activity is closed.

Suraj Vaishnav
  • 7,777
  • 4
  • 43
  • 46