Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will someone please explain RESULT_FIRST_USER

I don't understand the meaning, value, or importance of RESULT_FIRST_USER, other than that my own result codes must be greater than 1. Will someone please explain it? RESULT_OK and RESULT_CANCELED make perfect sense to an english speaker. But what in the world of android is RESULT_FIRST_USER? All the documentations says about it is

Start of user-defined activity results. 
like image 528
Katedral Pillon Avatar asked Aug 14 '15 15:08

Katedral Pillon


People also ask

What is RESULT_ FIRST_ user?

RESULT_FIRST_USER identifies the first value in the user-defined range. The following sample definitions show how system- and user-defined values fit together: public static final int RESULT_OK = -1; // Defined by Android. You don't write this code.

What is onActivityResult?

onActivityResult is the callback you have on the first activity to grab the contacts you choose. Follow this answer to receive notifications.


1 Answers

The answer to the question is actually the combination of comments from @CommonsWare and @Chris. So, for the sake of progeny, I am going to consolidate the comments and make it available in one place.

Basically, there are two predefined constants for the requestCode and they are Activity.RESULT_OK and Activity.RESULT_CANCELLED. However, android developers can also set custom codes for their apps by using the offset Activity.RESULT_FIRST_USER. Doing so ensures that there are no clashes between constants set at the OS level and the app level.

Purely, my opinion, I think that the FIRST USER suffix is meant to refer to developers – just like how end consumer refers to consumers of a said product – who are the first users before the app users.

Below is an example of how you can use this offset,

public static final int MY_RESULT_CODE = Activity.RESULT_FIRST_USER + 1; 
like image 176
Avid Programmer Avatar answered Sep 19 '22 12:09

Avid Programmer