开发者

Implications of setting a flag on the Intent

开发者 https://www.devze.com 2023-01-30 06:06 出处:网络
I\'m calling context.startActivity(in开发者_JAVA百科tent) from within a seperate OnClickListener class.In order for this to work I had to set the FLAG_ACTIVITY_NEW_TASK on the intent.

I'm calling context.startActivity(in开发者_JAVA百科tent) from within a seperate OnClickListener class. In order for this to work I had to set the FLAG_ACTIVITY_NEW_TASK on the intent.

That all works as expected, but I'm wondering if there are any implications to doing this that I'm not aware of. Will this create any problems in terms of performance? Does it reflect poor design on my part?

What do you think?


From the Android docs: "This flag is generally used by activities that want to present a "launcher" style behavior: they give the user a list of separate things that can be done, which otherwise run completely independently of the activity launching them."

More from the Android docs: "Note that if this method is being called from outside of an Activity Context, then the Intent must include the FLAG_ACTIVITY_NEW_TASK launch flag. This is because, without being started from an existing Activity, there is no existing task in which to place the new activity and thus it needs to be placed in its own separate task."

As you are starting a new activity each time and adding this to the stack, if you leave that activity and then start another with the onClickListener you might run the risk of starting another activity instead of resuming the previous activity. I think changing the flag to FLAG_ACTIVITY_RESET_TASK_IF_NEEDED should fix this.

0

精彩评论

暂无评论...
验证码 换一张
取 消