Skip to content Skip to sidebar Skip to footer

Adding Functionality To Back Key In Android To Go To Previous Folder Location In A File Manager

I know this has been discussed so many times but really I am not able to figure it out. I am so sorry for asking it again. I am making android file manager. I am showing the fil

Solution 1:

you can try this:

@OverrideprotectedvoidonBackPressed(){
    //super.onBackPressed(); //remove it if you want controlStringpreviousDir="build your previous dir here";
    if (previousDir != null){ //if deferent root pathIntentactivityDir=newIntent(this, MainActivity.class);
       activityDir.putExtra("DIR_PATH", previousDir);
       startActivity(activityDir);
    }//end if

   finish(); //close this screen to show new screen above with new path
}

Note: you have to edit onCreate(....) as bellow code:

@OverridepublicvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);  /**super keyword in java is a reference variable that
         is used to refer immediate parent class object. */setContentView(R.layout.activity_main);
        myPath = (TextView)findViewById(R.id.path); /* storing the current path*/if(getIntent() != null){
           root = getIntent().getStringExtra("DIR_PATH", root); //if is null then get root
        }
        getDir(root);
    }

Post a Comment for "Adding Functionality To Back Key In Android To Go To Previous Folder Location In A File Manager"