开发者

What is the recommend way to get the main Activity from child Activity

开发者 https://www.devze.com 2022-12-25 05:00 出处:网络
My android application has 1 main activity. And it launches some sub-activity (which I wrote) and that also launches some sub-activity (which I wrote).I do this:

My android application has 1 main activity. And it launches some sub-activity (which I wrote) and that also launches some sub-activity (which I wrote). I do this:

 Intent i = new Inte开发者_运维问答nt("my intent1");
 startActivity(i);

My question is how can each of my sub-activity and sub-sub-activity get back to the Parent activity?

Thank you.


You should start your sub Activities via [startActivityForResult()][1], and when you're done in your sub-activity, call finish(). This will close the sub-activity and return to the Activity that called startActivityForResult.

[1]: http://developer.android.com/intl/de/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)


I think there is a method getParent() which returns the parent Activity of a child activity.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号