I have this code:
public class MainActivity extends ActivityGroup
In MainActivity, I use this to start an activity and get its handle:
final LocalActivityManager manager = getLocalActivityManager(); final Intent i = new Intent(MainActivity.this, SearchActivity.class); final Window w = manager.startActivity("SearchActivity", i); Activity activity = (Activity) w.getContext();
The reason for this usage is that I want to minimize the responsibilities of MainActivity. SearchActivity will handle its own event.
<strong>Is the above a right way to get child activity? If not, what is the best way to get child activity in this case?</strong>Answer1:
There's a <a href="http://developer.android.com/reference/android/app/LocalActivityManager.html#getActivity%28java.lang.String%29" rel="nofollow">LocalActivityManager#getActivity(String id)</a> method available. Just use the same id you used to start the Activity.Answer2:
I hope it may help. it's my own experience that if you use Activity group then always try to open new activity from the activity group. i.e always open new activity from the group activity. if you open it from child activity it creates number of problem. one is window manager bad token exception.
to open new activity from group here is code: i hope it help you:
View view = getLocalActivityManager() .startActivity("ReferenceName",intent_to_start_activity .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView(); Your_group_cativity.this.setContentView(view);