简体   繁体   English

FLAG_ACTIVITY_CLEAR_TOP调用onCreate()而不是onResume()

[英]FLAG_ACTIVITY_CLEAR_TOP calls onCreate() instead of onResume()

So I have an abstract class extended through the entire app that overrides the back key to reorder Activity A to the front (With the flag). 所以我在整个应用程序中扩展了一个抽象类,它覆盖了后退键,将活动A重新排序到前面(带有标志)。

So, it would be: 那么,它将是:

A > B > anywhere, and the back key should bring me back to A A> B>任何地方,后退键应该让我回到A

I'm using the FLAG_ACTIVITY_CLEAR_TOP, but it is entirely refreshing A for some reason and I don't want that. 我正在使用FLAG_ACTIVITY_CLEAR_TOP,但由于某些原因它完全令人耳目一新,我不希望这样。

So: Flag_activity_clear_top is reloading the onCreate() rather than onResume(). 所以:Flag_activity_clear_top正在重新加载onCreate()而不是onResume()。 What gives? 是什么赋予了?

If you want the activity to just be brought to the top without restarting it set the launchMode of the activity to singleTop in the manifest. 如果您希望仅在不重新启动的情况下将活动置于顶部 ,则将活动的launchMode设置为清单中的singleTop。 You will receive a call to onNewIntent when the activity is being brought to the top. 当活动被带到顶部时,您将收到对onNewIntent的调用。 onNewIntent is called before onResume. 在onResume之前调用onNewIntent。 If you only want this behavior for the specific intent you can add the FLAG_ACTIVITY_SINGLE_TOP (in addition to FLAG_ACTIVITY_CLEAR_TOP) to the intent with the addFlags call instead of the manifest. 如果你只想要这种行为的具体意图,你可以添加FLAG_ACTIVITY_SINGLE_TOP (除FLAG_ACTIVITY_CLEAR_TOP)的意图与addFlags调用清单代替。

From the API docs for FLAG_ACTIVITY_CLEAR_TOP 来自FLAG_ACTIVITY_CLEAR_TOP的API文档

For example, consider a task consisting of the activities:
A, B, C, D. If D calls startActivity() with an Intent that
resolves to the component of activity B, then C and D 
will be finished and B receive the given Intent,
resulting in the stack now being: A, B.

**The currently running instance of activity B in the above example
will either receive the new intent you are starting here in its
onNewIntent() method, or be itself finished and restarted with the new intent.**

So I think your activity is itself finished and restarted. 所以我认为你的活动本身已经完成并重新启动。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM