tags:

views:

332

answers:

2

Hi,

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 Intent("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.

+4  A: 

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)

synic
Basically, I want to start a Toast in my subActivity or subsubActivity, but it can stay there even if user back from my subActivity/sbusubActivity (until he/she back all the way from the MainActivity). Can I do that?
michael
The Toast will remain up for the specified duration, even if you back all the way out to the home screen.
synic
A: 

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

michael
That only works if the Activity is embedded in another Activity. Like an Activity that is the content of one of the tabs in a TabActivity; getParent() will return the TabActivity;
synic
If, inside an activity (say listactivity), there are some UI logic in and adapter, which want to close/access its calling activity. How can an adapter refer to its activity and send some parameter too? (not only notifyDataChange().)
karim