How getIntent.hasExtra method works in android
<p>I have been following a tutorial from this <a href="http://sampleprogramz.com/android/browse.php" rel="nofollow">link</a> which is basically about File browse concept in android. Everything works fine but I am getting confused of how passing intents between activities works in android after reading this link. The First activity is as follows,</p>

<pre><code>public class MainActivity extends Activity implements OnClickListener {

private static final int REQUEST_PICK_FILE = 1;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    filePath = (TextView)findViewById(R.id.file_path);
    Browse = (Button)findViewById(R.id.browse);
    Browse.setOnClickListener(this);      
}

public void onClick(View v) {

    switch(v.getId()) {

    case R.id.browse:
        Intent intent = new Intent(this, FilePicker.class);            
        startActivityForResult(intent, REQUEST_PICK_FILE);
        break;
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if(resultCode == RESULT_OK) {

        switch(requestCode) {

        case REQUEST_PICK_FILE:

            if(data.hasExtra(FilePicker.EXTRA_FILE_PATH)) {

                selectedFile = new File
                        (data.getStringExtra(FilePicker.EXTRA_FILE_PATH));
                filePath.setText(selectedFile.getPath());  
            }
            break;
        }
    }
</code></pre>

<p>As far as I understood, its passing the intent "REQUEST_PICK_FILE" and based on what it returns from "FilePicker.Class" , it will perform the action because its StartActivityOnResult. Confusion starts from next activity. Here is the File Picker class,</p>

<pre><code>  public class FilePicker extends ListActivity {

public final static String EXTRA_FILE_PATH = "file_path";
public final static String EXTRA_SHOW_HIDDEN_FILES = "show_hidden_files";
public final static String EXTRA_ACCEPTED_FILE_EXTENSIONS = "accepted_file_extensions";
private final static String DEFAULT_INITIAL_DIRECTORY = "/";
.......
protected String[] acceptedFileExtensions;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    .........
    // Initialize the extensions array to allow any file extensions
    acceptedFileExtensions = new String[] {};

    // Get intent extras
    if(getIntent().hasExtra(EXTRA_FILE_PATH)) 
        Directory = new File(getIntent().getStringExtra(EXTRA_FILE_PATH));

    if(getIntent().hasExtra(EXTRA_SHOW_HIDDEN_FILES)) 
        ShowHiddenFiles = getIntent().getBooleanExtra(EXTRA_SHOW_HIDDEN_FILES, false);

    if(getIntent().hasExtra(EXTRA_ACCEPTED_FILE_EXTENSIONS)) {

        ArrayList&lt;String&gt; collection = 
                getIntent().getStringArrayListExtra(EXTRA_ACCEPTED_FILE_EXTENSIONS);

        acceptedFileExtensions = (String[]) 
                collection.toArray(new String[collection.size()]);
    }
}
 ..............
</code></pre>

<p>Whats actually happening here? what does the lines ,</p>

<pre><code>   if(getIntent().hasExtra(EXTRA_SHOW_HIDDEN_FILES)) 
        ShowHiddenFiles = getIntent().getBooleanExtra(EXTRA_SHOW_HIDDEN_FILES, false); 
</code></pre>

<p>actually mean? We are not passing any extras like, "EXTRA_SHOW_HIDDEN_FILES" from previous activity and even EXTRA_SHOW_HIDDEN_FILES has been declared in this class. I seriously don't understand what's happening between these two activities . I am not able to proceed before understanding what's actually going on. Any help would be really great !! Thanks.</p>