Reputation: 9439
I have this code:
MainActivity:
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.
Is the above a right way to get child activity? If not, what is the best way to get child activity in this case?
Upvotes: 1
Views: 3651
Reputation: 1
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);
Upvotes: 0
Reputation: 40391
There's a LocalActivityManager#getActivity(String id) method available. Just use the same id you used to start the Activity.
Upvotes: 2