0

I am currently in the process of writing an android application which uses folder navigation. I have the user start off in

String rootPath = Environment.getExternalStorageDirectory().getPath()

and also a currentPath string which keeps track of the directory which the user is currently in.

and the user can navigate through just fine within sub folders, and navigate back to the root folder.

However, the program seems to continue trying to navigate below the initial rootPath string, This means that my if statement for if(currentPath != rootPath) { doesn't seem to be working at all. How may I fix this?

I have the program working now only because I have a try catch block for the code after this if statement which is not properly being tripped.

Also, I have set up Logcat messages to show what the current directory is and it is clearly the same as what it was when the program initialized, so why is it not equal to the rootPath string created at program initialization?

Michael
  • 57,169
  • 9
  • 80
  • 125

1 Answers1

0

Dont use

if(currentPath != rootPath) {

to compare strings.

You have to use equals :

if( ! currentPath.equals(rootPath)) {

!= operator compares the adresses of the strings objects. equals method compares the content of the strings...

see https://www.leepoint.net/data/expressions/22compareobjects.html

olikaf
  • 591
  • 3
  • 11