Android:FLAG_ ACTIVITY_ CLEAR_ Top and Android: launchmode = “singleinstance”

I think I just found a very strange error... But it may be just some features I've never heard of

On my application, if I install Android: launchmode = "singleinstance" on androidmanifest, when you try to "clean" the stack to a certain point with the following code:

    Intent intent = new Intent(this, Xpto.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);

It goes to that activity... But when you press it, it will return to the previous... It should have been completed

Example:

A – > B – > C

Then I use intent.flag from C_ ACTIVITY_ SINGLE_ Top | call a. intent.flag_ ACTIVITY_ CLEAR_ Top has a singleinstance on the manifest. It goes to a, but it only brings it to the front... And does not complete C and B

Can anyone explain this behavior?

The xpto class I'm calling is the root activity of the stack

thank you

resolvent:

Read this thread from:

http://groups.google.com/group/android-developers/browse_thread/thread/5eb400434e2c35f4

seem:

"In the above example, the currently running instance of activity B will either receive the new idea method you started here in onnewintent(), or complete and restart it by using the new idea. If it has declared its startup mode as" multiple "(the default) And you have enabled that if flag_activity_single_top is not set in the same intention, it will be completed and re created; for all other launch modes or if flag_activity_single_top is set, then pass this intent to onnewintent() of the current instance“

This means that you need to set the launchmode to multiple instances and use only flag_ ACTIVITY_ CLEAR_ TOP.

Intent intent = new Intent(this, Xpto.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);

In the scenario you described, when you start activity a (this is the root activity), activity B and C are not completed. This document describes the startup mode of using singleinstance and the flag flag flag set_ ACTIVITY_ SINGLE_ Top, activities B and C will not be completed. If activities B and C are to be completed, the startup mode must be set to multiple instances instead of flag flag_ ACTIVITY_ SINGLE_ TOP.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>