开发者

Could someone explain the differences here?

When I want to get result from start activity, I will use method startActiv开发者_StackOverflowityForResult(Intent, int).

What is the difference if I pass 0 (zero) as the second parameter and if pass -1 (negative one) as the parameter?


The difference is if you pass a value >= 0, this code will be returned in onActivityResult() when the activity exits and your window will not be displayed until a result is returned back from the started activity.

Otherwise, it is the same as calling startActivity(Intent). (the activity is not launched as a sub-activity)


From the documentation:

As a special case, if you call startActivityForResult() with a requestCode >= 0 during the initial onCreate(Bundle savedInstanceState)/onResume() of your activity, then your window will not be displayed until a result is returned back from the started activity. This is to avoid visible flickering when redirecting to another activity.


If you pass 0, the method will return 0 in onActivityResult() when the activity completes.

If you pass -1, I don't believe any value will be passed (according to the docs, the value will only be returned if it is >= 0)


The difference is that when onActivityResult method gets called back, its requestCode parameter will be either 0 or -1.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜