When ActivityGroup is used, how does one save the Activity status and use the Menu of the Child Activity?

Source: Internet
Author: User

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?

  1. 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?

 
  1. 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?

 
  1. @ Override
  2. Public boolean onKeyUp (int keyCode, KeyEvent event ){
  3. If (keyCode = KeyEvent. KEYCODE_MENU ){
  4. This. getLocalActivityManager (). getCurrentActivity (). openOptionsMenu ();
  5. }
  6. Return super. onKeyDown (keyCode, event );
  7. }


Both onkeyDown and onkeyUp are supported!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.