Android closing child activity from parent activity
Asked Answered
G

3

14

I wanted to close child activity from parent activity. My flow is like: activity A is opened, inside Activity A I am opening activity B. But at same time my activity A is doing some background task. When I got result of my background task I wanted to close activity B from Activity A.

Is it possible to do that?

Gillman answered 27/3, 2013 at 8:29 Comment(0)
B
29

You can start activity B by using startActivityForResult (Intent intent, int requestCode) then you can close activity B by calling finishActivity (int requestCode).

Bazooka answered 27/3, 2013 at 8:34 Comment(1)
startActivityForResult is deprecated. What's the new way to do this?Leaseback
M
6

What you should do is start your activity with startActivityForResult(yourIntent, childId);

Then, when you want to kill your child activity, try finishActivity(childId);

Saw that Here

Minny answered 27/3, 2013 at 8:42 Comment(1)
It's not, just quoting my source.Minny
M
1

you don't need to finish() every activity once you leave it, Android will do that for you. so you just restart Activity A to the top task .

Melodee answered 27/3, 2013 at 8:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.