Reprinted from: http://blog.csdn.net/feng88724
Many friends think that TabHost has too many restrictions and has little room for use. Therefore, ActivityGroup is used to replace TabHost.
However, when ActivityGroup is used, many friends may also encounter problems in the title.
The following describes the solution.
1. How do I save the Activity status when ActivityGroup is used?
In fact, it is very easy to load the Activity as follows.
[Java]View plaincopyprint?
- GetLocalActivityManager (). startActivity ("XXX", new Intent (this, XXX. class). getDecorView ()
So how can we prevent ActivityGroup from saving the status of the sub-Activity? That is, when switching, it is destroyed directly.
In fact, you only need to add a Flag: Intent. FLAG_ACTIVITY_CLEAR_TOP, as shown below:
[Html]View plaincopyprint?
- GetLocalActivityManager (). startActivity ("YYY", new Intent (this, YYY. class). addFlags (Intent. FLAG_ACTIVITY_CLEAR_TOP). getDecorView ()
2. How do I use the Menu of a sub-Activity when ActivityGroup is used?
In fact, it is also very simple, as long as in the class inheriting ActivityGroup
[Java]View plaincopyprint?
- @ Override
- Public boolean onKeyUp (int keyCode, KeyEvent event ){
- If (keyCode = KeyEvent. KEYCODE_MENU ){
- This. getLocalActivityManager (). getCurrentActivity (). openOptionsMenu ();
- }
- Return super. onKeyDown (keyCode, event );
- }
Both onkeyDown and onkeyUp are supported!