I think this is a basic question. Is there any option to stop an activity by using intent.
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:5554"));
startActivity(intent);
This is my code. I would like to stop this activity (That means, i want to drop this call) if the user is busy or something. What can I do for that? I tried this:
if (condition) {
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:5554"));
startActivity(intent);
}else {
this.finish();
}
But of no use. Does anybody have a suggestion?
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
singleTop
then many instances of this activity will be created.singleTop
makes 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:
You can turn off the background data of play store and play services for not entering the play store .it will simply say, " COULD NOT BE LOADED " Thats the only way i found to stop intent