Activitygroup Brief Introduction

Source: Internet
Author: User


Activitygroup Brief Introduction


1.ActivityGroupthe core is to inherit the class, you can get a getlocalactivitymanager () Localactivitymanager

Such as, Localactivitymanager am= Getlocalactivitymanager ();

2.And then throughLocalactivitymanagerPassstartactivity (String ID, Intent Intent),Ability to work with the specifiedactiivtybinding, and returns aWindow。LocalactivitymanagerBe able to manage multiple at the same timeActivity

Window Window1 = am.startactivity ("Module1", Newintent (Testview.this, Moduleview1.class));
Window Window2 = am.startactivity ("Module2", Newintent (Testview.this, Moduleview2.class));

3.And thenWindowTo passGetdecorview ()Method, returns aView,And then through the container with the specifiedAddView (View)Method,Achieve a different effect

View view1 = Window1.getdecorview ()
View view2 = Window2.getdecorview ()

in practice, many shorthand forms , such as
ContainerIsScrollViewAn instance of
container.removeallviews (); //Remove all other child views
Container.addview (Getlocalactivitymanager (). StartActivity (
"Module2",
New Intent (Testview.this, Moduleview2.class)
. Addflags (Intent.flag_activity_clear_top))
. Getdecorview ());

Attention:
Container.removeallviews ():Indicates that all other views are removed before the view is displayed.
Intent.flag_activity_clear_top:Assuming that the currentTask, you have to start theActivity, then put theacitivityAll the previousActivityAll off, and put thisActivityPre-set to avoid creatingActivityInstances of

this way has very great flexibility, often used is to achieve tabhost paging effect, but very good to avoid the shortcomings of Tabhost , such as title

Assume that four activity:a,b,c and d have been started. In d activity, we want to jump to B activity, at the same time want C finish off, can be in startactivity (intent) in the intent to add the flags, such as the following see:

Intent Intent = new Intent (this, b.class); Intent.setflags (Intent.flag_activity_clear_top); startactivity (intent);


To start B activity, you will finished d,c, assuming that your B activity's startup mode is the default (multiple), B activity will finished off, and then start a new Activity B. Assuming that you don't want to create a new B Activity again, add it in the code above:

Intent.addflags (Intent.flag_activity_single_top);

Then B activity will create a new one, but will reuse the previous B activity, at the same time invoke B activity's onnewintent () method.

Problem:
Multiple activity exits the entire program, such as from A->b->c->d, when I need to exit the program from D directly.

Online information:{
Both finish () and system (0) can only exit a single activity. Kill the process, etc.
To solve this problem:
We know that the Android form class provides a history stack, which we can skillfully implement using the stack principle, where we add the flag intent.flag_activity_clear_top directly to the intent in the D form when we open the a form. When you turn on a again, all activity for that process space will be cleared.
Use the following code in D:

Intent Intent = new Intent (); Intent.setclass (D.this, A.class); Intent.setflags (intent.flag_activity_clear_top); Note The bank's flag setting startactivity (intent); finish ();


Shut yourself down.
Add the code in a:

overrideprotected void Onnewintent (Intent Intent) {//TODO auto-generated method Stubsuper.onnewintent (Intent);//Exit if ( (Intent.flag_activity_clear_top & Intent.getflags ())! = 0) {finish ();}}


A manifest.xml is configured as android:launchmode= "Singletop"

Principle Summary:
General A is the entry point of the program, from D to a ACTIVITY, to increase the identity of the Intent.flag_activity_clear_top this process will be b,c in the stack, are cleared away. Because A is android:launchmode= "Singletop"
does not call OnCreate (), but responds to Onnewintent () by this time infer intent.flag_activity_clear_top, and then put a finish () off.
All the a,b,c,d in the stack are cleaned up. So the whole program exited.

Activitygroup Brief Introduction

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.