I am wondering if there’s a stopActivity() function like the stopService() function.
My research indicates that there is no such function. However, I still need the ability to close one Activity from another.
How can I accomplish this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I had this problem a few days ago, and I’m happy to tell you I’ve found a way around this.
First of all, to the activity you want to stop add this in the
AndroidManifest.xml:I’m going to use a CheckBox example. When it’s checked the activity is started and when unchecked will kill the activity.
Example Activity A is calling Activity B and then killing it using an intent.
Code to be put in A:
Code to be put into B:
Explanation : What this basically does is, when the checkbox is checked it calls the activity and passes a boolean value, if it’s true the activity is kept alive and is brought to the foreground. Now, if you don’t pass the flag
singleTopthen many instances of this activity will be created.singleTopmakes sure only the same instance is called. Now, when the checkbox is unchecked a new value for keep is passed which is verified in B. If unchecked, the Activity A will be passing false, and hence B terminates itself from within theonNewIntent()function.P.S – You can close Activity B from another Activity too. Just use
If the other activity is C: