Elegant app quits completely (no hidden memory leaks)

Source: Internet
Author: User

In the Android development process, especially the interface is more than the case, with the usual exit is often not completely quit the application, the network is also a lot of various exit programs. One of them should be used by the vast number of developers, but also very clear and convenient. is to maintain a single instance of the List<activity> management container in application, each time the new activity is opened, the current activity is added to the container, and then when the need to completely exit. Loop through the container respectively finish () each activity. The total exit function is achieved.

Although this kind of exit method is very good. But there is a hidden memory leak. Therefore, we need to find a better solution. Here's a very good, super-simple way to do it, not to manage the activity, but to make a fuss about the activity's startup mode.

Give me a sample!

For example: There is an application that opens first into the A Interface (boot interface), then into the B interface (main interface), then into the C interface, into the D interface, into the E interface, into the F interface, then back to the B interface (main interface), then into the G interface, into the H interface, and finally back to the B interface a->b->c->d->e->f->b->g->h->b.

If the activity is in the default startup mode, click Exit button on main interface B to exit the entire app, you will need to turn off the B-h-g-b-f-e-d-c-b-a interface in turn. And then the egg ... No one wants to shut it off like this. But let's assume that the B interface (main interface): Android:launchmode= "Singletask", then the boot process from a->b->c->d->e->f->b to the B interface, This is not another time to create a B interface, but the initiative to finish off the C, D, E, F interface and then use the original B interface. And then from the b->g->h->b, but also will take the initiative to finish off the G, H interface and before using the B interface. Therefore, exiting the entire app will simply leave interface A and interface B, and a interface is the boot interface. When you enter B from a, you can finish off a, however. Now you just have to finish it on the main interface B.

Easily complete the exit of the app.


Elegant app quits completely (no hidden memory leaks)

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.